void stringIdGetMemoryTracking( uint64 & retSidCount, uint64 & retStaticSidCount, uint64 & retSidBytes ) { retSidCount = atomicRead( &totalStringIds_ ); retStaticSidCount = atomicRead( &totalStaticStringIds_ ); retSidBytes = atomicRead( &totalStringBytes_ ); }
void workerThread (State *s) { taskID work; watchList *tasksToNotify, next; bool canQueue; do { task = getWork(dispatch); /* Do stuff */ atomicWrite(status[work] = INPROGRESS); doStuff(work); atomicWrite(status[work] = DONE); /* NOTE : Race condition */ tasksToNotify = getWatches(work); while (tasksToNotify != NULL) { next = tasksToNotify->tail; canQueue = TRUE; foreach (dep in dep[tasksToNotify->id]) { /* OPT : Watch ordering */ if (atomicRead(status[dep]) != DONE) { /* NOTE : Race condition */ if (moveWatch(watch[dep],tasksToNotify)) { canQueue = FALSE; break; } else { /* Have hit the race condition, try the next option */ assert(atomicRead(status[dep]) == DONE); } } } if (canQueue) { /* OPT : Save one work item */ addWork(*dispatch,tasksToNotify->id); deleteWatch(tasksToNotify); } tasksToNotify = next; } } while (1); /* NOTE : some kind of control for thread exit needed */ return; }
int moveWatch (watchList **w, watchList *t) { watchList *local; t->tail = NULL; do { local = atomicRead(*w); if (local == doNotAdd) { return 0; } else { t->tail = local; } } while (!atomicCAS(*w,local,t)); /* OPT : Delay loop */ return 1; }