示例#1
0
void *thread_main8(void *arg)
{
  /*  The mutator will patch in messaging primitives to signal events at mutex creation,
      deletion, locking and unlocking.  Thus far, we are only considering reporting of events
      so actual contention is meaningless */
  Lock_t newmutex;
  if (!createLock(&newmutex)) {
     fprintf(stderr, "%s[%d]:  createLock failed\n", __FILE__, __LINE__);
     return NULL;
  }
  sleep_ms(100);
  if (!lockLock(&newmutex)) {
     fprintf(stderr, "%s[%d]:  lockLock failed\n", __FILE__, __LINE__);
     return NULL;
  }
  sleep_ms(100);
  if (!unlockLock(&newmutex)) {
     fprintf(stderr, "%s[%d]:  unlockLock failed\n", __FILE__, __LINE__);
     return NULL;
  }
  sleep_ms(100); 
  if (!destroyLock(&newmutex)) {
     fprintf(stderr, "%s[%d]:  destroyLock failed\n", __FILE__, __LINE__);
     return NULL;
  }

  sleep(1);
  return NULL;
}
示例#2
0
static int decrementLock(void * dat, int datLen, int currentLevel) {
  //  pthread_mutex_unlock(&xid_table_mutex);
  pthread_mutex_t * mut = getMutex(dat, datLen);
  pthread_mutex_lock(mut);
  lock * ridLock = pblHtLookup_r(ridLockTable, dat, datLen);
  assert(ridLock);
  ridLock->active++;
  if(currentLevel == LM_WRITELOCK) {
    ridLock->writers--;
    ridLock->readers--;
  } else if(currentLevel == LM_READLOCK) {
    ridLock->readers--;
  } else if(currentLevel == 0) {
    assert(0); // Someone tried to release a lock they didn't own!
  } else {
    fprintf(stderr, "Unknown lock type encountered!");
    ridLock->active--;
    pthread_mutex_unlock(mut);
    return LLADD_INTERNAL_ERROR;
  }

  ridLock->active--;

  if(!(ridLock->active || ridLock->waiting || ridLock->readers || ridLock->writers)) {
    //   printf("destroyed lock");
    destroyLock(dat, datLen, ridLock);
  } else {
    //    printf("(%d %d %d %d)", ridLock->active, ridLock->waiting, ridLock->readers, ridLock->writers);
  }
  pthread_mutex_unlock(mut);
  return 0;
}
示例#3
0
void callBack()
{
	destroyLock(&mutex);
}