Changeset View
Changeset View
Standalone View
Standalone View
sys/sys/_eventhandler.h
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | |||||
#define EVENTHANDLER_DECLARE(name, type) \ | #define EVENTHANDLER_DECLARE(name, type) \ | ||||
struct eventhandler_entry_ ## name \ | struct eventhandler_entry_ ## name \ | ||||
{ \ | { \ | ||||
struct eventhandler_entry ee; \ | struct eventhandler_entry ee; \ | ||||
type eh_func; \ | type eh_func; \ | ||||
}; \ | }; \ | ||||
struct __hack | struct __hack | ||||
/* | |||||
* Headers to accomodate _rmlock.h | |||||
*/ | |||||
#include <sys/param.h> | |||||
#include <sys/_cpuset.h> | |||||
#include <sys/_lock.h> | |||||
#include <sys/_mutex.h> | |||||
#include <sys/_sx.h> | |||||
#include <sys/_rmlock.h> | |||||
typedef void eventhandler_cb(void *); | |||||
enum eventhandler_priority { | |||||
EVENTHANDLER_PRIORITY_INVALID, | |||||
EVENTHANDLER_PRIORITY_FIRST, | |||||
EVENTHANDLER_PRIORITY_ANY, | |||||
EVENTHANDLER_PRIORITY_LAST | |||||
}; | |||||
struct eventhandler_common { | |||||
eventhandler_cb **cb; | |||||
u_int count; | |||||
u_int size; | |||||
const char *ident; | |||||
enum eventhandler_priority *prio; | |||||
}; | |||||
struct eventhandler_preemptible { | |||||
struct rmlock lock; | |||||
struct eventhandler_common common; | |||||
}; | |||||
rpokala: Would it make more sense to have `common` be the first field, so the sleepable/preemptable… | |||||
Not Done Inline ActionsThat would make sense to me, too. erj: That would make sense to me, too. | |||||
Done Inline Actionsi don't see any point. if there is any need to pass them in, you can pass the common part already and whatever code needs the full thing can just unwrap it with container_of, in fact this is already done in this file mjg: i don't see any point. if there is any need to pass them in, you can pass the common part… | |||||
struct eventhandler_sleepable { | |||||
struct rmslock lock; | |||||
struct eventhandler_common common; | |||||
}; | |||||
#define EVENTHANDLER_PREEMPTIBLE_DECLARE(name) \ | |||||
extern struct eventhandler_preemptible eventhandler_preemptible_ ## name | |||||
#define EVENTHANDLER_PREEMPTIBLE_REGISTER(name, func, prio) \ | |||||
eventhandler_preemptible_register(&eventhandler_preemptible_ ## name, func, \ | |||||
EVENTHANDLER_PRIORITY_ ## prio) | |||||
#define EVENTHANDLER_PREEMPTIBLE_DEREGISTER(name, func) \ | |||||
eventhandler_preemptible_deregister(&eventhandler_preemptible_ ## name, func) | |||||
#define EVENTHANDLER_PREEMPTIBLE_INVOKE(name, arg) \ | |||||
eventhandler_preemptible_invoke(&eventhandler_preemptible_ ## name, arg) | |||||
#define EVENTHANDLER_PREEMPTIBLE_DEFINE(name) \ | |||||
struct eventhandler_preemptible eventhandler_preemptible_ ## name = { \ | |||||
.common.ident = __STRING(name), \ | |||||
}; \ | |||||
SYSINIT(_ehs_init_ ## name, SI_SUB_EVENTHANDLER, SI_ORDER_SECOND, \ | |||||
eventhandler_preemptible_init, &eventhandler_preemptible_ ## name); | |||||
#define EVENTHANDLER_SLEEPABLE_DECLARE(name) \ | |||||
extern struct eventhandler_sleepable eventhandler_sleepable_ ## name | |||||
#define EVENTHANDLER_SLEEPABLE_REGISTER(name, func, prio) \ | |||||
{ eventhandler_cb *__typecheck __unused = func; } \ | |||||
eventhandler_sleepable_register(&eventhandler_sleepable_ ## name, func, \ | |||||
EVENTHANDLER_PRIORITY_ ## prio) | |||||
#define EVENTHANDLER_SLEEPABLE_DEREGISTER(name, func) \ | |||||
eventhandler_sleepable_deregister(&eventhandler_sleepable_ ## name, func) | |||||
#define EVENTHANDLER_SLEEPABLE_INVOKE(name, arg) \ | |||||
eventhandler_sleepable_invoke(&eventhandler_sleepable_ ## name, arg) | |||||
#define EVENTHANDLER_SLEEPABLE_DEFINE(name) \ | |||||
struct eventhandler_sleepable eventhandler_sleepable_ ## name = { \ | |||||
.common.ident = __STRING(name), \ | |||||
}; \ | |||||
SYSINIT(_ehs_init_ ## name, SI_SUB_EVENTHANDLER, SI_ORDER_SECOND, \ | |||||
eventhandler_sleepable_init, &eventhandler_sleepable_ ## name); | |||||
#endif | #endif |
Would it make more sense to have common be the first field, so the sleepable/preemptable structures would have the same starting layout and could be cast to the common structure?