Changeset View
Changeset View
Standalone View
Standalone View
head/sys/compat/linuxkpi/common/src/linux_lock.c
Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | |||||
static inline void | static inline void | ||||
linux_ww_unlock(void) | linux_ww_unlock(void) | ||||
{ | { | ||||
mtx_unlock(&ww_mutex_global); | mtx_unlock(&ww_mutex_global); | ||||
} | } | ||||
/* lock a mutex with deadlock avoidance */ | /* lock a mutex with deadlock avoidance */ | ||||
int | int | ||||
linux_ww_mutex_lock_sub(struct ww_mutex *lock, int catch_signal) | linux_ww_mutex_lock_sub(struct ww_mutex *lock, | ||||
struct ww_acquire_ctx *ctx, int catch_signal) | |||||
{ | { | ||||
struct task_struct *task; | struct task_struct *task; | ||||
struct ww_mutex_thread entry; | struct ww_mutex_thread entry; | ||||
struct ww_mutex_thread *other; | struct ww_mutex_thread *other; | ||||
int retval = 0; | int retval = 0; | ||||
task = current; | task = current; | ||||
Show All 38 Lines | if (unlikely(sx_try_xlock(&lock->base.sx) == 0)) { | ||||
} while (sx_try_xlock(&lock->base.sx) == 0); | } while (sx_try_xlock(&lock->base.sx) == 0); | ||||
done: | done: | ||||
TAILQ_REMOVE(&ww_mutex_head, &entry, entry); | TAILQ_REMOVE(&ww_mutex_head, &entry, entry); | ||||
/* if the lock is free, wakeup next lock waiter, if any */ | /* if the lock is free, wakeup next lock waiter, if any */ | ||||
if ((struct thread *)SX_OWNER(lock->base.sx.sx_lock) == NULL) | if ((struct thread *)SX_OWNER(lock->base.sx.sx_lock) == NULL) | ||||
cv_signal(&lock->condvar); | cv_signal(&lock->condvar); | ||||
} | } | ||||
if (retval == 0) | |||||
lock->ctx = ctx; | |||||
linux_ww_unlock(); | linux_ww_unlock(); | ||||
return (retval); | return (retval); | ||||
} | } | ||||
void | void | ||||
linux_ww_mutex_unlock_sub(struct ww_mutex *lock) | linux_ww_mutex_unlock_sub(struct ww_mutex *lock) | ||||
{ | { | ||||
/* protect ww_mutex ownership change */ | /* protect ww_mutex ownership change */ | ||||
linux_ww_lock(); | linux_ww_lock(); | ||||
lock->ctx = NULL; | |||||
sx_xunlock(&lock->base.sx); | sx_xunlock(&lock->base.sx); | ||||
/* wakeup a lock waiter, if any */ | /* wakeup a lock waiter, if any */ | ||||
cv_signal(&lock->condvar); | cv_signal(&lock->condvar); | ||||
linux_ww_unlock(); | linux_ww_unlock(); | ||||
} | } | ||||
int | int | ||||
linux_mutex_lock_interruptible(mutex_t *m) | linux_mutex_lock_interruptible(mutex_t *m) | ||||
Show All 23 Lines |