25 if(next.
p == NULL || next.
mark1 || CAS(&block->
next,next,{next.p,next.mark2,true}))
break;
32 for(
int i=0;i<BLOCK_SIZE;i++) block->
nodes[i]=NULL;
36 for(
int i=0;i<NR_THREADS/WORD_SIZE;i++)
41 long old = block->
notifyAdd[Id/WORD_SIZE];
42 }
while(!CAS(&block->
notifyAdd[Id/WORD_SIZE],old,old|(1<<(Id%WORD_SIZE))));
46 return (block->
notifyAdd[Id/WORD_SIZE]&(1<<(Id%WORD_SIZE)))==0;
50 for(
int i=0;i<NR_THREADS;i++) globalHeadBlock[i]=NULL;
53 threadBlock = globalHeadBlock[
threadID];
56 stealBlock = NULL; stealPrev = NULL;
60 void Add(
void *item) {
64 if(head==BLOCK_SIZE) {
72 else if(block->
nodes[head]==NULL) {
74 block->
nodes[head]=item;
87 if(block == NULL || (head<0 && block->
next.p ==NULL)) {
92 if(result!=NULL)
return result;
96 else if(stealBlock==NULL) i++;
97 }
while(i<NR_THREADS);
98 }
while(++round<=NR_THREADS);
108 if(CAS(&globalHeadBlock[threadId],block,next.
p)) {
109 block->
next = {NULL,
false,
true};
110 DeleteNode(block); ReScan(next);
113 else block=DeRefLink(&globalHeadBlock[threadId]);
122 void *data = block->
nodes[head];
123 if(data==NULL) head--;
124 else if(CAS(&block->
nodes[head],data,NULL)) {
146 block = DeRefLink(&globalHeadBlock[
stealIndex]);
150 if(head==BLOCK_SIZE) {
157 stealBlock = NULL; stealPrev = NULL;
163 if(head==BLOCK_SIZE) {
168 void *data = block->
nodes[head];
169 if(data==NULL) head++;
170 else if(CAS(&block->
nodes[head],data,NULL)) {
182 block = DeRefLink(&globalHeadBlock[
stealIndex]);
185 next = DeRefLink(&block->
next);
187 if(stealPrev == NULL || next.
p == NULL) {
190 if(CAS(&globalHeadBlock[
stealIndex],block,next.
p)) {
191 block->
next = {NULL,
false,
true};
192 DeleteNode(block); ReScan(next);
196 block = DeRefLink(&globalHeadBlock[stealIndex]);
200 else stealPrev = block;
205 if(CAS(&stealPrev->
next,prevnext,next.
p)){
206 block->
next = {NULL,
false,
true};
207 DeleteNode(block); ReScan(next);
211 block = DeRefLink(&globalHeadBlock[
stealIndex]);
215 else if(block==stealBlock) {
216 if(CAS(&stealPrev->
next,block,{block,true,false})) {
222 block = DeRefLink(&globalHeadBlock[
stealIndex]);
226 else stealPrev = block;
228 if(block == stealBlock || next.
p == stealBlock) {
void NotifyAll(block_t *block)
void NotifyStart(block_t *block, int Id)
bool NotifyCheck(block_t *block, int Id)
block_t * globalHeadBlock[NR_THREADS]
long notifyAdd[NR_THREADS/WORD_SIZE]
void * TryStealBlock(int round)
static unsigned long * next
void Mark1Block(block_t *block)
block_t * NextStealBlock(block_t *block)