lib/libthread_xu/thread/thr_umtx.c
int
__thr_umtx_lock(volatile umtx_t *mtx, int timo)
{
	int v, errval, ret = 0;

	/* contested */
	do {
		v = *mtx;
		if (v == 2 || atomic_cmpset_acq_int(mtx, 1, 2)) {
			if (timo == 0)
				_umtx_sleep_err(mtx, 2, timo);
			else if ( (errval = _umtx_sleep_err(mtx, 2, timo)) > 0) {
				if (errval == EAGAIN) {
					if (atomic_cmpset_acq_int(mtx, 0, 2))
						ret = 0;
					else
						ret = ETIMEDOUT;
					break;
				}
			}
		}
	} while (!atomic_cmpset_acq_int(mtx, 0, 2));

	return (ret);
}
/*
 * This function is used to acquire a contested lock.
 */
This function is used to acquire a contested lock.
This function is used to acquire a contested lock .
int
__thr_umtx_lock(volatile umtx_t *mtx, int timo)
{
	int v, errval, ret = 0;
	do {
		v = *mtx;
		if (v == 2 || atomic_cmpset_acq_int(mtx, 1, 2)) {
			if (timo == 0)
				_umtx_sleep_err(mtx, 2, timo);
			else if ( (errval = _umtx_sleep_err(mtx, 2, timo)) > 0) {
				if (errval == EAGAIN) {
					if (atomic_cmpset_acq_int(mtx, 0, 2))
						ret = 0;
					else
						ret = ETIMEDOUT;
					break;
				}
			}
		}
	} while (!atomic_cmpset_acq_int(mtx, 0, 2));
	return (ret);
}
int __thr_umtx_lock ( volatile umtx_t * mtx , int timo ) { int v , errval , ret = 0 ; do { v = * mtx ; if ( v == 2 || atomic_cmpset_acq_int ( mtx , 1 , 2 ) ) { if ( timo == 0 ) _umtx_sleep_err ( mtx , 2 , timo ) ; else if ( ( errval = _umtx_sleep_err ( mtx , 2 , timo ) ) > 0 ) { if ( errval == EAGAIN ) { if ( atomic_cmpset_acq_int ( mtx , 0 , 2 ) ) ret = 0 ; else ret = ETIMEDOUT ; break ; } } } } while ( ! atomic_cmpset_acq_int ( mtx , 0 , 2 ) ) ; return ( ret ) ; }
This function is used to acquire a contested lock.
This function is used to acquire a contested lock .
/* contested */