| Commit | Line | Data |
|---|---|---|
| b46c3c82 | 1 | #include <netgraph7/ng_message.h> |
| 0147868e NA |
2 | |
| 3 | #include <sys/malloc.h> | |
| 4 | #include <sys/linker.h> | |
| 5 | #include <sys/thread2.h> | |
| 6 | #include <sys/vnode.h> | |
| 7 | ||
| 8 | #include "dragonfly.h" | |
| 9 | ||
| 10 | /* Temporary lock stuff. */ | |
| 11 | #include <sys/lock.h> | |
| 12 | /* End Temporary lock stuff. */ | |
| 13 | ||
| 0147868e NA |
14 | |
| 15 | ||
| 16 | /* Locking stuff. */ | |
| 17 | ||
| 18 | ||
| 19 | int | |
| 20 | lockstatus_owned(struct lock *lkp, struct thread *td) | |
| 21 | { | |
| 22 | int lock_type = 0; | |
| 23 | ||
| 24 | if (lkp->lk_exclusivecount != 0) { | |
| 25 | if (td == NULL || lkp->lk_lockholder == td) | |
| 26 | lock_type = LK_EXCLUSIVE; | |
| 27 | else | |
| 28 | lock_type = LK_EXCLOTHER; | |
| 29 | } else if (lkp->lk_sharecount != 0) { | |
| 30 | lock_type = LK_SHARED; | |
| 31 | } | |
| 32 | return (lock_type); | |
| 33 | } | |
| 34 | ||
| 35 | /* | |
| 36 | * Atomically drop a lockmgr lock and go to sleep. The lock is reacquired | |
| 37 | * before returning from this function. Passes on the value returned by | |
| 38 | * tsleep(). | |
| 39 | */ | |
| 40 | int | |
| 41 | lock_sleep(void *ident, int flags, const char *wmesg, int timo, | |
| 42 | struct lock *lk) | |
| 43 | { | |
| 44 | int err, mode; | |
| 45 | ||
| 46 | mode = lockstatus_owned(lk, curthread); | |
| 47 | KKASSERT((mode == LK_EXCLUSIVE) || (mode == LK_SHARED)); | |
| 48 | ||
| 49 | crit_enter(); | |
| 530b6fa9 | 50 | tsleep_interlock(ident, flags); |
| 0147868e NA |
51 | lockmgr(lk, LK_RELEASE); |
| 52 | err = tsleep(ident, flags, wmesg, timo); | |
| 53 | crit_exit(); | |
| 54 | lockmgr(lk, mode); | |
| 55 | return err; | |
| 56 | } |