8 /****************************************************************************/
9 void util_thread_starter_new( struct util_thread_starter_state **tts, lfds700_pal_uint_t number_threads )
14 assert( tts != NULL );
15 // TRD : number_threads cam be any value in its range
17 *tts = util_malloc_wrapper( sizeof(struct util_thread_starter_state) );
19 (*tts)->tsts = util_malloc_wrapper( sizeof(struct util_thread_starter_thread_state) * number_threads );
20 (*tts)->thread_start_flag = LOWERED;
21 (*tts)->number_thread_states = number_threads;
23 for( loop = 0 ; loop < number_threads ; loop++ )
25 ((*tts)->tsts+loop)->thread_ready_flag = LOWERED;
26 ((*tts)->tsts+loop)->thread_start_flag = &(*tts)->thread_start_flag;
29 LFDS700_MISC_BARRIER_STORE;
31 lfds700_misc_force_store();
40 /****************************************************************************/
41 void util_thread_starter_start( struct util_thread_starter_state *tts,
42 test_pal_thread_state_t *thread_state,
43 lfds700_pal_uint_t thread_number,
44 struct test_pal_logical_processor *lp,
45 test_pal_thread_return_t (TEST_PAL_CALLING_CONVENTION *thread_function)( void *thread_user_state ),
46 void *thread_user_state )
48 assert( tts != NULL );
49 assert( thread_state != NULL );
51 assert( thread_function != NULL );
52 // TRD : thread_user_state can be NULL
54 (tts->tsts+thread_number)->thread_user_state = thread_user_state;
56 util_thread_start_wrapper( thread_state, lp, thread_function, tts->tsts+thread_number );
58 // TRD : wait for the thread to indicate it is ready and waiting
59 while( (tts->tsts+thread_number)->thread_ready_flag == LOWERED );
68 /****************************************************************************/
69 void util_thread_starter_ready_and_wait( struct util_thread_starter_thread_state *tsts )
71 assert( tsts != NULL );
73 tsts->thread_ready_flag = RAISED;
75 LFDS700_MISC_BARRIER_FULL;
77 // TRD : threads here are all looping, so we don't need to force a store
79 while( *tsts->thread_start_flag == LOWERED )
80 LFDS700_MISC_BARRIER_LOAD;
89 /****************************************************************************/
90 void util_thread_starter_run( struct util_thread_starter_state *tts )
92 assert( tts != NULL );
94 /* TRD : all threads at this point are ready to go
95 as we wait for their ready flag immediately after their spawn
98 tts->thread_start_flag = RAISED;
100 LFDS700_MISC_BARRIER_STORE;
102 lfds700_misc_force_store();
111 /****************************************************************************/
112 void util_thread_starter_delete( struct util_thread_starter_state *tts )
114 assert( tts != NULL );
127 /****************************************************************************/
128 void util_thread_start_wrapper( test_pal_thread_state_t *thread_state,
129 struct test_pal_logical_processor *lp,
130 test_pal_thread_return_t (TEST_PAL_CALLING_CONVENTION *thread_function)(void *thread_user_state),
131 void *thread_user_state )
136 assert( thread_state != NULL );
137 assert( lp != NULL );
138 assert( thread_function != NULL );
139 // TRD : thread_user_state can be NULL
141 rv = test_pal_thread_start( thread_state, lp, thread_function, thread_user_state );
145 puts( "test_pal_thread_start() failed." );
146 exit( EXIT_FAILURE );