Skip to content

Commit 77692ae

Browse files
Treehugger RobotGerrit Code Review
Treehugger Robot
authored and
Gerrit Code Review
committed
Merge "Make libcutils' thread local stuff more clearly deprecated."
2 parents cd91f86 + 0675702 commit 77692ae

File tree

2 files changed

+17
-70
lines changed

2 files changed

+17
-70
lines changed

libcutils/include/cutils/threads.h

+16-32
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
#ifndef _LIBS_CUTILS_THREADS_H
18-
#define _LIBS_CUTILS_THREADS_H
17+
#pragma once
1918

2019
#include <sys/types.h>
2120

@@ -29,16 +28,6 @@
2928
extern "C" {
3029
#endif
3130

32-
//
33-
// Deprecated: use android::base::GetThreadId instead, which doesn't truncate on Mac/Windows.
34-
//
35-
36-
extern pid_t gettid();
37-
38-
//
39-
// Deprecated: use `_Thread_local` in C or `thread_local` in C++.
40-
//
41-
4231
#if !defined(_WIN32)
4332

4433
typedef struct {
@@ -49,29 +38,24 @@ typedef struct {
4938

5039
#define THREAD_STORE_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, 0, 0 }
5140

52-
#else // !defined(_WIN32)
53-
54-
typedef struct {
55-
int lock_init;
56-
int has_tls;
57-
DWORD tls;
58-
CRITICAL_SECTION lock;
59-
} thread_store_t;
60-
61-
#define THREAD_STORE_INITIALIZER { 0, 0, 0, {0, 0, 0, 0, 0, 0} }
62-
63-
#endif // !defined(_WIN32)
64-
65-
typedef void (*thread_store_destruct_t)(void* value);
41+
#endif
6642

67-
extern void* thread_store_get(thread_store_t* store);
43+
//
44+
// Deprecated: use android::base::GetThreadId instead, which doesn't truncate on Mac/Windows.
45+
//
46+
extern pid_t gettid();
6847

69-
extern void thread_store_set(thread_store_t* store,
70-
void* value,
71-
thread_store_destruct_t destroy);
48+
//
49+
// Deprecated: use `_Thread_local` in C or `thread_local` in C++.
50+
//
51+
#if !defined(_WIN32)
52+
typedef void (*thread_store_destruct_t)(void* x);
53+
extern void* thread_store_get(thread_store_t* x)
54+
__attribute__((__deprecated__("use thread_local instead")));
55+
extern void thread_store_set(thread_store_t* x, void* y, thread_store_destruct_t z)
56+
__attribute__((__deprecated__("use thread_local instead")));
57+
#endif
7258

7359
#ifdef __cplusplus
7460
}
7561
#endif
76-
77-
#endif /* _LIBS_CUTILS_THREADS_H */

libcutils/threads.cpp

+1-38
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ pid_t gettid() {
4747
#endif // __ANDROID__
4848

4949
#if !defined(_WIN32)
50-
5150
void* thread_store_get( thread_store_t* store )
5251
{
5352
if (!store->has_tls)
@@ -72,40 +71,4 @@ extern void thread_store_set( thread_store_t* store,
7271

7372
pthread_setspecific( store->tls, value );
7473
}
75-
76-
#else /* !defined(_WIN32) */
77-
void* thread_store_get( thread_store_t* store )
78-
{
79-
if (!store->has_tls)
80-
return NULL;
81-
82-
return (void*) TlsGetValue( store->tls );
83-
}
84-
85-
void thread_store_set( thread_store_t* store,
86-
void* value,
87-
thread_store_destruct_t /*destroy*/ )
88-
{
89-
/* XXX: can't use destructor on thread exit */
90-
if (!store->lock_init) {
91-
store->lock_init = -1;
92-
InitializeCriticalSection( &store->lock );
93-
store->lock_init = -2;
94-
} else while (store->lock_init != -2) {
95-
Sleep(10); /* 10ms */
96-
}
97-
98-
EnterCriticalSection( &store->lock );
99-
if (!store->has_tls) {
100-
store->tls = TlsAlloc();
101-
if (store->tls == TLS_OUT_OF_INDEXES) {
102-
LeaveCriticalSection( &store->lock );
103-
return;
104-
}
105-
store->has_tls = 1;
106-
}
107-
LeaveCriticalSection( &store->lock );
108-
109-
TlsSetValue( store->tls, value );
110-
}
111-
#endif /* !defined(_WIN32) */
74+
#endif

0 commit comments

Comments
 (0)