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