예제 #1
0
void spinWithdraw1(int junk, int a) {
  int res = 1;
  int tries = 0;
  int i;
  int oldTries;

  while(res != 0) {
    //crap
    oldTries = tries;
    for(i = 0; i < oldTries; i++) {
      tries--;
    }
    tries = oldTries;
    res = _spin_trylock(&gLock1);
    tries++;
    oldTries = tries;
    for(i = 0; i < oldTries; i++) {
      tries--;
    }
    tries = oldTries;
  }

  donor1_blood -= a;

  _spin_unlock(&gLock1);
}
예제 #2
0
void deposit2(int a) {
  int res;

  res = _spin_trylock(&gLock2);
  if(res == 0) {
    donor2_blood += a;
    _spin_unlock(&gLock2);
  }
}
예제 #3
0
int withdraw2(int a) {
  int res;

  res = _spin_trylock(&gLock2);
  if(res == 0) {
    donor2_blood -= a;
    _spin_unlock(&gLock2);
  }
  return donor2_blood;
}
예제 #4
0
파일: sm_locking2.c 프로젝트: UIKit0/smatch
int func (void)
{
	int mylock = 1;
	int mylock2 = 1;
	int mylock3 = 1;

	if (!_spin_trylock(mylock)) {
		return;
	}

	_spin_unlock(mylock);
	_spin_unlock(mylock2);

	if (a)
		_spin_unlock(mylock);
	_spin_lock(mylock2);

	if (!_spin_trylock(mylock3))
		return;
	return;
}
예제 #5
0
int transfer(int a) {
  int res;
  int succ = 0;

  res = _spin_trylock(&gLock1);
  if(res == 0) {
    res = _spin_trylock(&gLock2);
    if(res == 0) {

      if(donor1_blood >= a) {
        donor1_blood -= a;
        donor2_blood += a;
        succ = 1;
      }
      
      _spin_unlock(&gLock2);
    }
    _spin_unlock(&gLock1);
  }

  return succ;
}
예제 #6
0
int safeDeposit(spinlock_t *l, int dnum, int a) {
  int res;
  int succ = 0;

  res = _spin_trylock(l);
  if(res == 0) {
    switch (dnum) {
    case 1: donor1_blood += a;
      break;
    case 2: donor2_blood += a;
      break;
    }
    succ = 1;

  }


  if(res == 0) {
    donor1_blood += 1;
    _spin_unlock(l);
  }

  return succ;
}