@@ -94,6 +94,8 @@ static FILE *tsrm_error_file;
94
94
static pthread_key_t tls_key ;
95
95
#elif defined(TSRM_ST )
96
96
static int tls_key ;
97
+ #elif defined(TSRM_WIN32 )
98
+ static DWORD tls_key ;
97
99
#endif
98
100
99
101
@@ -107,6 +109,8 @@ TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debu
107
109
#elif defined(TSRM_ST )
108
110
st_init ();
109
111
st_key_create (& tls_key , 0 );
112
+ #elif defined(TSRM_WIN32 )
113
+ tls_key = TlsAlloc ();
110
114
#endif
111
115
112
116
tsrm_error_file = stderr ;
@@ -175,7 +179,9 @@ TSRM_API void tsrm_shutdown(void)
175
179
#if defined(GNUPTH )
176
180
pth_kill ();
177
181
#elif defined(PTHREADS )
178
- pthread_key_delete ( tls_key );
182
+ pthread_key_delete (tls_key );
183
+ #elif defined(TSRM_WIN32 )
184
+ TlsFree (tls_key );
179
185
#endif
180
186
}
181
187
@@ -248,9 +254,11 @@ static void allocate_new_resource(tsrm_tls_entry **thread_resources_ptr, THREAD_
248
254
249
255
#if defined(PTHREADS )
250
256
/* Set thread local storage to this new thread resources structure */
251
- pthread_setspecific ( tls_key , (void * )* thread_resources_ptr );
257
+ pthread_setspecific (tls_key , (void * ) * thread_resources_ptr );
252
258
#elif defined(TSRM_ST )
253
259
st_thread_setspecific (tls_key , (void * ) * thread_resources_ptr );
260
+ #elif defined(TSRM_WIN32 )
261
+ TlsSetValue (tls_key , (void * ) * thread_resources_ptr );
254
262
#endif
255
263
256
264
if (tsrm_new_thread_begin_handler ) {
@@ -288,6 +296,8 @@ TSRM_API void *ts_resource_ex(ts_rsrc_id id, THREAD_T *th_id)
288
296
thread_resources = pthread_getspecific (tls_key );
289
297
#elif defined(TSRM_ST )
290
298
thread_resources = st_thread_getspecific (tls_key );
299
+ #elif defined(TSRM_WIN32 )
300
+ thread_resources = TlsGetValue (tls_key );
291
301
#else
292
302
thread_resources = NULL ;
293
303
#endif
@@ -370,6 +380,8 @@ void ts_free_thread(void)
370
380
}
371
381
#if defined(PTHREADS )
372
382
pthread_setspecific (tls_key , 0 );
383
+ #elif defined(TSRM_WIN32 )
384
+ TlsSetValue (tls_key , 0 );
373
385
#endif
374
386
free (thread_resources );
375
387
break ;
0 commit comments