45c498865f35d63c2a40afea9d59338d1fb20ddf
1 // SPDX-FileCopyrightText: 2023 Olivier Dion <odion@efficios.com>
3 // SPDX-License-Identifier: GPL-2.0-or-later
8 * Userspace RCU library - test wfcqueue race conditions
17 #include <urcu/wfcqueue.h>
22 #define NR_PRODUCERS 4
26 struct cds_wfcq_head head
;
27 struct cds_wfcq_tail tail
;
30 static void async_run(struct queue
*queue
)
32 struct cds_wfcq_node
*node
= malloc(sizeof(*node
));
34 cds_wfcq_node_init(node
);
36 cds_wfcq_enqueue(&queue
->head
, &queue
->tail
, node
);
38 static void do_async_loop(size_t *k
, struct queue
*queue
)
40 struct queue my_queue
;
41 enum cds_wfcq_ret state
;
42 struct cds_wfcq_node
*node
, *next
;
44 cds_wfcq_init(&my_queue
.head
, &my_queue
.tail
);
46 state
= cds_wfcq_splice_blocking(&my_queue
.head
,
51 if (state
== CDS_WFCQ_RET_SRC_EMPTY
) {
55 __cds_wfcq_for_each_blocking_safe(&my_queue
.head
,
63 static void *async_loop(void *queue
)
67 while (k
< LOOP
* NR_PRODUCERS
) {
68 (void) poll(NULL
, 0, 10);
69 do_async_loop(&k
, queue
);
75 static void *spawn_jobs(void *queue
)
77 for (size_t k
= 0; k
< LOOP
; ++k
) {
87 pthread_t producers
[NR_PRODUCERS
];
92 cds_wfcq_init(&queue
.head
, &queue
.tail
);
93 pthread_create(&consumer
, NULL
, async_loop
, &queue
);
95 for (size_t k
= 0; k
< NR_PRODUCERS
; ++k
) {
96 pthread_create(&producers
[k
], NULL
, spawn_jobs
, &queue
);
99 pthread_join(consumer
, NULL
);
100 for (size_t k
= 0; k
< NR_PRODUCERS
; ++k
) {
101 pthread_join(producers
[k
], NULL
);
104 ok1("No race conditions");
106 return exit_status();
This page took 0.034626 seconds and 3 git commands to generate.