7 struct lfds700_queue_state
11 /***** private prototypes *****/
12 static test_pal_thread_return_t TEST_PAL_CALLING_CONVENTION thread_enqueuer_with_malloc_and_dequeuer_with_free( void *util_thread_starter_thread_state );
13 static void queue_element_cleanup_callback( struct lfds700_queue_state *qs, struct lfds700_queue_element *qe, enum lfds700_misc_flag dummy_element_flag );
19 /****************************************************************************/
20 void test_lfds700_queue_enqueuing_with_malloc_and_dequeuing_with_free( struct lfds700_list_asu_state *list_of_logical_processors )
22 enum lfds700_misc_validity
23 dvs = LFDS700_MISC_VALIDITY_VALID;
27 number_logical_processors;
29 struct lfds700_list_asu_element
32 struct lfds700_misc_prng_state
35 struct lfds700_queue_element
38 struct lfds700_queue_state
41 struct lfds700_misc_validation_info
44 struct test_pal_logical_processor
47 struct util_thread_starter_state
53 test_pal_thread_state_t
56 assert( list_of_logical_processors != NULL );
57 // TRD : qt can be any value in its range
59 /* TRD : one thread per logical core
60 each thread loops for ten seconds
61 mallocs and enqueues 1k elements, then dequeues and frees 1k elements
64 internal_display_test_name( "Enqueuing with malloc dequeuing with free (%d seconds)", TEST_DURATION_IN_SECONDS );
66 lfds700_list_asu_query( list_of_logical_processors, LFDS700_LIST_ASU_QUERY_GET_POTENTIALLY_INACCURATE_COUNT, NULL, (void **) &number_logical_processors );
68 lfds700_misc_prng_init( &ps );
70 qe = util_aligned_malloc( sizeof(struct lfds700_queue_element), LFDS700_PAL_ATOMIC_ISOLATION_IN_BYTES );
72 lfds700_queue_init_valid_on_current_logical_core( &qs, qe, &ps, NULL );
74 ts = util_malloc_wrapper( sizeof(struct test_state) * number_logical_processors );
76 for( loop = 0 ; loop < number_logical_processors ; loop++ )
79 thread_handles = util_malloc_wrapper( sizeof(test_pal_thread_state_t) * number_logical_processors );
81 util_thread_starter_new( &tts, number_logical_processors );
83 LFDS700_MISC_BARRIER_STORE;
85 lfds700_misc_force_store();
90 while( LFDS700_LIST_ASU_GET_START_AND_THEN_NEXT(*list_of_logical_processors, lasue) )
92 lp = LFDS700_LIST_ASU_GET_VALUE_FROM_ELEMENT( *lasue );
93 util_thread_starter_start( tts, &thread_handles[loop], loop, lp, thread_enqueuer_with_malloc_and_dequeuer_with_free, ts+loop );
97 util_thread_starter_run( tts );
99 for( loop = 0 ; loop < number_logical_processors ; loop++ )
100 test_pal_thread_wait( thread_handles[loop] );
102 util_thread_starter_delete( tts );
104 free( thread_handles );
106 LFDS700_MISC_BARRIER_LOAD;
108 vi.min_elements = vi.max_elements = 0;
110 lfds700_queue_query( &qs, LFDS700_QUEUE_QUERY_SINGLETHREADED_VALIDATE, &vi, &dvs );
114 lfds700_queue_cleanup( &qs, queue_element_cleanup_callback );
116 internal_display_test_result( 1, "queue", dvs );
125 /****************************************************************************/
126 static test_pal_thread_return_t TEST_PAL_CALLING_CONVENTION thread_enqueuer_with_malloc_and_dequeuer_with_free( void *util_thread_starter_thread_state )
132 struct lfds700_misc_prng_state
135 struct lfds700_queue_element
141 struct util_thread_starter_thread_state
148 LFDS700_MISC_MAKE_VALID_ON_CURRENT_LOGICAL_CORE_INITS_COMPLETED_BEFORE_NOW_ON_ANY_OTHER_LOGICAL_CORE;
150 assert( util_thread_starter_thread_state != NULL );
152 tsts = (struct util_thread_starter_thread_state *) util_thread_starter_thread_state;
153 ts = (struct test_state *) tsts->thread_user_state;
155 lfds700_misc_prng_init( &ps );
157 util_thread_starter_ready_and_wait( tsts );
159 current_time = start_time = time( NULL );
161 while( current_time < start_time + TEST_DURATION_IN_SECONDS )
163 for( loop = 0 ; loop < 1000 ; loop++ )
165 qe = util_aligned_malloc( sizeof(struct lfds700_queue_element), LFDS700_PAL_ATOMIC_ISOLATION_IN_BYTES );
166 lfds700_queue_enqueue( ts->qs, qe, &ps );
169 for( loop = 0 ; loop < 1000 ; loop++ )
171 lfds700_queue_dequeue( ts->qs, &qe, &ps );
172 util_aligned_free( qe );
175 if( time_loop++ == REDUCED_TIME_LOOP_COUNT )
178 time( ¤t_time );
182 LFDS700_MISC_BARRIER_STORE;
184 lfds700_misc_force_store();
186 return( (test_pal_thread_return_t) EXIT_SUCCESS );
193 /****************************************************************************/
194 #pragma warning( disable : 4100 )
196 static void queue_element_cleanup_callback( struct lfds700_queue_state *qs, struct lfds700_queue_element *qe, enum lfds700_misc_flag dummy_element_flag )
198 assert( qs != NULL );
199 assert( qe != NULL );
200 // TRD : dummy_element_flag can be any value in its range
202 util_aligned_free( qe );
207 #pragma warning( default : 4100 )