summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2013-02-01 17:39:20 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2013-02-01 17:39:20 +0100
commit5ac5b735b8cbc2bab60298ae93b381e88b00007f (patch)
tree3f4b7ff72d572259c9630aa7007eb214bf30345a
parent0a6e6c9e4155fae6b39871caf9b69e5b4a74bdd1 (diff)
downloadlock_free-master.zip
lock_free-master.tar.gz
wip-worktree-stateHEADmaster
-rw-r--r--.lvimrc2
-rw-r--r--Makefile4
-rw-r--r--lf_fifo_test.c70
3 files changed, 72 insertions, 4 deletions
diff --git a/.lvimrc b/.lvimrc
new file mode 100644
index 0000000..caca9da
--- /dev/null
+++ b/.lvimrc
@@ -0,0 +1,2 @@
+"
+set ts=8 sw=3 sts=3 expandtab cino=>5n-3f0^-2{2(0W1st0
diff --git a/Makefile b/Makefile
index e3ecd9a..52a9a1d 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
CC = gcc
STD = _GNU_SOURCE
-CFLAGS = -DDEBUG
+CFLAGS = -DDEBUG -g
BIN = cas container_of lock_free_queue_test lf_fifo_test lf_ringbuffer_test
.c.o:
@@ -28,7 +28,7 @@ lock_free_queue_test: lock_free_queue.o lock_free_queue_test.o
lf_fifo.o: lf_fifo.h lf_fifo.c lf_cas.h
lf_fifo_test.o: lf_fifo_test.c
lf_fifo_test: lf_fifo.o lf_fifo_test.o
- $(CC) -lpthread lf_fifo.o lf_fifo_test.o -o lf_fifo_test
+ $(CC) -g -lpthread lf_fifo.o lf_fifo_test.o -o lf_fifo_test
lf_ringbuffer.o: lf_ringbuffer.h lf_ringbuffer.c lf_ringbuffer_data.h lf_portable_cas.h
lf_ringbuffer_test.o: lf_ringbuffer_test.c lf_ringbuffer.h
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");