|
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/trusted/service_runtime/arch/sel_ldr_arch.h" | |
12 #include "native_client/src/trusted/service_runtime/nacl_globals.h" | |
13 | |
14 #if NACL_ARCH(NACL_BUILD_ARCH) != NACL_x86 || NACL_BUILD_SUBARCH != 32 | |
Mark Seaborn
2013/02/14 23:55:02
Again, probably better to say:
#if NACL_ARCH(NACL_
| |
15 | |
16 static mach_port_t mach_threads[NACL_THREAD_MAX]; | |
17 | |
18 size_t NaClGetThreadIndexForMachThread(mach_port_t mach_thread) { | |
19 size_t nacl_thread_index; | |
20 | |
21 DCHECK(mach_thread != MACH_PORT_NULL); | |
22 | |
23 CHECK(NACL_TLS_INDEX_INVALID < NACL_THREAD_MAX); /* Skip the invalid slot. */ | |
24 for (nacl_thread_index = NACL_TLS_INDEX_INVALID + 1; | |
25 nacl_thread_index < NACL_THREAD_MAX; | |
26 ++nacl_thread_index) { | |
27 if (mach_threads[nacl_thread_index] == mach_thread) { | |
28 break; | |
29 } | |
30 } | |
31 | |
32 return nacl_thread_index == NACL_THREAD_MAX ? NACL_TLS_INDEX_INVALID : | |
33 nacl_thread_index; | |
34 } | |
35 | |
36 void NaClSetCurrentMachThreadForThreadIndex(size_t nacl_thread_index) { | |
37 mach_port_t mach_thread = pthread_mach_thread_np(pthread_self()); | |
Mark Seaborn
2013/02/14 23:55:02
It might be worth commenting that:
We assume that
Mark Mentovai
2013/02/15 17:36:42
Mark Seaborn wrote:
Mark Seaborn
2013/02/15 22:48:08
What's this interface called?
Whether it's worth
| |
38 CHECK(mach_thread != MACH_PORT_NULL); | |
39 | |
40 DCHECK(nacl_thread_index > NACL_TLS_INDEX_INVALID && | |
41 nacl_thread_index < NACL_THREAD_MAX); | |
42 DCHECK(mach_threads[nacl_thread_index] == MACH_PORT_NULL); | |
43 DCHECK(NaClGetThreadIndexForMachThread(mach_thread) == | |
44 NACL_TLS_INDEX_INVALID); | |
45 | |
46 mach_threads[nacl_thread_index] = mach_thread; | |
47 } | |
48 | |
49 void NaClClearMachThreadForThreadIndex(size_t nacl_thread_index) { | |
50 DCHECK(nacl_thread_index > NACL_TLS_INDEX_INVALID && | |
51 nacl_thread_index < NACL_THREAD_MAX); | |
52 DCHECK(mach_threads[nacl_thread_index] == | |
53 pthread_mach_thread_np(pthread_self())); | |
54 | |
55 mach_threads[nacl_thread_index] = MACH_PORT_NULL; | |
56 } | |
57 | |
58 #endif | |
OLD | NEW |