From: Matthew Dillon Date: Fri, 7 Aug 2009 06:09:19 +0000 (-0700) Subject: Kernel mtx - Add mtxsleep(), interlocked tsleep w/ mutexes X-Git-Tag: v2.4.0~324 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/7f6220a9966bf104115eb413930aea5f901bedc8 Kernel mtx - Add mtxsleep(), interlocked tsleep w/ mutexes --- diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index 23095b3595..76dfb63a87 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -61,6 +61,7 @@ #include #include +#include #include #include @@ -693,6 +694,26 @@ msleep(void *ident, struct spinlock *spin, int flags, return (error); } +/* + * Interlocked mutex sleep. An exclusively held mutex must be passed + * to mtxsleep(). The function will atomically release the mutex + * and tsleep on the ident, then reacquire the mutex and return. + */ +int +mtxsleep(void *ident, struct mtx *mtx, int flags, + const char *wmesg, int timo) +{ + globaldata_t gd = mycpu; + int error; + + _tsleep_interlock(gd, ident, flags); + mtx_unlock(mtx); + error = tsleep(ident, flags | PINTERLOCKED, wmesg, timo); + mtx_lock_ex_quick(mtx, wmesg); + + return (error); +} + /* * Interlocked serializer sleep. An exclusively held serializer must * be passed to serialize_sleep(). The function will atomically release diff --git a/sys/sys/systm.h b/sys/sys/systm.h index 7a2fb3795a..d1df7691be 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -123,6 +123,7 @@ extern vm_paddr_t Maxmem; /* Highest physical memory address in system */ struct intrframe; struct spinlock; +struct mtx; struct lwkt_serialize; struct malloc_type; struct proc; @@ -332,6 +333,7 @@ extern watchdog_tickle_fn wdog_tickler; */ int tsleep (void *, int, const char *, int); int msleep (void *, struct spinlock *, int, const char *, int); +int mtxsleep (void *, struct mtx *, int, const char *, int); int serialize_sleep(void *, struct lwkt_serialize *, int, const char *, int); void tsleep_interlock (void *, int);