summaryrefslogtreecommitdiffstats
path: root/sys/sys/mutex.h
diff options
context:
space:
mode:
authorattilio <attilio@FreeBSD.org>2011-11-20 16:33:09 +0000
committerattilio <attilio@FreeBSD.org>2011-11-20 16:33:09 +0000
commit6a69e947d3eb5ffaceb04f999c1925ed771b7546 (patch)
tree1fcde0be5ef74d1581c3a825bc7f36ff5d1c05b3 /sys/sys/mutex.h
parentbf5f03ca46a93268d5d0eccc7318039bda9106d2 (diff)
downloadFreeBSD-src-6a69e947d3eb5ffaceb04f999c1925ed771b7546.zip
FreeBSD-src-6a69e947d3eb5ffaceb04f999c1925ed771b7546.tar.gz
Introduce macro stubs in the mutex implementation that will be always
defined and will allow consumers, willing to provide options, file and line to locking requests, to not worry about options redefining the interfaces. This is typically useful when there is the need to build another locking interface on top of the mutex one. The introduced functions that consumers can use are: - mtx_lock_flags_ - mtx_unlock_flags_ - mtx_lock_spin_flags_ - mtx_unlock_spin_flags_ - mtx_assert_ - thread_lock_flags_ Spare notes: - Likely we can get rid of all the 'INVARIANTS' specification in the ppbus code by using the same macro as done in this patch (but this is left to the ppbus maintainer) - all the other locking interfaces may require a similar cleanup, where the most notable case is sx which will allow a further cleanup of vm_map locking facilities - The patch should be fully compatible with older branches, thus a MFC is previewed (infact it uses all the underlying mechanisms already present). Comments review by: eadler, Ben Kaduk Discussed with: kib, jhb MFC after: 1 month
Diffstat (limited to 'sys/sys/mutex.h')
-rw-r--r--sys/sys/mutex.h75
1 files changed, 45 insertions, 30 deletions
diff --git a/sys/sys/mutex.h b/sys/sys/mutex.h
index 7a9d5d7..1e88e10 100644
--- a/sys/sys/mutex.h
+++ b/sys/sys/mutex.h
@@ -81,6 +81,10 @@
* of the kernel via macros, thus allowing us to use the cpp LOCK_FILE
* and LOCK_LINE. These functions should not be called directly by any
* code using the API. Their macros cover their functionality.
+ * Functions with a `_' suffix are the entrypoint for the common
+ * KPI covering both compat shims and fast path case. These can be
+ * used by consumers willing to pass options, file and line
+ * informations, in an option-independent way.
*
* [See below for descriptions]
*
@@ -88,6 +92,8 @@
void mtx_init(struct mtx *m, const char *name, const char *type, int opts);
void mtx_destroy(struct mtx *m);
void mtx_sysinit(void *arg);
+int mtx_trylock_flags_(struct mtx *m, int opts, const char *file,
+ int line);
void mutex_init(void);
void _mtx_lock_sleep(struct mtx *m, uintptr_t tid, int opts,
const char *file, int line);
@@ -97,7 +103,6 @@ void _mtx_lock_spin(struct mtx *m, uintptr_t tid, int opts,
const char *file, int line);
#endif
void _mtx_unlock_spin(struct mtx *m, int opts, const char *file, int line);
-int _mtx_trylock(struct mtx *m, int opts, const char *file, int line);
void _mtx_lock_flags(struct mtx *m, int opts, const char *file, int line);
void _mtx_unlock_flags(struct mtx *m, int opts, const char *file, int line);
void _mtx_lock_spin_flags(struct mtx *m, int opts, const char *file,
@@ -107,12 +112,12 @@ void _mtx_unlock_spin_flags(struct mtx *m, int opts, const char *file,
#if defined(INVARIANTS) || defined(INVARIANT_SUPPORT)
void _mtx_assert(const struct mtx *m, int what, const char *file, int line);
#endif
-void _thread_lock_flags(struct thread *, int, const char *, int);
+void thread_lock_flags_(struct thread *, int, const char *, int);
#define thread_lock(tdp) \
- _thread_lock_flags((tdp), 0, __FILE__, __LINE__)
+ thread_lock_flags_((tdp), 0, __FILE__, __LINE__)
#define thread_lock_flags(tdp, opt) \
- _thread_lock_flags((tdp), (opt), __FILE__, __LINE__)
+ thread_lock_flags_((tdp), (opt), __FILE__, __LINE__)
#define thread_unlock(tdp) \
mtx_unlock_spin((tdp)->td_lock)
@@ -290,27 +295,48 @@ extern struct mtx_pool *mtxpool_sleep;
#error LOCK_DEBUG not defined, include <sys/lock.h> before <sys/mutex.h>
#endif
#if LOCK_DEBUG > 0 || defined(MUTEX_NOINLINE)
-#define mtx_lock_flags(m, opts) \
- _mtx_lock_flags((m), (opts), LOCK_FILE, LOCK_LINE)
-#define mtx_unlock_flags(m, opts) \
- _mtx_unlock_flags((m), (opts), LOCK_FILE, LOCK_LINE)
-#define mtx_lock_spin_flags(m, opts) \
- _mtx_lock_spin_flags((m), (opts), LOCK_FILE, LOCK_LINE)
-#define mtx_unlock_spin_flags(m, opts) \
- _mtx_unlock_spin_flags((m), (opts), LOCK_FILE, LOCK_LINE)
+#define mtx_lock_flags_(m, opts, file, line) \
+ _mtx_lock_flags((m), (opts), (file), (line))
+#define mtx_unlock_flags_(m, opts, file, line) \
+ _mtx_unlock_flags((m), (opts), (file), (line))
+#define mtx_lock_spin_flags_(m, opts, file, line) \
+ _mtx_lock_spin_flags((m), (opts), (file), (line))
+#define mtx_unlock_spin_flags_(m, opts, file, line) \
+ _mtx_unlock_spin_flags((m), (opts), (file), (line))
#else /* LOCK_DEBUG == 0 && !MUTEX_NOINLINE */
+#define mtx_lock_flags_(m, opts, file, line) \
+ __mtx_lock((m), curthread, (opts), (file), (line))
+#define mtx_unlock_flags_(m, opts, file, line) \
+ __mtx_unlock((m), curthread, (opts), (file), (line))
+#define mtx_lock_spin_flags_(m, opts, file, line) \
+ __mtx_lock_spin((m), curthread, (opts), (file), (line))
+#define mtx_unlock_spin_flags_(m, opts, file, line) \
+ __mtx_unlock_spin((m))
+#endif /* LOCK_DEBUG > 0 || MUTEX_NOINLINE */
+
+#ifdef INVARIANTS
+#define mtx_assert_(m, what, file, line) \
+ _mtx_assert((m), (what), (file), (line))
+
+#define GIANT_REQUIRED mtx_assert_(&Giant, MA_OWNED, __FILE__, __LINE__)
+
+#else /* INVARIANTS */
+#define mtx_assert_(m, what, file, line) (void)0
+#define GIANT_REQUIRED
+#endif /* INVARIANTS */
+
#define mtx_lock_flags(m, opts) \
- __mtx_lock((m), curthread, (opts), LOCK_FILE, LOCK_LINE)
+ mtx_lock_flags_((m), (opts), LOCK_FILE, LOCK_LINE)
#define mtx_unlock_flags(m, opts) \
- __mtx_unlock((m), curthread, (opts), LOCK_FILE, LOCK_LINE)
+ mtx_unlock_flags_((m), (opts), LOCK_FILE, LOCK_LINE)
#define mtx_lock_spin_flags(m, opts) \
- __mtx_lock_spin((m), curthread, (opts), LOCK_FILE, LOCK_LINE)
+ mtx_lock_spin_flags_((m), (opts), LOCK_FILE, LOCK_LINE)
#define mtx_unlock_spin_flags(m, opts) \
- __mtx_unlock_spin((m))
-#endif /* LOCK_DEBUG > 0 || MUTEX_NOINLINE */
-
+ mtx_unlock_spin_flags_((m), (opts), LOCK_FILE, LOCK_LINE)
#define mtx_trylock_flags(m, opts) \
- _mtx_trylock((m), (opts), LOCK_FILE, LOCK_LINE)
+ mtx_trylock_flags_((m), (opts), LOCK_FILE, LOCK_LINE)
+#define mtx_assert(m, what) \
+ mtx_assert_((m), (what), __FILE__, __LINE__)
#define mtx_sleep(chan, mtx, pri, wmesg, timo) \
_sleep((chan), &(mtx)->lock_object, (pri), (wmesg), (timo))
@@ -398,17 +424,6 @@ struct mtx_args {
#define MA_NOTRECURSED LA_NOTRECURSED
#endif
-#ifdef INVARIANTS
-#define mtx_assert(m, what) \
- _mtx_assert((m), (what), __FILE__, __LINE__)
-
-#define GIANT_REQUIRED mtx_assert(&Giant, MA_OWNED)
-
-#else /* INVARIANTS */
-#define mtx_assert(m, what) (void)0
-#define GIANT_REQUIRED
-#endif /* INVARIANTS */
-
/*
* Common lock type names.
*/
OpenPOWER on IntegriCloud