MCPcopy Create free account
hub / github.com/F-Stack/f-stack / do_sem2_wait

Function do_sem2_wait

freebsd/kern/kern_umtx.c:3268–3347  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3266#endif
3267
3268static int
3269do_sem2_wait(struct thread *td, struct _usem2 *sem, struct _umtx_time *timeout)
3270{
3271 struct abs_timeout timo;
3272 struct umtx_q *uq;
3273 uint32_t count, flags;
3274 int error, rv;
3275
3276 uq = td->td_umtxq;
3277 flags = fuword32(&sem->_flags);
3278 if (timeout != NULL)
3279 abs_timeout_init2(&timo, timeout);
3280
3281again:
3282 error = umtx_key_get(sem, TYPE_SEM, GET_SHARE(flags), &uq->uq_key);
3283 if (error != 0)
3284 return (error);
3285 umtxq_lock(&uq->uq_key);
3286 umtxq_busy(&uq->uq_key);
3287 umtxq_insert(uq);
3288 umtxq_unlock(&uq->uq_key);
3289 rv = fueword32(&sem->_count, &count);
3290 if (rv == -1) {
3291 umtxq_lock(&uq->uq_key);
3292 umtxq_unbusy(&uq->uq_key);
3293 umtxq_remove(uq);
3294 umtxq_unlock(&uq->uq_key);
3295 umtx_key_release(&uq->uq_key);
3296 return (EFAULT);
3297 }
3298 for (;;) {
3299 if (USEM_COUNT(count) != 0) {
3300 umtxq_lock(&uq->uq_key);
3301 umtxq_unbusy(&uq->uq_key);
3302 umtxq_remove(uq);
3303 umtxq_unlock(&uq->uq_key);
3304 umtx_key_release(&uq->uq_key);
3305 return (0);
3306 }
3307 if (count == USEM_HAS_WAITERS)
3308 break;
3309 rv = casueword32(&sem->_count, 0, &count, USEM_HAS_WAITERS);
3310 if (rv == 0)
3311 break;
3312 umtxq_lock(&uq->uq_key);
3313 umtxq_unbusy(&uq->uq_key);
3314 umtxq_remove(uq);
3315 umtxq_unlock(&uq->uq_key);
3316 umtx_key_release(&uq->uq_key);
3317 if (rv == -1)
3318 return (EFAULT);
3319 rv = thread_check_susp(td, true);
3320 if (rv != 0)
3321 return (rv);
3322 goto again;
3323 }
3324 umtxq_lock(&uq->uq_key);
3325 umtxq_unbusy(&uq->uq_key);

Callers 1

__umtx_op_sem2_waitFunction · 0.85

Calls 13

fuword32Function · 0.85
abs_timeout_init2Function · 0.85
umtx_key_getFunction · 0.85
umtxq_lockFunction · 0.85
umtxq_busyFunction · 0.85
umtxq_unlockFunction · 0.85
fueword32Function · 0.85
umtxq_unbusyFunction · 0.85
umtx_key_releaseFunction · 0.85
casueword32Function · 0.85
thread_check_suspFunction · 0.85
umtxq_sleepFunction · 0.85

Tested by

no test coverage detected