summaryrefslogtreecommitdiffstats
path: root/sys/sys/callout.h
diff options
context:
space:
mode:
authorattilio <attilio@FreeBSD.org>2007-11-20 00:37:45 +0000
committerattilio <attilio@FreeBSD.org>2007-11-20 00:37:45 +0000
commit6c4cd05be50053faf8e34d54658f463bbb1f9779 (patch)
tree3ece3b77fdcda6430089e6c864821e50d11b6cea /sys/sys/callout.h
parent0e8f2ba6baa43a0010f7d36e884aa4a40923558f (diff)
downloadFreeBSD-src-6c4cd05be50053faf8e34d54658f463bbb1f9779.zip
FreeBSD-src-6c4cd05be50053faf8e34d54658f463bbb1f9779.tar.gz
Add the function callout_init_rw() to callout facility in order to use
rwlocks in conjuction with callouts. The function does basically what callout_init_mtx() alredy does with the difference of using a rwlock as extra argument. CALLOUT_SHAREDLOCK flag can be used, now, in order to acquire the lock only in read mode when running the callout handler. It has no effects when used in conjuction with mtx. In order to implement this, underlying callout functions have been made completely lock type-unaware, so accordingly with this, sysctl debug.to_avg_mtxcalls is now changed in the generic debug.to_avg_lockcalls. Note: currently the allowed lock classes are mutexes and rwlocks because callout handlers run in softclock swi, so they cannot sleep and they cannot acquire sleepable locks like sx or lockmgr. Requested by: kmacy, pjd, rwatson Reviewed by: jhb
Diffstat (limited to 'sys/sys/callout.h')
-rw-r--r--sys/sys/callout.h13
1 files changed, 10 insertions, 3 deletions
diff --git a/sys/sys/callout.h b/sys/sys/callout.h
index a554562..d7adeaf 100644
--- a/sys/sys/callout.h
+++ b/sys/sys/callout.h
@@ -40,7 +40,7 @@
#include <sys/queue.h>
-struct mtx;
+struct lock_object;
SLIST_HEAD(callout_list, callout);
TAILQ_HEAD(callout_tailq, callout);
@@ -53,7 +53,7 @@ struct callout {
int c_time; /* ticks to the event */
void *c_arg; /* function argument */
void (*c_func)(void *); /* function to call */
- struct mtx *c_mtx; /* mutex to lock */
+ struct lock_object *c_lock; /* lock to handle */
int c_flags; /* state of this entry */
};
@@ -62,6 +62,7 @@ struct callout {
#define CALLOUT_PENDING 0x0004 /* callout is waiting for timeout */
#define CALLOUT_MPSAFE 0x0008 /* callout handler is mp safe */
#define CALLOUT_RETURNUNLOCKED 0x0010 /* handler returns with mtx unlocked */
+#define CALLOUT_SHAREDLOCK 0x0020 /* callout lock held in shared mode */
struct callout_handle {
struct callout *callout;
@@ -79,7 +80,13 @@ extern struct mtx callout_lock;
#define callout_deactivate(c) ((c)->c_flags &= ~CALLOUT_ACTIVE)
#define callout_drain(c) _callout_stop_safe(c, 1)
void callout_init(struct callout *, int);
-void callout_init_mtx(struct callout *, struct mtx *, int);
+void _callout_init_lock(struct callout *, struct lock_object *, int);
+#define callout_init_mtx(c, mtx, flags) \
+ _callout_init_lock((c), ((mtx) != NULL) ? &(mtx)->lock_object : \
+ NULL, (flags))
+#define callout_init_rw(c, rw, flags) \
+ _callout_init_lock((c), ((rw) != NULL) ? &(rw)->lock_object : \
+ NULL, (flags))
#define callout_pending(c) ((c)->c_flags & CALLOUT_PENDING)
int callout_reset(struct callout *, int, void (*)(void *), void *);
#define callout_stop(c) _callout_stop_safe(c, 0)
OpenPOWER on IntegriCloud