]> git.saurik.com Git - apple/xnu.git/blame_incremental - tools/tests/xnu_quick_test/atomic_fifo_queue_test.c
xnu-1699.26.8.tar.gz
[apple/xnu.git] / tools / tests / xnu_quick_test / atomic_fifo_queue_test.c
... / ...
CommitLineData
1#if defined(i386) || defined(__x86_64__)
2
3#include <libkern/OSAtomic.h>
4#include <stdio.h>
5#include <string.h>
6#include <err.h>
7
8typedef struct {
9 void *next;
10 char *str;
11} QueueNode;
12
13int atomic_fifo_queue_test( void *the_argp ) {
14 OSFifoQueueHead head = OS_ATOMIC_FIFO_QUEUE_INIT;
15 char *str1 = "String 1", *str2 = "String 2";
16 QueueNode node1 = { 0, str1 };
17 OSAtomicFifoEnqueue(&head, &node1, 0);
18 QueueNode node2 = { 0, str2 };
19 OSAtomicFifoEnqueue(&head, &node2, 0);
20 QueueNode *node_ptr = OSAtomicFifoDequeue(&head, 0);
21 if( strcmp(node_ptr->str, str1) != 0 ) {
22 warnx("OSAtomicFifoDequeue returned incorrect string. Expected %s, got %s", str1, node_ptr->str);
23 return 1;
24 }
25 node_ptr = OSAtomicFifoDequeue(&head, 0);
26 if( strcmp(node_ptr->str, str2) != 0 ) {
27 warnx("OSAtomicFifoDequeue returned incorrect string. Expected %s, got %s", str2, node_ptr->str);
28 return 1;
29 }
30 return 0;
31}
32
33#endif