Example #1
0
void
GPEnabled::destroy()
{
  // Only delete if the counter is still zero.
  // because someone may have rescued the object...
  // If yes, set the counter to -0x7fff to mark 
  // the object as doomed and make sure things
  // will work if the destructor uses a GP...
  if (atomicCompareAndSwap(&count, 0, -0x7fff))
    delete this;
}
Example #2
0
void TBPClose(TBPHandle *H)
{
  atomicCompareAndSwap(&H->current_task, H->current_task, -1);

  for (int i = 0; i < H->threads; i++) {
    pthread_join(H->workthreads[i], NULL);

    free(H->daemons[i]);
  }
  free(H->daemons);
  free(H->results);
  free(H->workthreads);
  free(H);
}
bool LazyInstanceState::needConstruction() {
    AtomicType state = loadAcquire(&mState);
    if (mState == STATE_DONE)
        return false;

    state = atomicCompareAndSwap(&mState, STATE_INIT, STATE_CONSTRUCTING);
    if (state == STATE_INIT)
        return true;

    do {
        yieldThread();
        state = loadAcquire(&mState);
    } while (state != STATE_DONE);

    return false;
}
Example #4
0
void *tbp_thread_daemon(void *threaddata_vp) {
  TBPDaemon *D = threaddata_vp;

  int mytask = 0;

  for (;;) {
    // Wait for a new task
    int newtask;
    while (atomicCompareAndSwap(&D->H->current_task, mytask+1, mytask+1) == 0) {
      ThreadYield();
    }
    newtask = D->H->current_task;
    if (newtask == -1) { // Terminate
      break;
    }
    // new task
    mytask = newtask;
    D->result = D->H->current_task_start_routine(D->threaddata, D->H->current_task_data);
    atomicFetchAndAdd(&D->H->jobs_complete, 1);

    // and wait for a new task.
  }
  return NULL;
}