spmc_queue: Fix order of block::{next, consumer, producer} reads
[libnbds.git] / test / spsc_queue_s.c
blobd830bc7c012fa0564ced1a976f8d9e40c63bdee7
1 /*
2 libnbds
3 Copyright (C) 2013 Paweł Dziepak
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <stdint.h>
21 #include "spsc_queue.h"
23 struct spsc_queue queue;
25 int main(int argc, char** argv)
27 uintptr_t i;
28 int error;
30 (void)argc;
31 (void)argv;
33 error = spsc_queue_init(&queue);
34 if (error)
35 return 1;
37 if (spsc_queue_dequeue(&queue))
38 return 1;
40 for (i = 1; i < 1024u; i++) {
41 error = spsc_queue_enqueue(&queue, (void*)i);
42 if (error)
43 return 1;
46 for (i = 1; i < 1024u; i++) {
47 if ((uintptr_t)spsc_queue_dequeue(&queue) != i)
48 return 1;
51 if (spsc_queue_dequeue(&queue))
52 return 1;
54 for (i = 1; i < 1024u; i++) {
55 spsc_queue_enqueue(&queue, (void*)i);
56 if ((uintptr_t)spsc_queue_dequeue(&queue) != i)
57 return 1;
60 if (spsc_queue_dequeue(&queue))
61 return 1;
63 spsc_queue_destroy(&queue);
64 error = spsc_queue_init(&queue);
65 if (error)
66 return 1;
68 for (i = 1; i < 1024u; i++) {
69 error = spsc_queue_enqueue(&queue, (void*)i);
70 if (error)
71 return 1;
74 spsc_queue_destroy(&queue);
75 error = spsc_queue_init(&queue);
76 if (error)
77 return 1;
79 if (spsc_queue_dequeue(&queue))
80 return 1;
82 spsc_queue_destroy(&queue);