summaryrefslogtreecommitdiffstats
path: root/lock_free_queue.h
blob: 0bce83e47fdb9b4f8e388ce30882dea9e20e5518 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * File     : lock_free_queue.h
 * Author   : Jérémy Zurcher  <jeremy@asynk.ch>
 * Date     : 2009/11/01
 * License  : stolen from http://www.cs.rochester.edu/~scott/papers/1996_PODC_queues.pdf
 */

#ifndef  _LOCK_FREE_QUEUE_H_
#define _LOCK_FREE_QUEUE_H_

# ifdef __cplusplus
extern "C" {
# endif /* __cplusplus */

struct node;

typedef union pointer
{
   struct
     {
        volatile struct node *ptr;
        volatile unsigned int count;
     } split;
   volatile unsigned long long concat;
} pointer_t;

typedef struct node
{
   void *data;
   pointer_t next;
} node_t;

typedef struct queue
{
   pointer_t head;
   pointer_t tail;
} lfq_t;

void init(lfq_t *q);
void enqueue(lfq_t *q, void *data);
void* dequeue(lfq_t *q);

# ifdef __cplusplus
}
# endif /* __cplusplus */

# endif /* _LOCK_FREE_QUEUE_H_ */