@@ -63,6 +63,10 @@ static int tsrm_debug_status;
63
63
/* Startup TSRM (call once for the entire process) */
64
64
TSRM_API int tsrm_startup (int expected_threads , int expected_resources , int debug_status )
65
65
{
66
+ #if defined(GNUPTH )
67
+ pth_init ();
68
+ #endif
69
+
66
70
tsrm_tls_table_size = expected_threads ;
67
71
tsrm_tls_table = (tsrm_tls_entry * * ) calloc (tsrm_tls_table_size , sizeof (tsrm_tls_entry * ));
68
72
if (!tsrm_tls_table ) {
@@ -116,6 +120,9 @@ TSRM_API void tsrm_shutdown(void)
116
120
}
117
121
tsrm_mutex_free (tsmm_mutex );
118
122
tsrm_debug ("Shutdown TSRM\n" );
123
+ #if defined(GNUPTH )
124
+ pth_kill ();
125
+ #endif
119
126
}
120
127
121
128
@@ -301,6 +308,8 @@ TSRM_API THREAD_T tsrm_thread_id(void)
301
308
{
302
309
#ifdef WIN32
303
310
return GetCurrentThreadId ();
311
+ #elif defined(GNUPTH )
312
+ return pth_self ();
304
313
#elif defined(PTHREADS )
305
314
return pthread_self ();
306
315
#elif defined(NSAPI )
@@ -318,6 +327,9 @@ TSRM_API MUTEX_T tsrm_mutex_alloc( void )
318
327
319
328
#ifdef WIN32
320
329
mutexp = CreateMutex (NULL ,FALSE,NULL );
330
+ #elif defined(GNUPTH )
331
+ mutexp = (MUTEX_T ) malloc (sizeof (* mutexp ));
332
+ pth_mutex_init (mutexp );
321
333
#elif defined(PTHREADS )
322
334
mutexp = (pthread_mutex_t * )malloc (sizeof (pthread_mutex_t ));
323
335
pthread_mutex_init (mutexp ,NULL );
@@ -339,8 +351,11 @@ TSRM_API void tsrm_mutex_free( MUTEX_T mutexp )
339
351
if (mutexp ) {
340
352
#ifdef WIN32
341
353
CloseHandle (mutexp );
354
+ #elif defined(GNUPTH )
355
+ free (mutexp );
342
356
#elif defined(PTHREADS )
343
357
pthread_mutex_destroy (mutexp );
358
+ free (mutexp );
344
359
#elif defined(NSAPI )
345
360
crit_terminate (mutexp );
346
361
#elif defined(PI3WEB )
@@ -361,6 +376,8 @@ TSRM_API int tsrm_mutex_lock( MUTEX_T mutexp )
361
376
#endif
362
377
#ifdef WIN32
363
378
return WaitForSingleObject (mutexp ,1000 );
379
+ #elif defined(GNUPTH )
380
+ return pth_mutex_acquire (mutexp , 0 , NULL );
364
381
#elif defined(PTHREADS )
365
382
return pthread_mutex_lock (mutexp );
366
383
#elif defined(NSAPI )
@@ -379,6 +396,8 @@ TSRM_API int tsrm_mutex_unlock( MUTEX_T mutexp )
379
396
#endif
380
397
#ifdef WIN32
381
398
return ReleaseMutex (mutexp );
399
+ #elif defined(GNUPTH )
400
+ return pth_mutex_release (mutexp );
382
401
#elif defined(PTHREADS )
383
402
return pthread_mutex_unlock (mutexp );
384
403
#elif defined(NSAPI )
0 commit comments