4 * Userspace RCU library - test wfcqueue race conditions
6 * Copyright 2023 - Olivier Dion <odion@efficios.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <urcu/wfcqueue.h>
34 #define NR_PRODUCERS 4
38 struct cds_wfcq_head head
;
39 struct cds_wfcq_tail tail
;
42 static void async_run(struct queue
*queue
)
44 struct cds_wfcq_node
*node
= malloc(sizeof(*node
));
46 cds_wfcq_node_init(node
);
48 cds_wfcq_enqueue(&queue
->head
, &queue
->tail
, node
);
50 static void do_async_loop(size_t *k
, struct queue
*queue
)
52 struct queue my_queue
;
53 enum cds_wfcq_ret state
;
54 struct cds_wfcq_node
*node
, *next
;
56 cds_wfcq_init(&my_queue
.head
, &my_queue
.tail
);
58 state
= cds_wfcq_splice_blocking(&my_queue
.head
,
63 if (state
== CDS_WFCQ_RET_SRC_EMPTY
) {
67 __cds_wfcq_for_each_blocking_safe(&my_queue
.head
,
75 static void *async_loop(void *queue
)
79 while (k
< LOOP
* NR_PRODUCERS
) {
80 (void) poll(NULL
, 0, 10);
81 do_async_loop(&k
, queue
);
87 static void *spawn_jobs(void *queue
)
89 for (size_t k
= 0; k
< LOOP
; ++k
) {
99 pthread_t producers
[NR_PRODUCERS
];
102 plan_tests(NR_TESTS
);
104 cds_wfcq_init(&queue
.head
, &queue
.tail
);
105 pthread_create(&consumer
, NULL
, async_loop
, &queue
);
107 for (size_t k
= 0; k
< NR_PRODUCERS
; ++k
) {
108 pthread_create(&producers
[k
], NULL
, spawn_jobs
, &queue
);
111 pthread_join(consumer
, NULL
);
112 for (size_t k
= 0; k
< NR_PRODUCERS
; ++k
) {
113 pthread_join(producers
[k
], NULL
);
116 ok1("No race conditions");
118 return exit_status();
This page took 0.031803 seconds and 4 git commands to generate.