Lines Matching defs:mtx
143 struct rumpuser_mtx *mtx;
147 allocsz = (sizeof(*mtx)+RUMPUSER_LOCKALIGN) & ~(RUMPUSER_LOCKALIGN-1);
148 NOFAIL(mtx = aligned_alloc(RUMPUSER_LOCKALIGN, allocsz));
152 NOFAIL_ERRNO(pthread_mutex_init(&mtx->pthmtx, &att));
155 mtx->owner = NULL;
157 mtx->flags = flags;
159 *mtxp = mtx;
163 rumpuser_mutex_spin_p(struct rumpuser_mtx *mtx)
166 return (mtx->flags & RUMPUSER_MTX_SPIN) != 0;
170 mtxenter(struct rumpuser_mtx *mtx)
173 if (!(mtx->flags & RUMPUSER_MTX_KMUTEX))
176 assert(mtx->owner == NULL);
177 mtx->owner = rumpuser_curlwp();
181 mtxexit(struct rumpuser_mtx *mtx)
184 if (!(mtx->flags & RUMPUSER_MTX_KMUTEX))
187 assert(mtx->owner != NULL);
188 mtx->owner = NULL;
192 rumpuser_mutex_enter(struct rumpuser_mtx *mtx)
195 if (mtx->flags & RUMPUSER_MTX_SPIN) {
196 rumpuser_mutex_enter_nowrap(mtx);
200 assert(mtx->flags & RUMPUSER_MTX_KMUTEX);
201 if (pthread_mutex_trylock(&mtx->pthmtx) != 0)
202 KLOCK_WRAP(NOFAIL_ERRNO(pthread_mutex_lock(&mtx->pthmtx)));
203 mtxenter(mtx);
207 rumpuser_mutex_enter_nowrap(struct rumpuser_mtx *mtx)
210 assert(mtx->flags & RUMPUSER_MTX_SPIN);
211 NOFAIL_ERRNO(pthread_mutex_lock(&mtx->pthmtx));
212 mtxenter(mtx);
216 rumpuser_mutex_tryenter(struct rumpuser_mtx *mtx)
220 rv = pthread_mutex_trylock(&mtx->pthmtx);
222 mtxenter(mtx);
229 rumpuser_mutex_exit(struct rumpuser_mtx *mtx)
232 mtxexit(mtx);
233 NOFAIL_ERRNO(pthread_mutex_unlock(&mtx->pthmtx));
237 rumpuser_mutex_destroy(struct rumpuser_mtx *mtx)
240 NOFAIL_ERRNO(pthread_mutex_destroy(&mtx->pthmtx));
241 free(mtx);
245 rumpuser_mutex_owner(struct rumpuser_mtx *mtx, struct lwp **lp)
248 if (__predict_false(!(mtx->flags & RUMPUSER_MTX_KMUTEX))) {
253 *lp = mtx->owner;
519 cv_unschedule(struct rumpuser_mtx *mtx, int *nlocks)
522 rumpkern_unsched(nlocks, mtx);
523 mtxexit(mtx);
527 cv_reschedule(struct rumpuser_mtx *mtx, int nlocks)
545 if ((mtx->flags & (RUMPUSER_MTX_SPIN | RUMPUSER_MTX_KMUTEX)) ==
547 NOFAIL_ERRNO(pthread_mutex_unlock(&mtx->pthmtx));
548 rumpkern_sched(nlocks, mtx);
549 rumpuser_mutex_enter_nowrap(mtx);
551 mtxenter(mtx);
552 rumpkern_sched(nlocks, mtx);
557 rumpuser_cv_wait(struct rumpuser_cv *cv, struct rumpuser_mtx *mtx)
562 cv_unschedule(mtx, &nlocks);
563 NOFAIL_ERRNO(pthread_cond_wait(&cv->pthcv, &mtx->pthmtx));
564 cv_reschedule(mtx, nlocks);
569 rumpuser_cv_wait_nowrap(struct rumpuser_cv *cv, struct rumpuser_mtx *mtx)
573 mtxexit(mtx);
574 NOFAIL_ERRNO(pthread_cond_wait(&cv->pthcv, &mtx->pthmtx));
575 mtxenter(mtx);
580 rumpuser_cv_timedwait(struct rumpuser_cv *cv, struct rumpuser_mtx *mtx,
596 cv_unschedule(mtx, &nlocks);
604 rv = pthread_cond_timedwait(&cv->pthcv, &mtx->pthmtx, &ts);
606 cv_reschedule(mtx, nlocks);