9 #include "mpmc-queue-wildcard.h"
11 void threadA(struct mpmc_boundq_1_alt<int32_t, sizeof(int32_t)> *queue)
13 int32_t *bin = queue->write_prepare();
15 queue->write_publish();
18 void threadB(struct mpmc_boundq_1_alt<int32_t, sizeof(int32_t)> *queue)
21 while ((bin = queue->read_fetch()) != NULL) {
22 printf("Read: %d\n", load_32(bin));
23 queue->read_consume();
27 void threadC(struct mpmc_boundq_1_alt<int32_t, sizeof(int32_t)> *queue)
29 int32_t *bin = queue->write_prepare();
31 queue->write_publish();
33 while ((bin = queue->read_fetch()) != NULL) {
34 printf("Read: %d\n", load_32(bin));
35 queue->read_consume();
43 #ifdef CONFIG_MPMC_READERS
44 #define DEFAULT_READERS (CONFIG_MPMC_READERS)
46 #define DEFAULT_READERS 2
49 #ifdef CONFIG_MPMC_WRITERS
50 #define DEFAULT_WRITERS (CONFIG_MPMC_WRITERS)
52 #define DEFAULT_WRITERS 2
55 #ifdef CONFIG_MPMC_RDWR
56 #define DEFAULT_RDWR (CONFIG_MPMC_RDWR)
58 #define DEFAULT_RDWR 0
61 int readers = DEFAULT_READERS, writers = DEFAULT_WRITERS, rdwr = DEFAULT_RDWR;
65 printf("Error: use the following options\n"
66 " -r <num> Choose number of reader threads\n"
67 " -w <num> Choose number of writer threads\n");
71 void process_params(int argc, char **argv)
73 const char *shortopts = "hr:w:";
77 while (!error && (opt = getopt(argc, argv, shortopts)) != -1) {
83 readers = atoi(optarg);
86 writers = atoi(optarg);
94 if (writers < 1 || writers > MAXWRITERS)
96 if (readers < 1 || readers > MAXREADERS)
103 int user_main(int argc, char **argv)
105 struct mpmc_boundq_1_alt<int32_t, sizeof(int32_t)> queue;
106 thrd_t A[MAXWRITERS], B[MAXREADERS], C[MAXRDWR];
108 /* Note: optarg() / optind is broken in model-checker - workaround is
109 * to just copy&paste this test a few times */
110 //process_params(argc, argv);
111 printf("%d reader(s), %d writer(s)\n", readers, writers);
113 #ifndef CONFIG_MPMC_NO_INITIAL_ELEMENT
114 printf("Adding initial element\n");
115 int32_t *bin = queue.write_prepare();
117 queue.write_publish();
120 printf("Start threads\n");
122 for (int i = 0; i < writers; i++)
123 thrd_create(&A[i], (thrd_start_t)&threadA, &queue);
124 for (int i = 0; i < readers; i++)
125 thrd_create(&B[i], (thrd_start_t)&threadB, &queue);
127 for (int i = 0; i < rdwr; i++)
128 thrd_create(&C[i], (thrd_start_t)&threadC, &queue);
130 for (int i = 0; i < writers; i++)
132 for (int i = 0; i < readers; i++)
134 for (int i = 0; i < rdwr; i++)
137 printf("Threads complete\n");