4 extern unsigned iterations;
5 extern unsigned initial_nodes;
6 extern private_t private;
7 extern shared_mem_t* smp;
11 private.node = 2 + initial_nodes + pid;
12 private.value = 1 + initial_nodes + (pid * iterations);
20 static unsigned new_node()
25 static void reclaim(unsigned node)
34 /* initialize queue */
35 smp->head.sep.ptr = 1;
36 smp->head.sep.count = 0;
37 smp->tail.sep.ptr = 1;
38 smp->tail.sep.count = 0;
39 smp->nodes[1].next.sep.ptr = NULL;
40 smp->nodes[1].next.sep.count = 0;
42 /* initialize avail list */
43 for (i=2; i<MAX_NODES; i++) {
44 smp->nodes[i].next.sep.ptr = i+1;
45 smp->nodes[i].next.sep.count = 0;
47 smp->nodes[MAX_NODES].next.sep.ptr = NULL;
48 smp->nodes[MAX_NODES].next.sep.count = 0;
50 /* initialize queue contents */
51 if (initial_nodes > 0) {
52 for (i=2; i<initial_nodes+2; i++) {
53 smp->nodes[i].value = i;
54 smp->nodes[i-1].next.sep.ptr = i;
55 smp->nodes[i].next.sep.ptr = NULL;
57 smp->head.sep.ptr = 1;
58 smp->tail.sep.ptr = 1 + initial_nodes;
62 void enqueue(unsigned val)
70 smp->nodes[node].value = val;
71 smp->nodes[node].next.sep.ptr = NULL;
73 for (success = FALSE; success == FALSE; ) {
74 tail.con = smp->tail.con;
75 next.con = smp->nodes[tail.sep.ptr].next.con;
76 if (tail.con == smp->tail.con) {
77 if (next.sep.ptr == NULL) {
78 success = cas(&smp->nodes[tail.sep.ptr].next,
80 MAKE_LONG(node, next.sep.count+1));
82 if (success == FALSE) {
85 MAKE_LONG(smp->nodes[tail.sep.ptr].next.sep.ptr,
93 MAKE_LONG(node, tail.sep.count+1));
104 for (success = FALSE; success == FALSE; ) {
105 head.con = smp->head.con;
106 tail.con = smp->tail.con;
107 next.con = smp->nodes[head.sep.ptr].next.con;
108 if (smp->head.con == head.con) {
109 if (head.sep.ptr == tail.sep.ptr) {
110 if (next.sep.ptr == NULL) {
115 MAKE_LONG(next.sep.ptr, tail.sep.count+1));
118 value = smp->nodes[next.sep.ptr].value;
119 success = cas(&smp->head,
121 MAKE_LONG(next.sep.ptr, head.sep.count+1));
122 if (success == FALSE) {
128 reclaim(head.sep.ptr);