@@ -50,9 +50,8 @@ typedef enum {
50
50
TST_THREAD_SIGNAL_STATE_WAIT = 0 ,
51
51
TST_THREAD_SIGNAL_STATE_GOON
52
52
} tst_thread_signal_state ;
53
- /*
54
- * Local declarations
55
- */
53
+
54
+
56
55
/* saving thread_ids for global access, also available in main via struct thread_env */
57
56
static pthread_t * tst_thread_tid_array ;
58
57
@@ -67,28 +66,25 @@ int tst_thread_signals_count = 0; /* number of waiting threads */
67
66
static MPI_Request * tst_thread_requests_array ;
68
67
int tst_thread_requests_max = 0 ;
69
68
70
- /*
71
- * Function: worker_done
72
- */
73
- static inline void worker_done (void )
74
- {
69
+
70
+ /** \brief Function to signal when a worker thread finished execution of his work */
71
+ static inline void worker_done () {
75
72
pthread_mutex_lock (& working_mutex );
76
73
working -- ;
77
- if (0 == working )
78
- pthread_cond_signal (& working_cond );
79
- pthread_mutex_unlock (& working_mutex );
74
+ if (0 == working ) {
75
+ pthread_cond_signal (& working_cond );
76
+ }
77
+ pthread_mutex_unlock (& working_mutex );
80
78
}
81
79
82
- static inline void worker_barrier (void )
83
- {
84
- pthread_mutex_lock (& working_mutex );
85
- while (working > 0 )
86
- {
87
- tst_output_printf (DEBUG_LOG , TST_REPORT_MAX , "(Rank:%d) worker_barrier still working:%d\n" ,
88
- tst_global_rank , working );
89
- pthread_cond_wait (& working_cond , & working_mutex );
90
- }
91
- pthread_mutex_unlock (& working_mutex );
80
+
81
+ /** \brief Barrier to synchronize all worker threads finishing their work */
82
+ static inline void worker_barrier () {
83
+ pthread_mutex_lock (& working_mutex );
84
+ while (working > 0 ) {
85
+ pthread_cond_wait (& working_cond , & working_mutex );
86
+ }
87
+ pthread_mutex_unlock (& working_mutex );
92
88
}
93
89
94
90
@@ -179,9 +175,7 @@ int tst_thread_init(int max_threads, struct tst_thread_env_t ***thread_env) {
179
175
assert (max_threads > 0 );
180
176
assert (thread_env != NULL );
181
177
182
- /*
183
- * Without the pthread_mutex_lock, as no threads are started, yet
184
- */
178
+ /* Without the pthread_mutex_lock, as no threads are started, yet */
185
179
working = 0 ;
186
180
187
181
tst_output_printf (DEBUG_LOG , TST_REPORT_MAX , "(Rank:%d) tst_thread_init: max_threads:%d sizeof (struct tst_thread_env_t):%d\n" ,
@@ -207,7 +201,6 @@ int tst_thread_init(int max_threads, struct tst_thread_env_t ***thread_env) {
207
201
if (ret != 0 )
208
202
ERROR (errno , "tst_thread_init: pthread_create" );
209
203
tst_thread_tid_array [i + 1 ] = env [i ]-> tid ;
210
-
211
204
num_threads ++ ;
212
205
}
213
206
@@ -267,49 +260,57 @@ inline int tst_thread_get_num (void)
267
260
return -1 ;
268
261
}
269
262
270
- /*
271
- * Assign all running threads the same test-environment
263
+ /** \brief Reset test environment of all running threads
264
+ *
265
+ * \param[out] thread_env list of thread environments
266
+ *
267
+ * \return always 0
272
268
*/
273
- int tst_thread_assign_reset (struct tst_thread_env_t * * thread_env )
269
+ int tst_thread_assign_reset (struct tst_thread_env_t * * thread_env )
274
270
{
275
271
int i ;
276
- for (i = 0 ; i < num_threads ; i ++ )
277
- {
278
- memset (& (thread_env [i ]-> env ), 0 , sizeof (struct tst_env ));
279
- thread_env [i ]-> tst_init_func = NULL ;
280
- thread_env [i ]-> tst_run_func = NULL ;
281
- thread_env [i ]-> tst_cleanup_func = NULL ;
282
- }
272
+ for (i = 0 ; i < num_threads ; i ++ ) {
273
+ memset (& (thread_env [i ]-> env ), 0 , sizeof (struct tst_env ));
274
+ thread_env [i ]-> tst_init_func = NULL ;
275
+ thread_env [i ]-> tst_run_func = NULL ;
276
+ thread_env [i ]-> tst_cleanup_func = NULL ;
277
+ }
283
278
pthread_mutex_lock (& working_mutex );
284
279
working = 0 ;
285
280
pthread_mutex_unlock (& working_mutex );
286
-
287
281
return 0 ;
288
282
}
289
283
290
- /*
291
- * Assign all running threads the same test-environment
284
+ /** \brief Assign all running threads the same test-environment
285
+ *
286
+ * \param[in] env original environment to be assigned to all threads
287
+ * \param[out] thread_env list of thread environments
288
+ *
289
+ * \return always 0
292
290
*/
293
- int tst_thread_assign_all (struct tst_env * env , struct tst_thread_env_t * * thread_env )
294
- {
291
+ int tst_thread_assign_all (struct tst_env * env , struct tst_thread_env_t * * thread_env ) {
295
292
int i ;
296
- for (i = 0 ; i < num_threads ; i ++ )
297
- {
298
- memcpy (& (thread_env [i ]-> env ), env , sizeof (struct tst_env ));
299
- thread_env [i ]-> tst_init_func = tst_test_get_init_func (env );
300
- thread_env [i ]-> tst_run_func = tst_test_get_run_func (env );
301
- thread_env [i ]-> tst_cleanup_func = tst_test_get_cleanup_func (env );
302
- }
293
+ for (i = 0 ; i < num_threads ; i ++ ) {
294
+ memcpy (& (thread_env [i ]-> env ), env , sizeof (struct tst_env ));
295
+ thread_env [i ]-> tst_init_func = tst_test_get_init_func (env );
296
+ thread_env [i ]-> tst_run_func = tst_test_get_run_func (env );
297
+ thread_env [i ]-> tst_cleanup_func = tst_test_get_cleanup_func (env );
298
+ }
303
299
pthread_mutex_lock (& working_mutex );
304
300
working = num_threads ;
305
301
pthread_mutex_unlock (& working_mutex );
306
302
return 0 ;
307
303
}
308
304
309
- /*
310
- * Assign one particular running threads a test-environment
305
+ /** \brief Assign a test-environment to one particular thread
306
+ *
307
+ * \param[in] env original environment to be assigned to the thread
308
+ * \param[in] thread_number id of the thread to assign the env to
309
+ * \param[out] thread_env list of thread environments
310
+ *
311
+ * \return always 0
311
312
*/
312
- int tst_thread_assign_one (struct tst_env * env , int thread_number , struct tst_thread_env_t * * thread_env )
313
+ int tst_thread_assign_one (struct tst_env * env , int thread_number , struct tst_thread_env_t * * thread_env )
313
314
{
314
315
if (thread_number < 0 || thread_number >= num_threads )
315
316
ERROR (EINVAL , "tst_thread_assign_one: Assignment not possible -- not enough threads" );
@@ -378,14 +379,12 @@ int tst_thread_execute_cleanup (struct tst_env * env)
378
379
}
379
380
380
381
381
- inline int tst_thread_num_threads (void )
382
- {
382
+ inline int tst_thread_num_threads () {
383
383
return num_threads + 1 ; /* +1 because the main thread also is doing some work */
384
384
}
385
385
386
386
387
- inline int tst_thread_running (void )
388
- {
387
+ inline int tst_thread_running () {
389
388
return (num_threads > 0 );
390
389
}
391
390
0 commit comments