From 49b5ab5b028754ec66dab3a60d42300a4f26979d Mon Sep 17 00:00:00 2001 From: yeom Date: Wed, 6 Apr 2011 00:39:23 +0000 Subject: [PATCH] changes: handle the case that there is only one work item after enqueue, then it reports nothing and makes the worker steal from other queues. --- Robust/src/Runtime/squeue.h | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/Robust/src/Runtime/squeue.h b/Robust/src/Runtime/squeue.h index f15c1a13..73963c29 100644 --- a/Robust/src/Runtime/squeue.h +++ b/Robust/src/Runtime/squeue.h @@ -133,6 +133,35 @@ static inline void dqPushBottom( deque* p, void* work ) { p->tail=realptr; } +static inline void* dqPopTopSelf(deque *p) { + int tryagain=1; + while(1) { + dequeItem *ptr=p->head; + dequeItem *realptr=(dequeItem *) EXTRACTPTR((INTPTR)ptr); + dequeItem *next=realptr->next; + //remove if we can..steal work no matter what + if (likely(next!=NULL)) { + if (((dequeItem *)CAS(&(p->head),(INTPTR)ptr, (INTPTR)next))!=ptr) + return DQ_POP_EMPTY; + void * item=NULL; + item=(void *)LOCKXCHG((unsigned INTPTR*) &(realptr->work), (unsigned INTPTR) item); + realptr->next=NULL; + BARRIER(); + tagpoolfreeinto(&p->objret,ptr, realptr); + if (item==NULL&&tryagain) { + tryagain=0; + continue; + } + return item; + } else { + void * item=NULL; + if (realptr->work!=NULL) + item=(void *) LOCKXCHG((unsigned INTPTR*) &(realptr->work), (unsigned INTPTR) item); + return item; + } + } +} + static inline void* dqPopTop(deque *p) { dequeItem *ptr=p->head; dequeItem *realptr=(dequeItem *) EXTRACTPTR((INTPTR)ptr); @@ -155,7 +184,7 @@ static inline void* dqPopTop(deque *p) { } } -#define dqPopBottom dqPopTop +#define dqPopBottom dqPopTopSelf #endif // ___MEMPOOL_H__ -- 2.34.1