@@ -117,7 +117,7 @@ TSRM_TLS uint8_t is_thread_shutdown = 0;
117
117
118
118
/* Startup TSRM (call once for the entire process) */
119
119
TSRM_API int tsrm_startup (int expected_threads , int expected_resources , int debug_level , char * debug_filename )
120
- {/*{{{*/
120
+ {
121
121
#if defined(TSRM_WIN32 )
122
122
tls_key = TlsAlloc ();
123
123
#else
@@ -159,12 +159,12 @@ TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debu
159
159
tsrm_env_mutex = tsrm_mutex_alloc ();
160
160
161
161
return 1 ;
162
- }/*}}}*/
162
+ }
163
163
164
164
165
165
/* Shutdown TSRM (call once for the entire process) */
166
166
TSRM_API void tsrm_shutdown (void )
167
- {/*{{{*/
167
+ {
168
168
int i ;
169
169
170
170
if (is_thread_shutdown ) {
@@ -224,21 +224,21 @@ TSRM_API void tsrm_shutdown(void)
224
224
225
225
tsrm_reserved_pos = 0 ;
226
226
tsrm_reserved_size = 0 ;
227
- }/*}}}*/
227
+ }
228
228
229
- /* {{{ */
229
+ /* */
230
230
/* environ lock api */
231
231
TSRM_API void tsrm_env_lock () {
232
232
tsrm_mutex_lock (tsrm_env_mutex );
233
233
}
234
234
235
235
TSRM_API void tsrm_env_unlock () {
236
236
tsrm_mutex_unlock (tsrm_env_mutex );
237
- } /* }}} */
237
+ }
238
238
239
239
/* enlarge the arrays for the already active threads */
240
240
static void tsrm_update_active_threads (void )
241
- {/*{{{*/
241
+ {
242
242
int i ;
243
243
244
244
for (i = 0 ; i < tsrm_tls_table_size ; i ++ ) {
@@ -264,12 +264,12 @@ static void tsrm_update_active_threads(void)
264
264
p = p -> next ;
265
265
}
266
266
}
267
- }/*}}}*/
267
+ }
268
268
269
269
270
270
/* allocates a new thread-safe-resource id */
271
271
TSRM_API ts_rsrc_id ts_allocate_id (ts_rsrc_id * rsrc_id , size_t size , ts_allocate_ctor ctor , ts_allocate_dtor dtor )
272
- {/*{{{*/
272
+ {
273
273
TSRM_ERROR ((TSRM_ERROR_LEVEL_CORE , "Obtaining a new resource id, %d bytes" , size ));
274
274
275
275
tsrm_mutex_lock (tsmm_mutex );
@@ -302,20 +302,20 @@ TSRM_API ts_rsrc_id ts_allocate_id(ts_rsrc_id *rsrc_id, size_t size, ts_allocate
302
302
303
303
TSRM_ERROR ((TSRM_ERROR_LEVEL_CORE , "Successfully allocated new resource id %d" , * rsrc_id ));
304
304
return * rsrc_id ;
305
- }/*}}}*/
305
+ }
306
306
307
307
308
308
/* Reserve space for fast thread-safe-resources */
309
309
TSRM_API void tsrm_reserve (size_t size )
310
- {/*{{{*/
310
+ {
311
311
tsrm_reserved_pos = 0 ;
312
312
tsrm_reserved_size = TSRM_ALIGNED_SIZE (size );
313
- }/*}}}*/
313
+ }
314
314
315
315
316
316
/* allocates a new fast thread-safe-resource id */
317
317
TSRM_API ts_rsrc_id ts_allocate_fast_id (ts_rsrc_id * rsrc_id , size_t * offset , size_t size , ts_allocate_ctor ctor , ts_allocate_dtor dtor )
318
- {/*{{{*/
318
+ {
319
319
TSRM_ERROR ((TSRM_ERROR_LEVEL_CORE , "Obtaining a new fast resource id, %d bytes" , size ));
320
320
321
321
tsrm_mutex_lock (tsmm_mutex );
@@ -360,11 +360,11 @@ TSRM_API ts_rsrc_id ts_allocate_fast_id(ts_rsrc_id *rsrc_id, size_t *offset, siz
360
360
361
361
TSRM_ERROR ((TSRM_ERROR_LEVEL_CORE , "Successfully allocated new resource id %d" , * rsrc_id ));
362
362
return * rsrc_id ;
363
- }/*}}}*/
363
+ }
364
364
365
365
366
366
static void allocate_new_resource (tsrm_tls_entry * * thread_resources_ptr , THREAD_T thread_id )
367
- {/*{{{*/
367
+ {
368
368
int i ;
369
369
370
370
TSRM_ERROR ((TSRM_ERROR_LEVEL_CORE , "Creating data structures for thread %x" , thread_id ));
@@ -404,12 +404,12 @@ static void allocate_new_resource(tsrm_tls_entry **thread_resources_ptr, THREAD_
404
404
}
405
405
406
406
tsrm_mutex_unlock (tsmm_mutex );
407
- }/*}}}*/
407
+ }
408
408
409
409
410
410
/* fetches the requested resource for the current thread */
411
411
TSRM_API void * ts_resource_ex (ts_rsrc_id id , THREAD_T * th_id )
412
- {/*{{{*/
412
+ {
413
413
THREAD_T thread_id ;
414
414
int hash_value ;
415
415
tsrm_tls_entry * thread_resources ;
@@ -467,12 +467,12 @@ TSRM_API void *ts_resource_ex(ts_rsrc_id id, THREAD_T *th_id)
467
467
* changes to the structure as we read it.
468
468
*/
469
469
TSRM_SAFE_RETURN_RSRC (thread_resources -> storage , id , thread_resources -> count );
470
- }/*}}}*/
470
+ }
471
471
472
472
473
473
/* frees all resources allocated for the current thread */
474
474
void ts_free_thread (void )
475
- {/*{{{*/
475
+ {
476
476
tsrm_tls_entry * thread_resources ;
477
477
int i ;
478
478
THREAD_T thread_id = tsrm_thread_id ();
@@ -513,11 +513,11 @@ void ts_free_thread(void)
513
513
thread_resources = thread_resources -> next ;
514
514
}
515
515
tsrm_mutex_unlock (tsmm_mutex );
516
- }/*}}}*/
516
+ }
517
517
518
518
/* deallocates all occurrences of a given id */
519
519
void ts_free_id (ts_rsrc_id id )
520
- {/*{{{*/
520
+ {
521
521
int i ;
522
522
int j = TSRM_UNSHUFFLE_RSRC_ID (id );
523
523
@@ -548,7 +548,7 @@ void ts_free_id(ts_rsrc_id id)
548
548
tsrm_mutex_unlock (tsmm_mutex );
549
549
550
550
TSRM_ERROR ((TSRM_ERROR_LEVEL_CORE , "Successfully freed resource id %d" , id ));
551
- }/*}}}*/
551
+ }
552
552
553
553
554
554
/*
@@ -557,18 +557,18 @@ void ts_free_id(ts_rsrc_id id)
557
557
558
558
/* Obtain the current thread id */
559
559
TSRM_API THREAD_T tsrm_thread_id (void )
560
- {/*{{{*/
560
+ {
561
561
#ifdef TSRM_WIN32
562
562
return GetCurrentThreadId ();
563
563
#else
564
564
return pthread_self ();
565
565
#endif
566
- }/*}}}*/
566
+ }
567
567
568
568
569
569
/* Allocate a mutex */
570
570
TSRM_API MUTEX_T tsrm_mutex_alloc (void )
571
- {/*{{{*/
571
+ {
572
572
MUTEX_T mutexp ;
573
573
#ifdef TSRM_WIN32
574
574
mutexp = malloc (sizeof (CRITICAL_SECTION ));
@@ -581,12 +581,12 @@ TSRM_API MUTEX_T tsrm_mutex_alloc(void)
581
581
printf ("Mutex created thread: %d\n" ,mythreadid ());
582
582
#endif
583
583
return ( mutexp );
584
- }/*}}}*/
584
+ }
585
585
586
586
587
587
/* Free a mutex */
588
588
TSRM_API void tsrm_mutex_free (MUTEX_T mutexp )
589
- {/*{{{*/
589
+ {
590
590
if (mutexp ) {
591
591
#ifdef TSRM_WIN32
592
592
DeleteCriticalSection (mutexp );
@@ -599,78 +599,78 @@ TSRM_API void tsrm_mutex_free(MUTEX_T mutexp)
599
599
#ifdef THR_DEBUG
600
600
printf ("Mutex freed thread: %d\n" ,mythreadid ());
601
601
#endif
602
- }/*}}}*/
602
+ }
603
603
604
604
605
605
/*
606
606
Lock a mutex.
607
607
A return value of 0 indicates success
608
608
*/
609
609
TSRM_API int tsrm_mutex_lock (MUTEX_T mutexp )
610
- {/*{{{*/
610
+ {
611
611
TSRM_ERROR ((TSRM_ERROR_LEVEL_INFO , "Mutex locked thread: %ld" , tsrm_thread_id ()));
612
612
#ifdef TSRM_WIN32
613
613
EnterCriticalSection (mutexp );
614
614
return 0 ;
615
615
#else
616
616
return pthread_mutex_lock (mutexp );
617
617
#endif
618
- }/*}}}*/
618
+ }
619
619
620
620
621
621
/*
622
622
Unlock a mutex.
623
623
A return value of 0 indicates success
624
624
*/
625
625
TSRM_API int tsrm_mutex_unlock (MUTEX_T mutexp )
626
- {/*{{{*/
626
+ {
627
627
TSRM_ERROR ((TSRM_ERROR_LEVEL_INFO , "Mutex unlocked thread: %ld" , tsrm_thread_id ()));
628
628
#ifdef TSRM_WIN32
629
629
LeaveCriticalSection (mutexp );
630
630
return 0 ;
631
631
#else
632
632
return pthread_mutex_unlock (mutexp );
633
633
#endif
634
- }/*}}}*/
634
+ }
635
635
636
636
/*
637
637
Changes the signal mask of the calling thread
638
638
*/
639
639
#ifdef HAVE_SIGPROCMASK
640
640
TSRM_API int tsrm_sigmask (int how , const sigset_t * set , sigset_t * oldset )
641
- {/*{{{*/
641
+ {
642
642
TSRM_ERROR ((TSRM_ERROR_LEVEL_INFO , "Changed sigmask in thread: %ld" , tsrm_thread_id ()));
643
643
644
644
return pthread_sigmask (how , set , oldset );
645
- }/*}}}*/
645
+ }
646
646
#endif
647
647
648
648
649
649
TSRM_API void * tsrm_set_new_thread_begin_handler (tsrm_thread_begin_func_t new_thread_begin_handler )
650
- {/*{{{*/
650
+ {
651
651
void * retval = (void * ) tsrm_new_thread_begin_handler ;
652
652
653
653
tsrm_new_thread_begin_handler = new_thread_begin_handler ;
654
654
return retval ;
655
- }/*}}}*/
655
+ }
656
656
657
657
658
658
TSRM_API void * tsrm_set_new_thread_end_handler (tsrm_thread_end_func_t new_thread_end_handler )
659
- {/*{{{*/
659
+ {
660
660
void * retval = (void * ) tsrm_new_thread_end_handler ;
661
661
662
662
tsrm_new_thread_end_handler = new_thread_end_handler ;
663
663
return retval ;
664
- }/*}}}*/
664
+ }
665
665
666
666
667
667
TSRM_API void * tsrm_set_shutdown_handler (tsrm_shutdown_func_t shutdown_handler )
668
- {/*{{{*/
668
+ {
669
669
void * retval = (void * ) tsrm_shutdown_handler ;
670
670
671
671
tsrm_shutdown_handler = shutdown_handler ;
672
672
return retval ;
673
- }/*}}}*/
673
+ }
674
674
675
675
676
676
/*
@@ -679,7 +679,7 @@ TSRM_API void *tsrm_set_shutdown_handler(tsrm_shutdown_func_t shutdown_handler)
679
679
680
680
#if TSRM_DEBUG
681
681
int tsrm_error (int level , const char * format , ...)
682
- {/*{{{*/
682
+ {
683
683
if (level <=tsrm_error_level ) {
684
684
va_list args ;
685
685
int size ;
@@ -694,12 +694,12 @@ int tsrm_error(int level, const char *format, ...)
694
694
} else {
695
695
return 0 ;
696
696
}
697
- }/*}}}*/
697
+ }
698
698
#endif
699
699
700
700
701
701
void tsrm_error_set (int level , char * debug_filename )
702
- {/*{{{*/
702
+ {
703
703
tsrm_error_level = level ;
704
704
705
705
#if TSRM_DEBUG
@@ -716,16 +716,16 @@ void tsrm_error_set(int level, char *debug_filename)
716
716
tsrm_error_file = stderr ;
717
717
}
718
718
#endif
719
- }/*}}}*/
719
+ }
720
720
721
721
TSRM_API void * tsrm_get_ls_cache (void )
722
- {/*{{{*/
722
+ {
723
723
return tsrm_tls_get ();
724
- }/*}}}*/
724
+ }
725
725
726
726
/* Returns offset of tsrm_ls_cache slot from Thread Control Block address */
727
727
TSRM_API size_t tsrm_get_ls_cache_tcb_offset (void )
728
- {/*{{{*/
728
+ {
729
729
#if defined(__APPLE__ ) && defined(__x86_64__ )
730
730
// TODO: Implement support for fast JIT ZTS code ???
731
731
return 0 ;
@@ -744,25 +744,25 @@ TSRM_API size_t tsrm_get_ls_cache_tcb_offset(void)
744
744
#else
745
745
return 0 ;
746
746
#endif
747
- }/*}}}*/
747
+ }
748
748
749
749
TSRM_API uint8_t tsrm_is_main_thread (void )
750
- {/*{{{*/
750
+ {
751
751
return in_main_thread ;
752
- }/*}}}*/
752
+ }
753
753
754
754
TSRM_API uint8_t tsrm_is_shutdown (void )
755
- {/*{{{*/
755
+ {
756
756
return is_thread_shutdown ;
757
- }/*}}}*/
757
+ }
758
758
759
759
TSRM_API const char * tsrm_api_name (void )
760
- {/*{{{*/
760
+ {
761
761
#if defined(TSRM_WIN32 )
762
762
return "Windows Threads" ;
763
763
#else
764
764
return "POSIX Threads" ;
765
765
#endif
766
- }/*}}}*/
766
+ }
767
767
768
768
#endif /* ZTS */
0 commit comments