diff options
author | Renato Botelho <renato@netgate.com> | 2016-08-01 12:53:16 -0300 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2016-08-01 12:53:16 -0300 |
commit | 80c20d0bef69a2c543d1bc2dddd2bc34198fec9b (patch) | |
tree | fc6009a2d49da5ab043d4c847a288f71ec6aa731 /sys/kern/kern_mutex.c | |
parent | f235fecdc77c17505022bc5202d74f3d36b33359 (diff) | |
parent | eed7d9e93aec04a3f6a7d157c4cac7452a6c1727 (diff) | |
download | FreeBSD-src-80c20d0bef69a2c543d1bc2dddd2bc34198fec9b.zip FreeBSD-src-80c20d0bef69a2c543d1bc2dddd2bc34198fec9b.tar.gz |
Merge remote-tracking branch 'origin/stable/11' into devel-11
Diffstat (limited to 'sys/kern/kern_mutex.c')
-rw-r--r-- | sys/kern/kern_mutex.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c index 012cf7c..453add4 100644 --- a/sys/kern/kern_mutex.c +++ b/sys/kern/kern_mutex.c @@ -281,6 +281,34 @@ __mtx_lock_spin_flags(volatile uintptr_t *c, int opts, const char *file, WITNESS_LOCK(&m->lock_object, opts | LOP_EXCLUSIVE, file, line); } +int +__mtx_trylock_spin_flags(volatile uintptr_t *c, int opts, const char *file, + int line) +{ + struct mtx *m; + + if (SCHEDULER_STOPPED()) + return (1); + + m = mtxlock2mtx(c); + + KASSERT(m->mtx_lock != MTX_DESTROYED, + ("mtx_trylock_spin() of destroyed mutex @ %s:%d", file, line)); + KASSERT(LOCK_CLASS(&m->lock_object) == &lock_class_mtx_spin, + ("mtx_trylock_spin() of sleep mutex %s @ %s:%d", + m->lock_object.lo_name, file, line)); + KASSERT((opts & MTX_RECURSE) == 0, + ("mtx_trylock_spin: unsupp. opt MTX_RECURSE on mutex %s @ %s:%d\n", + m->lock_object.lo_name, file, line)); + if (__mtx_trylock_spin(m, curthread, opts, file, line)) { + LOCK_LOG_TRY("LOCK", &m->lock_object, opts, 1, file, line); + WITNESS_LOCK(&m->lock_object, opts | LOP_EXCLUSIVE, file, line); + return (1); + } + LOCK_LOG_TRY("LOCK", &m->lock_object, opts, 0, file, line); + return (0); +} + void __mtx_unlock_spin_flags(volatile uintptr_t *c, int opts, const char *file, int line) |