Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2013 The Native Client Authors. All rights reserved. | |
| 3 * Use of this source code is governed by a BSD-style license that can be | |
| 4 * found in the LICENSE file. | |
| 5 */ | |
| 6 | |
| 7 #include "native_client/src/trusted/service_runtime/osx/mach_thread_map.h" | |
| 8 | |
| 9 #include <pthread.h> | |
| 10 | |
| 11 #include "native_client/src/shared/platform/nacl_sync.h" | |
| 12 #include "native_client/src/shared/platform/nacl_sync_checked.h" | |
| 13 #include "native_client/src/trusted/service_runtime/arch/sel_ldr_arch.h" | |
| 14 #include "native_client/src/trusted/service_runtime/nacl_globals.h" | |
| 15 | |
| 16 #if NACL_ARCH(NACL_BUILD_ARCH) != NACL_x86 || NACL_BUILD_SUBARCH != 32 | |
| 17 | |
| 18 static struct NaClMutex mach_threads_mu; | |
| 19 static mach_port_t mach_threads[NACL_THREAD_MAX]; | |
| 20 | |
| 21 void NaClInitMachThreadMap(void) { | |
| 22 NaClXMutexCtor(&mach_threads_mu); | |
| 23 } | |
| 24 | |
| 25 size_t GetNaClThreadIndexForMachThread(mach_port_t mach_thread) { | |
| 26 size_t nacl_thread_index; | |
| 27 | |
| 28 NaClXMutexLock(&mach_threads_mu); | |
|
Mark Seaborn
2013/02/14 00:37:54
I'd be inclined not to use a lock for this (as on
Mark Mentovai
2013/02/14 19:35:40
Mark Seaborn wrote:
| |
| 29 for (nacl_thread_index = 0; | |
| 30 nacl_thread_index < NACL_THREAD_MAX; | |
| 31 ++nacl_thread_index) { | |
| 32 if (mach_threads[nacl_thread_index] == mach_thread) { | |
| 33 break; | |
| 34 } | |
| 35 } | |
| 36 NaClXMutexUnlock(&mach_threads_mu); | |
| 37 | |
| 38 return nacl_thread_index == NACL_THREAD_MAX ? 0 : nacl_thread_index; | |
|
Mark Seaborn
2013/02/14 00:37:54
Use NACL_TLS_INDEX_INVALID rather than 0
| |
| 39 } | |
| 40 | |
| 41 static void SetMachThreadForNaClThreadIndex(mach_port_t mach_thread, | |
| 42 size_t nacl_thread_index) { | |
| 43 NaClXMutexLock(&mach_threads_mu); | |
| 44 mach_threads[nacl_thread_index] = mach_thread; | |
| 45 NaClXMutexUnlock(&mach_threads_mu); | |
| 46 } | |
| 47 | |
| 48 void SetCurrentMachThreadForNaClThreadIndex(size_t nacl_thread_index) { | |
| 49 mach_port_t mach_thread = pthread_mach_thread_np(pthread_self()); | |
| 50 CHECK(mach_thread != MACH_PORT_NULL); | |
| 51 SetMachThreadForNaClThreadIndex(mach_thread, nacl_thread_index); | |
| 52 } | |
| 53 | |
| 54 void ClearMachThreadForNaClThreadIndex(size_t nacl_thread_index) { | |
| 55 SetMachThreadForNaClThreadIndex(MACH_PORT_NULL, nacl_thread_index); | |
| 56 } | |
| 57 | |
| 58 #endif | |
| OLD | NEW |