Loading libcutils/include/cutils/threads.h +16 −32 Original line number Diff line number Diff line Loading @@ -14,8 +14,7 @@ * limitations under the License. */ #ifndef _LIBS_CUTILS_THREADS_H #define _LIBS_CUTILS_THREADS_H #pragma once #include <sys/types.h> Loading @@ -29,16 +28,6 @@ extern "C" { #endif // // Deprecated: use android::base::GetThreadId instead, which doesn't truncate on Mac/Windows. // extern pid_t gettid(); // // Deprecated: use `_Thread_local` in C or `thread_local` in C++. // #if !defined(_WIN32) typedef struct { Loading @@ -49,29 +38,24 @@ typedef struct { #define THREAD_STORE_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, 0, 0 } #else // !defined(_WIN32) typedef struct { int lock_init; int has_tls; DWORD tls; CRITICAL_SECTION lock; } thread_store_t; #define THREAD_STORE_INITIALIZER { 0, 0, 0, {0, 0, 0, 0, 0, 0} } #endif // !defined(_WIN32) typedef void (*thread_store_destruct_t)(void* value); #endif extern void* thread_store_get(thread_store_t* store); // // Deprecated: use android::base::GetThreadId instead, which doesn't truncate on Mac/Windows. // extern pid_t gettid(); extern void thread_store_set(thread_store_t* store, void* value, thread_store_destruct_t destroy); // // Deprecated: use `_Thread_local` in C or `thread_local` in C++. // #if !defined(_WIN32) typedef void (*thread_store_destruct_t)(void* x); extern void* thread_store_get(thread_store_t* x) __attribute__((__deprecated__("use thread_local instead"))); extern void thread_store_set(thread_store_t* x, void* y, thread_store_destruct_t z) __attribute__((__deprecated__("use thread_local instead"))); #endif #ifdef __cplusplus } #endif #endif /* _LIBS_CUTILS_THREADS_H */ libcutils/threads.cpp +1 −38 Original line number Diff line number Diff line Loading @@ -47,7 +47,6 @@ pid_t gettid() { #endif // __ANDROID__ #if !defined(_WIN32) void* thread_store_get( thread_store_t* store ) { if (!store->has_tls) Loading @@ -72,40 +71,4 @@ extern void thread_store_set( thread_store_t* store, pthread_setspecific( store->tls, value ); } #else /* !defined(_WIN32) */ void* thread_store_get( thread_store_t* store ) { if (!store->has_tls) return NULL; return (void*) TlsGetValue( store->tls ); } void thread_store_set( thread_store_t* store, void* value, thread_store_destruct_t /*destroy*/ ) { /* XXX: can't use destructor on thread exit */ if (!store->lock_init) { store->lock_init = -1; InitializeCriticalSection( &store->lock ); store->lock_init = -2; } else while (store->lock_init != -2) { Sleep(10); /* 10ms */ } EnterCriticalSection( &store->lock ); if (!store->has_tls) { store->tls = TlsAlloc(); if (store->tls == TLS_OUT_OF_INDEXES) { LeaveCriticalSection( &store->lock ); return; } store->has_tls = 1; } LeaveCriticalSection( &store->lock ); TlsSetValue( store->tls, value ); } #endif /* !defined(_WIN32) */ #endif Loading
libcutils/include/cutils/threads.h +16 −32 Original line number Diff line number Diff line Loading @@ -14,8 +14,7 @@ * limitations under the License. */ #ifndef _LIBS_CUTILS_THREADS_H #define _LIBS_CUTILS_THREADS_H #pragma once #include <sys/types.h> Loading @@ -29,16 +28,6 @@ extern "C" { #endif // // Deprecated: use android::base::GetThreadId instead, which doesn't truncate on Mac/Windows. // extern pid_t gettid(); // // Deprecated: use `_Thread_local` in C or `thread_local` in C++. // #if !defined(_WIN32) typedef struct { Loading @@ -49,29 +38,24 @@ typedef struct { #define THREAD_STORE_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, 0, 0 } #else // !defined(_WIN32) typedef struct { int lock_init; int has_tls; DWORD tls; CRITICAL_SECTION lock; } thread_store_t; #define THREAD_STORE_INITIALIZER { 0, 0, 0, {0, 0, 0, 0, 0, 0} } #endif // !defined(_WIN32) typedef void (*thread_store_destruct_t)(void* value); #endif extern void* thread_store_get(thread_store_t* store); // // Deprecated: use android::base::GetThreadId instead, which doesn't truncate on Mac/Windows. // extern pid_t gettid(); extern void thread_store_set(thread_store_t* store, void* value, thread_store_destruct_t destroy); // // Deprecated: use `_Thread_local` in C or `thread_local` in C++. // #if !defined(_WIN32) typedef void (*thread_store_destruct_t)(void* x); extern void* thread_store_get(thread_store_t* x) __attribute__((__deprecated__("use thread_local instead"))); extern void thread_store_set(thread_store_t* x, void* y, thread_store_destruct_t z) __attribute__((__deprecated__("use thread_local instead"))); #endif #ifdef __cplusplus } #endif #endif /* _LIBS_CUTILS_THREADS_H */
libcutils/threads.cpp +1 −38 Original line number Diff line number Diff line Loading @@ -47,7 +47,6 @@ pid_t gettid() { #endif // __ANDROID__ #if !defined(_WIN32) void* thread_store_get( thread_store_t* store ) { if (!store->has_tls) Loading @@ -72,40 +71,4 @@ extern void thread_store_set( thread_store_t* store, pthread_setspecific( store->tls, value ); } #else /* !defined(_WIN32) */ void* thread_store_get( thread_store_t* store ) { if (!store->has_tls) return NULL; return (void*) TlsGetValue( store->tls ); } void thread_store_set( thread_store_t* store, void* value, thread_store_destruct_t /*destroy*/ ) { /* XXX: can't use destructor on thread exit */ if (!store->lock_init) { store->lock_init = -1; InitializeCriticalSection( &store->lock ); store->lock_init = -2; } else while (store->lock_init != -2) { Sleep(10); /* 10ms */ } EnterCriticalSection( &store->lock ); if (!store->has_tls) { store->tls = TlsAlloc(); if (store->tls == TLS_OUT_OF_INDEXES) { LeaveCriticalSection( &store->lock ); return; } store->has_tls = 1; } LeaveCriticalSection( &store->lock ); TlsSetValue( store->tls, value ); } #endif /* !defined(_WIN32) */ #endif