Exemple #1
0
void ggLock(void *lock)
{
	int *lck = lock;
	int i = 0;

	while (testandset(lck)) {
		if (i < GGLOCK_COUNT) {
			i++;
#ifdef HAVE_SCHED_YIELD
			sched_yield();
#endif
		} else {
#ifdef HAVE_NANOSLEEP
			struct timespec ts;
			ts.tv_sec = 0;
			ts.tv_nsec = (GGLOCK_SLEEP_US*1000);
			nanosleep(&ts, NULL);
#else
			ggUSleep(GGLOCK_SLEEP_US);
#endif
			i = 0;
		}
	}

	return;
}
Exemple #2
0
int ggTryLock(void *lock)
{
	int *lck = lock;

	if (testandset(lck)) return GGI_EBUSY;

	return 0;
}
int
__pthread_spin_lock (pthread_spinlock_t *lock)
{
  while (testandset (lock) != 0)
    ;

  return 0;
}
Exemple #4
0
/** semSignal **/
void semPost(semaphore_t *semaphore) {
   /** STUBBED **/
   runningTCB->inLock = 1;

   while (testandset(&(semaphore->locallock)) != 0) {
      tyield();
   }

   semaphore->count++;
   if( semaphore->count <= 0 ) {
      queue(readyList[0],dequeue(semaphore->waitlist)); 
   }

   semaphore->locallock = 0;

   runningTCB->inLock = 0;
}
Exemple #5
0
/** semWait **/
void semWait(semaphore_t *semaphore) {
   /** STUBBED **/
   runningTCB->inLock = 1;

   while (testandset(&(semaphore->locallock)) != 0) {
      tyield();
   }

   semaphore->count--;
   if( semaphore->count < 0 ) {
      queue(semaphore->waitlist, runningTCB); 
      semaphore->locallock = 0;
      runningTCB->inLock = 0;
      dispatch();
   } else {
      semaphore->locallock = 0;
      runningTCB->inLock = 0;
   }
}
int
__pthread_spin_trylock (pthread_spinlock_t *lock)
{
  return testandset (lock) != 0 ? EBUSY : 0;
}