From 1ac0b596891b03e2b3651ed78252294ca02e928a Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Wed, 10 Oct 2012 14:25:33 -0700 Subject: [PATCH] mpmc-queue: add test driver, Makefile, .gitignore --- mpmc-queue/.gitignore | 1 + mpmc-queue/Makefile | 11 +++++++++++ mpmc-queue/mpmc-queue.cc | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 mpmc-queue/.gitignore create mode 100644 mpmc-queue/Makefile create mode 100644 mpmc-queue/mpmc-queue.cc diff --git a/mpmc-queue/.gitignore b/mpmc-queue/.gitignore new file mode 100644 index 0000000..4b0d836 --- /dev/null +++ b/mpmc-queue/.gitignore @@ -0,0 +1 @@ +/mpmc-queue diff --git a/mpmc-queue/Makefile b/mpmc-queue/Makefile new file mode 100644 index 0000000..07e2540 --- /dev/null +++ b/mpmc-queue/Makefile @@ -0,0 +1,11 @@ +include ../benchmarks.mk + +TESTNAME = mpmc-queue + +all: $(TESTNAME) + +$(TESTNAME): $(TESTNAME).cc $(TESTNAME).h + $(CXX) -o $@ $< $(CPPFLAGS) $(LDFLAGS) + +clean: + rm -f $(TESTNAME) *.o diff --git a/mpmc-queue/mpmc-queue.cc b/mpmc-queue/mpmc-queue.cc new file mode 100644 index 0000000..b6af7ef --- /dev/null +++ b/mpmc-queue/mpmc-queue.cc @@ -0,0 +1,33 @@ +#include +#include + +#include + +#include "mpmc-queue.h" + +void threadA(struct mpmc_boundq_1_alt *queue) +{ + int *bin = queue->write_prepare(); + *bin = 1; + queue->write_publish(); +} + +void threadB(struct mpmc_boundq_1_alt *queue) +{ + int *bin = queue->read_fetch(); + printf("Read: %d\n", *bin); + queue->read_consume(); +} + +int user_main(int argc, char **argv) +{ + struct mpmc_boundq_1_alt queue; + thrd_t A, B; + + thrd_create(&A, (thrd_start_t)&threadA, &queue); + thrd_create(&B, (thrd_start_t)&threadB, &queue); + thrd_join(A); + thrd_join(B); + + return 0; +} -- 2.34.1