| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 #include "native_client/src/trusted/threading/nacl_thread_interface.h" | 7 #include "native_client/src/trusted/threading/nacl_thread_interface.h" |
| 8 | 8 |
| 9 #include "native_client/src/include/nacl_compiler_annotations.h" | 9 #include "native_client/src/include/nacl_compiler_annotations.h" |
| 10 | 10 |
| 11 #include "native_client/src/shared/platform/nacl_check.h" | 11 #include "native_client/src/shared/platform/nacl_check.h" |
| 12 #include "native_client/src/shared/platform/nacl_log.h" | 12 #include "native_client/src/shared/platform/nacl_log.h" |
| 13 #include "native_client/src/shared/platform/nacl_threads.h" | 13 #include "native_client/src/shared/platform/nacl_threads.h" |
| 14 #include "native_client/src/trusted/nacl_base/nacl_refcount.h" | 14 #include "native_client/src/trusted/nacl_base/nacl_refcount.h" |
| 15 | 15 |
| 16 void WINAPI NaClThreadInterfaceStart(void *data) { | 16 void WINAPI NaClThreadInterfaceStart(void *data) { |
| 17 struct NaClThreadInterface *tif = | 17 struct NaClThreadInterface *tif = |
| 18 (struct NaClThreadInterface *) data; | 18 (struct NaClThreadInterface *) data; |
| 19 void *thread_return; | 19 void *thread_return; |
| 20 | 20 |
| 21 NaClLog(4, |
| 22 ("Entered NaClThreadInterfaceStart: thread object 0x%"NACL_PRIxPTR |
| 23 " starting.\n"), |
| 24 (uintptr_t) tif); /* NaClThreadId() implicitly printed */ |
| 21 (*NACL_VTBL(NaClThreadInterface, tif)->LaunchCallback)(tif); | 25 (*NACL_VTBL(NaClThreadInterface, tif)->LaunchCallback)(tif); |
| 22 thread_return = (*tif->fn_ptr)(tif); | 26 thread_return = (*tif->fn_ptr)(tif); |
| 27 NaClLog(4, |
| 28 ("NaClThreadInterfaceStart: thread object 0x%"NACL_PRIxPTR |
| 29 " returned 0x%"NACL_PRIxPTR".\n"), |
| 30 (uintptr_t) tif, |
| 31 (uintptr_t) thread_return); /* NaClThreadId() implicitly printed */ |
| 23 (*NACL_VTBL(NaClThreadInterface, tif)->Exit)(tif, thread_return); | 32 (*NACL_VTBL(NaClThreadInterface, tif)->Exit)(tif, thread_return); |
| 24 NaClLog(LOG_FATAL, | 33 NaClLog(LOG_FATAL, |
| 25 "NaClThreadInterface: Exit member function did not exit thread\n"); | 34 "NaClThreadInterface: Exit member function did not exit thread\n"); |
| 26 } | 35 } |
| 27 | 36 |
| 28 int NaClThreadInterfaceCtor_protected( | 37 int NaClThreadInterfaceCtor_protected( |
| 29 struct NaClThreadInterface *self, | 38 struct NaClThreadInterface *self, |
| 30 NaClThreadIfFactoryFunction factory, | 39 NaClThreadIfFactoryFunction factory, |
| 31 void *factory_data, | 40 void *factory_data, |
| 32 NaClThreadIfStartFunction fn_ptr, | 41 NaClThreadIfStartFunction fn_ptr, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 if (0 != (rv = | 81 if (0 != (rv = |
| 73 NaClThreadInterfaceCtor_protected( | 82 NaClThreadInterfaceCtor_protected( |
| 74 new_thread, | 83 new_thread, |
| 75 NaClThreadInterfaceThreadFactory, | 84 NaClThreadInterfaceThreadFactory, |
| 76 factory_data, | 85 factory_data, |
| 77 fn_ptr, | 86 fn_ptr, |
| 78 thread_data, | 87 thread_data, |
| 79 thread_stack_size))) { | 88 thread_stack_size))) { |
| 80 *out_new_thread = new_thread; | 89 *out_new_thread = new_thread; |
| 81 NaClLog(3, | 90 NaClLog(3, |
| 82 "NaClThreadInterfaceThreadFactory: new thread 0x%"NACL_PRIxPTR"\n", | 91 "NaClThreadInterfaceThreadFactory: new thread object" |
| 92 " 0x%"NACL_PRIxPTR" (not started)\n", |
| 83 (uintptr_t) new_thread); | 93 (uintptr_t) new_thread); |
| 84 new_thread = NULL; | 94 new_thread = NULL; |
| 85 } | 95 } |
| 86 free(new_thread); | 96 free(new_thread); |
| 87 NaClLog(3, | 97 NaClLog(3, |
| 88 "Leaving NaClThreadInterfaceThreadFactory, returning %d\n", | 98 "Leaving NaClThreadInterfaceThreadFactory, returning %d\n", |
| 89 rv); | 99 rv); |
| 90 return rv; | 100 return rv; |
| 91 } | 101 } |
| 92 | 102 |
| 93 void NaClThreadInterfaceDtor(struct NaClRefCount *vself) { | 103 void NaClThreadInterfaceDtor(struct NaClRefCount *vself) { |
| 94 struct NaClThreadInterface *self = | 104 struct NaClThreadInterface *self = |
| 95 (struct NaClThreadInterface *) vself; | 105 (struct NaClThreadInterface *) vself; |
| 96 CHECK(self->thread_started == 0); | 106 CHECK(self->thread_started == 0); |
| 97 self->fn_ptr = NULL; | 107 self->fn_ptr = NULL; |
| 98 self->thread_data = NULL; | 108 self->thread_data = NULL; |
| 99 NACL_VTBL(NaClRefCount, self) = &kNaClRefCountVtbl; | 109 NACL_VTBL(NaClRefCount, self) = &kNaClRefCountVtbl; |
| 100 (*NACL_VTBL(NaClRefCount, self)->Dtor)(vself); | 110 (*NACL_VTBL(NaClRefCount, self)->Dtor)(vself); |
| 101 } | 111 } |
| 102 | 112 |
| 103 int NaClThreadInterfaceStartThread(struct NaClThreadInterface *self) { | 113 int NaClThreadInterfaceStartThread(struct NaClThreadInterface *self) { |
| 104 int rv; | 114 int rv; |
| 105 | 115 |
| 106 NaClLog(3, "Entered NaClThreadInterfaceStartThread\n"); | 116 NaClLog(3, |
| 117 "Entered NaClThreadInterfaceStartThread: self 0x%"NACL_PRIxPTR"\n", |
| 118 (uintptr_t) self); |
| 107 CHECK(self->thread_started == 0); | 119 CHECK(self->thread_started == 0); |
| 108 | 120 |
| 109 rv = NaClThreadCtor(&self->thread, | 121 rv = NaClThreadCtor(&self->thread, |
| 110 NaClThreadInterfaceStart, | 122 NaClThreadInterfaceStart, |
| 111 self, | 123 self, |
| 112 self->thread_stack_size); | 124 self->thread_stack_size); |
| 113 if (rv) { | 125 if (rv) { |
| 114 self->thread_started = 1; | 126 self->thread_started = 1; |
| 115 } | 127 } |
| 116 NaClLog(3, "Leaving NaClThreadInterfaceStartThread, rv=%d\n", rv); | 128 NaClLog(3, "Leaving NaClThreadInterfaceStartThread, rv=%d\n", rv); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 goto abort; | 194 goto abort; |
| 183 } | 195 } |
| 184 NaClLog(4, | 196 NaClLog(4, |
| 185 ("NaClThreadInterfaceConstructAndStartThread: thread 0x%"NACL_PRIxPTR | 197 ("NaClThreadInterfaceConstructAndStartThread: thread 0x%"NACL_PRIxPTR |
| 186 " started\n"), | 198 " started\n"), |
| 187 (uintptr_t) new_thread); | 199 (uintptr_t) new_thread); |
| 188 abort: | 200 abort: |
| 189 *out_new_thread = new_thread; | 201 *out_new_thread = new_thread; |
| 190 return new_thread != NULL; | 202 return new_thread != NULL; |
| 191 } | 203 } |
| OLD | NEW |