Skip to content

Commit cc91782

Browse files
committed
Comment cleanup, indentation fixes and documentation updates
1 parent 10bc337 commit cc91782

File tree

1 file changed

+53
-54
lines changed

1 file changed

+53
-54
lines changed

tst_threads.c

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ typedef enum {
5050
TST_THREAD_SIGNAL_STATE_WAIT = 0,
5151
TST_THREAD_SIGNAL_STATE_GOON
5252
} tst_thread_signal_state;
53-
/*
54-
* Local declarations
55-
*/
53+
54+
5655
/* saving thread_ids for global access, also available in main via struct thread_env */
5756
static pthread_t * tst_thread_tid_array;
5857

@@ -67,28 +66,25 @@ int tst_thread_signals_count = 0; /* number of waiting threads */
6766
static MPI_Request * tst_thread_requests_array;
6867
int tst_thread_requests_max = 0;
6968

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() {
7572
pthread_mutex_lock (&working_mutex);
7673
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);
8078
}
8179

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);
9288
}
9389

9490

@@ -179,9 +175,7 @@ int tst_thread_init(int max_threads, struct tst_thread_env_t ***thread_env) {
179175
assert(max_threads > 0);
180176
assert(thread_env != NULL);
181177

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 */
185179
working = 0;
186180

187181
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) {
207201
if (ret != 0)
208202
ERROR (errno, "tst_thread_init: pthread_create");
209203
tst_thread_tid_array[i + 1] = env[i]->tid;
210-
211204
num_threads++;
212205
}
213206

@@ -267,49 +260,57 @@ inline int tst_thread_get_num (void)
267260
return -1;
268261
}
269262

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
272268
*/
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)
274270
{
275271
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+
}
283278
pthread_mutex_lock (&working_mutex);
284279
working = 0;
285280
pthread_mutex_unlock (&working_mutex);
286-
287281
return 0;
288282
}
289283

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
292290
*/
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) {
295292
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+
}
303299
pthread_mutex_lock (&working_mutex);
304300
working = num_threads;
305301
pthread_mutex_unlock (&working_mutex);
306302
return 0;
307303
}
308304

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
311312
*/
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)
313314
{
314315
if (thread_number < 0 || thread_number >= num_threads)
315316
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)
378379
}
379380

380381

381-
inline int tst_thread_num_threads (void)
382-
{
382+
inline int tst_thread_num_threads () {
383383
return num_threads + 1; /* +1 because the main thread also is doing some work */
384384
}
385385

386386

387-
inline int tst_thread_running (void)
388-
{
387+
inline int tst_thread_running () {
389388
return (num_threads > 0);
390389
}
391390

0 commit comments

Comments
 (0)