summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorarr <arr@FreeBSD.org>2002-04-02 16:05:43 +0000
committerarr <arr@FreeBSD.org>2002-04-02 16:05:43 +0000
commit6ae00dcc9fb5b7c3f2e1a9a8e1d46be9ef9c2568 (patch)
tree7db549b5279f56d4862f7911f8017c7f3767fd0d
parentabc96715734af1438114308215116e86454d062a (diff)
downloadFreeBSD-src-6ae00dcc9fb5b7c3f2e1a9a8e1d46be9ef9c2568.zip
FreeBSD-src-6ae00dcc9fb5b7c3f2e1a9a8e1d46be9ef9c2568.tar.gz
- Add MTX_SYSINIT and SX_SYSINIT as macro glue for allowing sx and mtx
locks to be able to setup a SYSINIT call. This helps in places where a lock is needed to protect some data, but the data is not truly associated with a subsystem that can properly initialize it's lock. The macros use the mtx_sysinit() and sx_sysinit() functions, respectively, as the handler argument to SYSINIT(). Reviewed by: alfred, jhb, smp@
-rw-r--r--sys/kern/kern_mutex.c11
-rw-r--r--sys/kern/kern_sx.c8
-rw-r--r--sys/kern/subr_turnstile.c11
-rw-r--r--sys/sys/mutex.h16
-rw-r--r--sys/sys/sx.h14
5 files changed, 60 insertions, 0 deletions
diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c
index a79398b..d5a1b09 100644
--- a/sys/kern/kern_mutex.c
+++ b/sys/kern/kern_mutex.c
@@ -782,6 +782,17 @@ mtx_validate(struct mtx *m)
#endif
/*
+ * General init routine used by the MTX_SYSINIT() macro.
+ */
+void
+mtx_sysinit(void *arg)
+{
+ struct mtx_args *margs = arg;
+
+ mtx_init(margs->ma_mtx, margs->ma_desc, margs->ma_opts);
+}
+
+/*
* Mutex initialization routine; initialize lock `m' of type contained in
* `opts' with options contained in `opts' and description `description.'
*/
diff --git a/sys/kern/kern_sx.c b/sys/kern/kern_sx.c
index dda9fe7..fb6647d 100644
--- a/sys/kern/kern_sx.c
+++ b/sys/kern/kern_sx.c
@@ -53,6 +53,14 @@ struct lock_class lock_class_sx = {
#endif
void
+sx_sysinit(void *arg)
+{
+ struct sx_args *sargs = arg;
+
+ sx_init(sargs->sa_sx, sargs->sa_desc);
+}
+
+void
sx_init(struct sx *sx, const char *description)
{
struct lock_object *lock;
diff --git a/sys/kern/subr_turnstile.c b/sys/kern/subr_turnstile.c
index a79398b..d5a1b09 100644
--- a/sys/kern/subr_turnstile.c
+++ b/sys/kern/subr_turnstile.c
@@ -782,6 +782,17 @@ mtx_validate(struct mtx *m)
#endif
/*
+ * General init routine used by the MTX_SYSINIT() macro.
+ */
+void
+mtx_sysinit(void *arg)
+{
+ struct mtx_args *margs = arg;
+
+ mtx_init(margs->ma_mtx, margs->ma_desc, margs->ma_opts);
+}
+
+/*
* Mutex initialization routine; initialize lock `m' of type contained in
* `opts' with options contained in `opts' and description `description.'
*/
diff --git a/sys/sys/mutex.h b/sys/sys/mutex.h
index e0bce13..5f0d0c0 100644
--- a/sys/sys/mutex.h
+++ b/sys/sys/mutex.h
@@ -97,6 +97,7 @@
* [See below for descriptions]
*
*/
+void mtx_sysinit(void *arg);
void mtx_init(struct mtx *m, const char *description, int opts);
void mtx_destroy(struct mtx *m);
void _mtx_lock_sleep(struct mtx *m, int opts, const char *file, int line);
@@ -326,6 +327,21 @@ do { \
return (_val); \
} while (0)
+struct mtx_args {
+ struct mtx *ma_mtx;
+ const char *ma_desc;
+ int ma_opts;
+};
+
+#define MTX_SYSINIT(name, mtx, desc, opts) \
+ static struct mtx_args name##_args = { \
+ mtx, \
+ desc, \
+ opts \
+ }; \
+ SYSINIT(name##_mtx_sysinit, SI_SUB_LOCK, SI_ORDER_MIDDLE, \
+ mtx_sysinit, &name##_args)
+
/*
* The INVARIANTS-enabled mtx_assert() functionality.
*
diff --git a/sys/sys/sx.h b/sys/sys/sx.h
index f07c8dd..37fa061 100644
--- a/sys/sys/sx.h
+++ b/sys/sys/sx.h
@@ -47,6 +47,7 @@ struct sx {
};
#ifdef _KERNEL
+void sx_sysinit(void *arg);
void sx_init(struct sx *sx, const char *description);
void sx_destroy(struct sx *sx);
void _sx_slock(struct sx *sx, const char *file, int line);
@@ -59,6 +60,19 @@ int _sx_try_upgrade(struct sx *sx, const char *file, int line);
void _sx_downgrade(struct sx *sx, const char *file, int line);
#ifdef INVARIANT_SUPPORT
void _sx_assert(struct sx *sx, int what, const char *file, int line);
+
+struct sx_args {
+ struct sx *sa_sx;
+ const char *sa_desc;
+};
+
+#define SX_SYSINIT(name, sxa, desc) \
+ static struct sx_args name##_args = { \
+ sxa, \
+ desc \
+ }; \
+ SYSINIT(name##_sx_sysinit, SI_SUB_LOCK, SI_ORDER_MIDDLE, \
+ sx_sysinit, &name##_args)
#endif
#define sx_slock(sx) _sx_slock((sx), LOCK_FILE, LOCK_LINE)
OpenPOWER on IntegriCloud