summaryrefslogtreecommitdiffstats
path: root/lf_fifo_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'lf_fifo_test.c')
-rw-r--r--lf_fifo_test.c70
1 files changed, 68 insertions, 2 deletions
diff --git a/lf_fifo_test.c b/lf_fifo_test.c
index 7d6a165..13ec1f5 100644
--- a/lf_fifo_test.c
+++ b/lf_fifo_test.c
@@ -198,10 +198,76 @@ static void run_aggressive_push_pop(int threads_n, int nodes_n)
free(params);
}
+static void run_interlaced_push_pop(int push_threads_n, int pop_threads_n, int nodes_n)
+{
+ int threads_n;
+ uint32_t i,j;
+ lf_fifo_t fifo;
+ struct timespec start, end;
+ pthread_t *threads;
+ thread_params_t *params;
+
+ threads_n = push_threads_n + pop_threads_n;
+ threads = malloc( sizeof(pthread_t)*threads_n);
+ if (threads==NULL) _failure("threads malloc failure");
+ params = malloc( sizeof(thread_params_t)*threads_n);
+ if (params==NULL) _failure("params malloc failure");
+
+ lf_fifo_init( &fifo);
+
+ for(i=0; i<threads_n; i++)
+ {
+ params[i].fifo = &fifo;
+ params[i].n = nodes_n;
+ }
+
+ clock_gettime(CLOCK_MONOTONIC, &start);
+ for(i=0; i<push_threads_n; i++)
+ {
+ if (pthread_create( &threads[i], NULL, aggressive_push, &params[i]))
+ _failure("Failed to create push thread");
+ }
+ for(; i<threads_n-1; i++)
+ {
+ if (pthread_create( &threads[i], NULL, aggressive_pop, &params[i]))
+ _failure("Failed to create pop thread");
+ }
+ for(i=0; i<threads_n-1; i++)
+ {
+ pthread_join( threads[i], NULL );
+ }
+ if (pthread_create( &threads[threads_n-1], NULL, aggressive_pop, &params[threads_n-1]))
+ _failure("Failed to create pop thread");
+ pthread_join( threads[threads_n-1], NULL );
+ clock_gettime(CLOCK_MONOTONIC, &end);
+
+ for(i=0; i<push_threads_n; i++)
+ {
+ _check((params[i].n==nodes_n),"push n failure after aggressive push");
+ if (params[i].nodes) free(params[i].nodes);
+ }
+ j = 0;
+ for(; i<threads_n; i++)
+ {
+ j += params[i].n;
+ if (params[i].nodes) free(params[i].nodes);
+ }
+ /* _check((j==(push_threads_n*nodes_n)),"poped nodes count failure"); */
+ fprintf(stderr,"%d/%d\n",j,(push_threads_n*nodes_n));
+
+ /* report( "interlaced push-pop", (push_threads_n+pop_threads), nodes_n, time_diff( &start, &end )); */
+ /* _check((fifo_length(&fifo)==(threads_n*nodes_n)),"fifo length failure after aggressive push"); */
+
+ free(threads);
+ free(params);
+}
+
int main(int argc, char *argv[])
{
- run_aggressive_push_pop(100,100000);
- /* run_aggressive_push_pop(1,10); */
+ printf("running...\n");
+
+ /* run_aggressive_push_pop(100,1000000); */
+ run_interlaced_push_pop(10,10,10000000);
printf("success\n");