do { oldstatus = sem->sem_status; if ((oldstatus & 1) == 0 || (oldstatus == 1)) { errno = EAGAIN; return -1; } newstatus = oldstatus - 2;
__pthread_lock((struct _pthread_fastlock *) &sem->sem_lock); if (sem->sem_value == 0) { errno = EAGAIN; retval = -1; } else { sem->sem_value--; retval = 0;
int sem_trywait(sem_t * sem){  long oldstatus, newstatus;  do {    oldstatus = sem->sem_status;    if ((oldstatus & 1) == 0 || (oldstatus == 1)) {      errno = EAGAIN;      return -1;    }    newstatus = oldstatus - 2;  }  while (! sem_compare_and_swap(sem, oldstatus, newstatus));  return 0;}