4 extern unsigned iterations;
5 extern unsigned initial_nodes;
6 extern unsigned backoff;
7 extern unsigned backoff_base;
8 extern private_t private;
9 extern shared_mem_t* smp;
14 private.node = 2 + initial_nodes + pid;
15 private.value = 1 + initial_nodes + (pid * iterations);
31 reclaim(unsigned node)
41 /* initialize queue */
42 smp->head.sep.ptr = 1;
43 smp->head.sep.count = 0;
44 smp->tail.sep.ptr = 1;
45 smp->tail.sep.count = 0;
46 smp->nodes[1].next.sep.ptr = NULL;
47 smp->nodes[1].next.sep.count = 0;
49 /* initialize avail list */
50 for (i=2; i<MAX_NODES; i++) {
51 smp->nodes[i].next.sep.ptr = i+1;
52 smp->nodes[i].next.sep.count = 0;
54 smp->nodes[MAX_NODES].next.sep.ptr = NULL;
55 smp->nodes[MAX_NODES].next.sep.count = 0;
57 /* initialize queue contents */
58 if (initial_nodes > 0) {
59 for (i=2; i<initial_nodes+2; i++) {
60 smp->nodes[i].value = i;
61 smp->nodes[i-1].next.sep.ptr = i;
62 smp->nodes[i].next.sep.ptr = NULL;
64 smp->head.sep.ptr = 1;
65 smp->tail.sep.ptr = 1 + initial_nodes;
78 smp->nodes[node].value = val;
79 smp->nodes[node].next.sep.ptr = NULL;
81 backoff = backoff_base;
82 for (success = FALSE; success == FALSE; ) {
83 tail.con = smp->tail.con;
84 next.con = smp->nodes[tail.sep.ptr].next.con;
85 if (tail.con == smp->tail.con) {
86 if (next.sep.ptr == NULL) {
87 backoff = backoff_base;
88 success = cas(&smp->nodes[tail.sep.ptr].next,
90 MAKE_LONG(node, next.sep.count+1));
92 if (success == FALSE) {
95 MAKE_LONG(smp->nodes[tail.sep.ptr].next.sep.ptr,
103 MAKE_LONG(node, tail.sep.count+1));
115 backoff = backoff_base;
116 for (success = FALSE; success == FALSE; ) {
117 head.con = smp->head.con;
118 tail.con = smp->tail.con;
119 next.con = smp->nodes[head.sep.ptr].next.con;
120 if (smp->head.con == head.con) {
121 if (head.sep.ptr == tail.sep.ptr) {
122 if (next.sep.ptr == NULL) {
127 MAKE_LONG(next.sep.ptr, tail.sep.count+1));
130 value = smp->nodes[next.sep.ptr].value;
131 success = cas(&smp->head,
133 MAKE_LONG(next.sep.ptr, head.sep.count+1));
134 if (success == FALSE) {
140 reclaim(head.sep.ptr);