void armci_lapi_unlock(int *lock) { atomic_p word_addr = (atomic_p)lock; if(_check_lock(word_addr, LOCKED, 0) == TRUE ) armci_die("somebody else unlocked",0); }
void armci_lapi_lock(int *lock) { atomic_p word_addr = (atomic_p)lock; int spin = 1; while(1){ if(_check_lock(word_addr, 0, LOCKED) == FALSE ) break; /* we got the lock */ if(spin){ armci_waitsome(1); spin = 0; }else{ /* yield processor to another thread */ /* cannot yield w/o affecting thread priority - better sleep */ /* yield(); */ /* call usleep to notify scheduler */ (void)usleep(5); } } }
PR_StackPush(PRStack *stack, PRStackElem *stack_elem) { PRStackElem *addr; boolean_t locked = TRUE; /* Is it safe to cast a pointer to an int? */ PR_ASSERT(sizeof(int) == sizeof(PRStackElem *)); do { while ((addr = stack->prstk_head.prstk_elem_next) == (PRStackElem *)_PR_AIX_ATOMIC_LOCK) ; locked = _check_lock((atomic_p) &stack->prstk_head.prstk_elem_next, (int) addr, _PR_AIX_ATOMIC_LOCK); } while (locked == TRUE); stack_elem->prstk_elem_next = addr; _clear_lock((atomic_p)&stack->prstk_head.prstk_elem_next, (int)stack_elem); return; }
PR_StackPop(PRStack *stack) { PRStackElem *element; boolean_t locked = TRUE; /* Is it safe to cast a pointer to an int? */ PR_ASSERT(sizeof(int) == sizeof(PRStackElem *)); do { while ((element = stack->prstk_head.prstk_elem_next) == (PRStackElem *) _PR_AIX_ATOMIC_LOCK) ; locked = _check_lock((atomic_p) &stack->prstk_head.prstk_elem_next, (int)element, _PR_AIX_ATOMIC_LOCK); } while (locked == TRUE); if (element == NULL) { _clear_lock((atomic_p) &stack->prstk_head.prstk_elem_next, NULL); } else { _clear_lock((atomic_p) &stack->prstk_head.prstk_elem_next, (int) element->prstk_elem_next); } return element; }