@@ -112,11 +112,11 @@ static pthread_key_t tls_key;
112
112
# define tsrm_tls_get () pthread_getspecific(tls_key)
113
113
#endif
114
114
115
- TSRM_TLS uint8_t in_main_thread = 0 ;
116
- TSRM_TLS uint8_t is_thread_shutdown = 0 ;
115
+ TSRM_TLS bool in_main_thread = false ;
116
+ TSRM_TLS bool is_thread_shutdown = false ;
117
117
118
118
/* Startup TSRM (call once for the entire process) */
119
- TSRM_API int tsrm_startup (int expected_threads , int expected_resources , int debug_level , const char * debug_filename )
119
+ TSRM_API bool tsrm_startup (int expected_threads , int expected_resources , int debug_level , const char * debug_filename )
120
120
{/*{{{*/
121
121
#ifdef TSRM_WIN32
122
122
tls_key = TlsAlloc ();
@@ -125,8 +125,8 @@ TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debu
125
125
#endif
126
126
127
127
/* ensure singleton */
128
- in_main_thread = 1 ;
129
- is_thread_shutdown = 0 ;
128
+ in_main_thread = true ;
129
+ is_thread_shutdown = false ;
130
130
131
131
tsrm_error_file = stderr ;
132
132
tsrm_error_set (debug_level , debug_filename );
@@ -135,7 +135,7 @@ TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debu
135
135
tsrm_tls_table = (tsrm_tls_entry * * ) calloc (tsrm_tls_table_size , sizeof (tsrm_tls_entry * ));
136
136
if (!tsrm_tls_table ) {
137
137
TSRM_ERROR ((TSRM_ERROR_LEVEL_ERROR , "Unable to allocate TLS table" ));
138
- is_thread_shutdown = 1 ;
138
+ is_thread_shutdown = true ;
139
139
return 0 ;
140
140
}
141
141
id_count = 0 ;
@@ -144,7 +144,7 @@ TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debu
144
144
resource_types_table = (tsrm_resource_type * ) calloc (resource_types_table_size , sizeof (tsrm_resource_type ));
145
145
if (!resource_types_table ) {
146
146
TSRM_ERROR ((TSRM_ERROR_LEVEL_ERROR , "Unable to allocate resource types table" ));
147
- is_thread_shutdown = 1 ;
147
+ is_thread_shutdown = true ;
148
148
free (tsrm_tls_table );
149
149
return 0 ;
150
150
}
@@ -165,28 +165,24 @@ TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debu
165
165
/* Shutdown TSRM (call once for the entire process) */
166
166
TSRM_API void tsrm_shutdown (void )
167
167
{/*{{{*/
168
- int i ;
169
-
170
168
if (is_thread_shutdown ) {
171
169
/* shutdown must only occur once */
172
170
return ;
173
171
}
174
172
175
- is_thread_shutdown = 1 ;
173
+ is_thread_shutdown = true ;
176
174
177
175
if (!in_main_thread ) {
178
176
/* only the main thread may shutdown tsrm */
179
177
return ;
180
178
}
181
179
182
- for (i = 0 ; i < tsrm_tls_table_size ; i ++ ) {
180
+ for (int i = 0 ; i < tsrm_tls_table_size ; i ++ ) {
183
181
tsrm_tls_entry * p = tsrm_tls_table [i ], * next_p ;
184
182
185
183
while (p ) {
186
- int j ;
187
-
188
184
next_p = p -> next ;
189
- for (j = 0 ; j < p -> count ; j ++ ) {
185
+ for (int j = 0 ; j < p -> count ; j ++ ) {
190
186
if (p -> storage [j ]) {
191
187
if (resource_types_table ) {
192
188
if (!resource_types_table [j ].done ) {
@@ -244,9 +240,7 @@ TSRM_API void tsrm_env_unlock(void) {
244
240
/* enlarge the arrays for the already active threads */
245
241
static void tsrm_update_active_threads (void )
246
242
{/*{{{*/
247
- int i ;
248
-
249
- for (i = 0 ; i < tsrm_tls_table_size ; i ++ ) {
243
+ for (int i = 0 ; i < tsrm_tls_table_size ; i ++ ) {
250
244
tsrm_tls_entry * p = tsrm_tls_table [i ];
251
245
252
246
while (p ) {
@@ -370,8 +364,6 @@ TSRM_API ts_rsrc_id ts_allocate_fast_id(ts_rsrc_id *rsrc_id, size_t *offset, siz
370
364
371
365
static void allocate_new_resource (tsrm_tls_entry * * thread_resources_ptr , THREAD_T thread_id )
372
366
{/*{{{*/
373
- int i ;
374
-
375
367
TSRM_ERROR ((TSRM_ERROR_LEVEL_CORE , "Creating data structures for thread %x" , thread_id ));
376
368
(* thread_resources_ptr ) = (tsrm_tls_entry * ) malloc (TSRM_ALIGNED_SIZE (sizeof (tsrm_tls_entry )) + tsrm_reserved_size );
377
369
(* thread_resources_ptr )-> storage = NULL ;
@@ -389,7 +381,7 @@ static void allocate_new_resource(tsrm_tls_entry **thread_resources_ptr, THREAD_
389
381
if (tsrm_new_thread_begin_handler ) {
390
382
tsrm_new_thread_begin_handler (thread_id );
391
383
}
392
- for (i = 0 ; i < id_count ; i ++ ) {
384
+ for (int i = 0 ; i < id_count ; i ++ ) {
393
385
if (resource_types_table [i ].done ) {
394
386
(* thread_resources_ptr )-> storage [i ] = NULL ;
395
387
} else {
@@ -479,7 +471,6 @@ TSRM_API void *ts_resource_ex(ts_rsrc_id id, THREAD_T *th_id)
479
471
void ts_free_thread (void )
480
472
{/*{{{*/
481
473
tsrm_tls_entry * thread_resources ;
482
- int i ;
483
474
THREAD_T thread_id = tsrm_thread_id ();
484
475
int hash_value ;
485
476
tsrm_tls_entry * last = NULL ;
@@ -492,12 +483,12 @@ void ts_free_thread(void)
492
483
493
484
while (thread_resources ) {
494
485
if (thread_resources -> thread_id == thread_id ) {
495
- for (i = 0 ; i < thread_resources -> count ; i ++ ) {
486
+ for (int i = 0 ; i < thread_resources -> count ; i ++ ) {
496
487
if (resource_types_table [i ].dtor ) {
497
488
resource_types_table [i ].dtor (thread_resources -> storage [i ]);
498
489
}
499
490
}
500
- for (i = 0 ; i < thread_resources -> count ; i ++ ) {
491
+ for (int i = 0 ; i < thread_resources -> count ; i ++ ) {
501
492
if (!resource_types_table [i ].fast_offset ) {
502
493
free (thread_resources -> storage [i ]);
503
494
}
@@ -523,34 +514,33 @@ void ts_free_thread(void)
523
514
/* deallocates all occurrences of a given id */
524
515
void ts_free_id (ts_rsrc_id id )
525
516
{/*{{{*/
526
- int i ;
527
- int j = TSRM_UNSHUFFLE_RSRC_ID (id );
517
+ int rsrc_id = TSRM_UNSHUFFLE_RSRC_ID (id );
528
518
529
519
tsrm_mutex_lock (tsmm_mutex );
530
520
531
521
TSRM_ERROR ((TSRM_ERROR_LEVEL_CORE , "Freeing resource id %d" , id ));
532
522
533
523
if (tsrm_tls_table ) {
534
- for (i = 0 ; i < tsrm_tls_table_size ; i ++ ) {
524
+ for (int i = 0 ; i < tsrm_tls_table_size ; i ++ ) {
535
525
tsrm_tls_entry * p = tsrm_tls_table [i ];
536
526
537
527
while (p ) {
538
- if (p -> count > j && p -> storage [j ]) {
528
+ if (p -> count > rsrc_id && p -> storage [rsrc_id ]) {
539
529
if (resource_types_table ) {
540
- if (resource_types_table [j ].dtor ) {
541
- resource_types_table [j ].dtor (p -> storage [j ]);
530
+ if (resource_types_table [rsrc_id ].dtor ) {
531
+ resource_types_table [rsrc_id ].dtor (p -> storage [rsrc_id ]);
542
532
}
543
- if (!resource_types_table [j ].fast_offset ) {
544
- free (p -> storage [j ]);
533
+ if (!resource_types_table [rsrc_id ].fast_offset ) {
534
+ free (p -> storage [rsrc_id ]);
545
535
}
546
536
}
547
- p -> storage [j ] = NULL ;
537
+ p -> storage [rsrc_id ] = NULL ;
548
538
}
549
539
p = p -> next ;
550
540
}
551
541
}
552
542
}
553
- resource_types_table [j ].done = 1 ;
543
+ resource_types_table [rsrc_id ].done = 1 ;
554
544
555
545
tsrm_mutex_unlock (tsmm_mutex );
556
546
@@ -770,12 +760,12 @@ TSRM_API size_t tsrm_get_ls_cache_tcb_offset(void)
770
760
#endif
771
761
}/*}}}*/
772
762
773
- TSRM_API uint8_t tsrm_is_main_thread (void )
763
+ TSRM_API bool tsrm_is_main_thread (void )
774
764
{/*{{{*/
775
765
return in_main_thread ;
776
766
}/*}}}*/
777
767
778
- TSRM_API uint8_t tsrm_is_shutdown (void )
768
+ TSRM_API bool tsrm_is_shutdown (void )
779
769
{/*{{{*/
780
770
return is_thread_shutdown ;
781
771
}/*}}}*/
0 commit comments