1
1
#include "config.h"
2
- #ifdef HAVE_PTHREAD_H
3
- # include <pthread .h>
4
- #endif
2
+
3
+ #include <assert .h>
4
+ #include <pthread.h>
5
5
6
6
#include "mpi_test_suite.h"
7
7
8
8
9
- static int num_threads ; /* Number of available threads - 1 */
9
+ static int num_threads ; /**< Number of available threads - 1 */
10
10
static int working ;
11
11
static pthread_mutex_t working_mutex = PTHREAD_MUTEX_INITIALIZER ;
12
12
static pthread_cond_t working_cond = PTHREAD_COND_INITIALIZER ;
@@ -171,18 +171,14 @@ static void * tst_thread_dispatcher (void * arg)
171
171
}
172
172
173
173
174
- /*
175
- * Initialize the thread-framework
176
- */
177
- int tst_thread_init (int max_threads , struct tst_thread_env_t * * * thread_env )
178
- {
174
+ /** \brief Initialize the thread-framework */
175
+ int tst_thread_init (int max_threads , struct tst_thread_env_t * * * thread_env ) {
179
176
int i ;
180
177
struct tst_thread_env_t * * env ;
181
178
182
- if (max_threads <= 0 || thread_env == NULL )
183
- ERROR ( EINVAL , "Called with faulty arguments" );
179
+ assert (max_threads > 0 );
180
+ assert ( thread_env != NULL );
184
181
185
- num_threads = max_threads - 1 ;
186
182
/*
187
183
* Without the pthread_mutex_lock, as no threads are started, yet
188
184
*/
@@ -201,20 +197,21 @@ int tst_thread_init (int max_threads, struct tst_thread_env_t *** thread_env)
201
197
*/
202
198
tst_thread_tid_array [0 ] = pthread_self ();
203
199
204
- for (i = 0 ; i < num_threads ; i ++ )
205
- {
206
- int ret ;
207
- env [i ] = malloc ( sizeof (struct tst_thread_env_t ));
208
- memset ( env [i ], 0 , sizeof ( struct tst_thread_env_t )) ;
209
- env [i ]-> thread_num = i ;
210
- env [i ]-> state = TST_THREAD_STATE_IDLE ;
211
- ret = pthread_create ( & ( env [ i ] -> tid ), NULL , tst_thread_dispatcher , env [ i ]);
212
- if ( ret != 0 )
213
- ERROR ( errno , "tst_thread_init: pthread_create" ) ;
214
- tst_thread_tid_array [ i + 1 ] = env [ i ] -> tid ;
215
- }
216
-
200
+ for (i = 0 ; i < max_threads - 1 ; i ++ ) {
201
+ int ret ;
202
+ env [ i ] = malloc ( sizeof ( struct tst_thread_env_t )) ;
203
+ memset ( env [i ], 0 , sizeof (struct tst_thread_env_t ));
204
+ env [i ]-> thread_num = i ;
205
+ env [i ]-> state = TST_THREAD_STATE_IDLE ;
206
+ ret = pthread_create ( & ( env [i ]-> tid ), NULL , tst_thread_dispatcher , env [ i ]) ;
207
+ if ( ret != 0 )
208
+ ERROR ( errno , "tst_thread_init: pthread_create" );
209
+ tst_thread_tid_array [ i + 1 ] = env [ i ] -> tid ;
210
+
211
+ num_threads ++ ;
212
+ }
217
213
214
+ assert (num_threads == max_threads - 1 );
218
215
* thread_env = env ;
219
216
return 0 ;
220
217
}
0 commit comments