7 /****************************************************************************/
8 void test_lfds600_stack( void )
14 struct lfds600_stack_state
20 /* TRD : there are 5 tests
22 1. single reader thread per CPU
24 2. single writer thread per CPU
26 3. one reader and one writer thread per CPU
28 4. one reader and two writer threads per CPU
30 5. two reader and one writer thread per CPU
31 - stack tends to empty
34 cpu_count = abstraction_cpu_count();
40 // TRD : 1. single reader thread per CPU
43 "1. single reader thread per CPU\n"
44 "===============================\n" );
46 lfds600_stack_new( &ss, 10000 );
48 thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 1 );
50 for( loop = 0 ; loop < cpu_count ; loop++ )
51 abstraction_thread_start( &thread_handles[loop], loop, lfds600_stack_internal_thread_reader, ss );
53 for( loop = 0 ; loop < cpu_count ; loop++ )
54 abstraction_thread_wait( thread_handles[loop] );
56 lfds600_stack_delete( ss, NULL, NULL );
58 free( thread_handles );
60 // TRD : 2. single writer thread per CPU
63 "2. single writer thread per CPU\n"
64 "===============================\n" );
66 lfds600_stack_new( &ss, 10000 );
68 thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 1 );
70 for( loop = 0 ; loop < cpu_count ; loop++ )
71 abstraction_thread_start( &thread_handles[loop], loop, lfds600_stack_internal_thread_writer, ss );
73 for( loop = 0 ; loop < cpu_count ; loop++ )
74 abstraction_thread_wait( thread_handles[loop] );
76 lfds600_stack_delete( ss, NULL, NULL );
78 free( thread_handles );
80 // TRD : 3. one reader and one writer thread per CPU
83 "3. one reader and one writer thread per CPU\n"
84 "===========================================\n" );
86 lfds600_stack_new( &ss, 10000 );
88 thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 2 );
90 for( loop = 0 ; loop < cpu_count ; loop++ )
92 abstraction_thread_start( &thread_handles[loop], loop, lfds600_stack_internal_thread_reader, ss );
93 abstraction_thread_start( &thread_handles[loop+cpu_count], loop, lfds600_stack_internal_thread_writer, ss );
96 for( loop = 0 ; loop < cpu_count * 2 ; loop++ )
97 abstraction_thread_wait( thread_handles[loop] );
99 lfds600_stack_delete( ss, NULL, NULL );
101 free( thread_handles );
103 // TRD : 4. one reader and two writer threads per CPU
106 "4. one reader and two writer threads per CPU\n"
107 "============================================\n" );
109 lfds600_stack_new( &ss, 10000 );
111 thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 3 );
113 for( loop = 0 ; loop < cpu_count ; loop++ )
115 abstraction_thread_start( &thread_handles[loop], loop, lfds600_stack_internal_thread_reader, ss );
116 abstraction_thread_start( &thread_handles[loop+cpu_count], loop, lfds600_stack_internal_thread_writer, ss );
117 abstraction_thread_start( &thread_handles[loop+cpu_count*2], loop, lfds600_stack_internal_thread_writer, ss );
120 for( loop = 0 ; loop < cpu_count * 3 ; loop++ )
121 abstraction_thread_wait( thread_handles[loop] );
123 lfds600_stack_delete( ss, NULL, NULL );
125 free( thread_handles );
127 // TRD : 5. two reader and one writer thread per CPU
130 "5. two reader and one writer thread per CPU\n"
131 "===========================================\n" );
133 lfds600_stack_new( &ss, 10000 );
135 thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count * 3 );
137 for( loop = 0 ; loop < cpu_count ; loop++ )
139 abstraction_thread_start( &thread_handles[loop], loop, lfds600_stack_internal_thread_reader, ss );
140 abstraction_thread_start( &thread_handles[loop+cpu_count], loop, lfds600_stack_internal_thread_reader, ss );
141 abstraction_thread_start( &thread_handles[loop+cpu_count*2], loop, lfds600_stack_internal_thread_writer, ss );
144 for( loop = 0 ; loop < cpu_count * 3 ; loop++ )
145 abstraction_thread_wait( thread_handles[loop] );
147 lfds600_stack_delete( ss, NULL, NULL );
149 free( thread_handles );
158 /****************************************************************************/
159 thread_return_t CALLING_CONVENTION lfds600_stack_internal_thread_reader( void *lfds600_stack_state )
161 struct lfds600_stack_state
170 unsigned long long int
173 assert( lfds600_stack_state != NULL );
175 ss = (struct lfds600_stack_state *) lfds600_stack_state;
179 while( time(NULL) < start_time + 10 )
181 if( lfds600_stack_pop(ss, &user_data) )
185 printf( "read count = %llu\n", count );
187 return( (thread_return_t) EXIT_SUCCESS );
194 /****************************************************************************/
195 thread_return_t CALLING_CONVENTION lfds600_stack_internal_thread_writer( void *lfds600_stack_state )
197 struct lfds600_stack_state
203 unsigned long long int
206 assert( lfds600_stack_state != NULL );
208 ss = (struct lfds600_stack_state *) lfds600_stack_state;
212 while( time(NULL) < start_time + 10 )
214 // TRD : we don't store any user data
215 if( lfds600_stack_push(ss, NULL) )
219 printf( "write count = %llu\n", count );
221 return( (thread_return_t) EXIT_SUCCESS );