PERFORCE change 100707 for review
Paolo Pisati
piso at FreeBSD.org
Thu Jul 6 09:53:16 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=100707
Change 100707 by piso at piso_newluxor on 2006/07/06 09:52:41
Now we have a rwlock for the modules in kernel land (handler_rw)
and nothing in userland: to avoid races in userland the
lock will go into *_dll(), but for now we can live without
it cause libalias is used only in single threaded app.
Affected files ...
.. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_mod.c#11 edit
.. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_mod.h#11 edit
Differences ...
==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_mod.c#11 (text+ko) ====
@@ -60,92 +60,96 @@
#include <sys/types.h>
/* protocol and userland module handlers chains */
-struct chain handler_chain;
+struct chain handler_chain;
+#ifdef _KERNEL
+struct rwlock handler_rw;
+#endif
+
SLIST_HEAD(dll_chain, dll) dll_chain = SLIST_HEAD_INITIALIZER(foo);
#ifdef _KERNEL
-#define LIBALIAS_LOCK_INIT(_chain) \
- rw_init(&_chain->rw, "Libalias_rwlock")
-#define LIBALIAS_LOCK_DESTROY(_chain) rw_destroy(&_chain->rw)
-#define LIBALIAS_WLOCK_ASSERT(_chain) \
- rw_assert(&_chain->rw, RA_WLOCKED)
+#define LIBALIAS_LOCK_INIT() \
+ rw_init(&handler_rw, "Libalias_modules_rwlock")
+#define LIBALIAS_LOCK_DESTROY() rw_destroy(&handler_rw)
+#define LIBALIAS_WLOCK_ASSERT() \
+ rw_assert(&handler_rw, RA_WLOCKED)
static __inline void
-LIBALIAS_RLOCK(struct chain *chain)
+LIBALIAS_RLOCK(void)
{
- rw_rlock(&chain->rw);
+ rw_rlock(&handler_rw);
}
static __inline void
-LIBALIAS_RUNLOCK(struct chain *chain)
+LIBALIAS_RUNLOCK(void)
{
- rw_runlock(&chain->rw);
+ rw_runlock(&handler_rw);
}
static __inline void
-LIBALIAS_WLOCK(struct chain *chain)
+LIBALIAS_WLOCK(void)
{
- rw_wlock(&chain->rw);
+ rw_wlock(&handler_rw);
}
static __inline void
-LIBALIAS_WUNLOCK(struct chain *chain)
+LIBALIAS_WUNLOCK(void)
{
- rw_wunlock(&chain->rw);
+ rw_wunlock(&handler_rw);
}
static void
-_handler_chain_init(struct chain *chain) {
+_handler_chain_init(void) {
- if (!rw_initialized(&chain->rw))
- LIBALIAS_LOCK_INIT(chain);
+ if (!rw_initialized(&handler_rw))
+ LIBALIAS_LOCK_INIT();
}
static void
-_handler_chain_destroy(struct chain *chain) {
+_handler_chain_destroy(void) {
- if (rw_initialized(&chain->rw))
- LIBALIAS_LOCK_DESTROY(chain);
+ if (rw_initialized(&handler_rw))
+ LIBALIAS_LOCK_DESTROY();
}
#else
-#define LIBALIAS_LOCK_INIT(_chain) ;
-#define LIBALIAS_LOCK_DESTROY(_chain) ;
-#define LIBALIAS_WLOCK_ASSERT(_chain) ;
+#define LIBALIAS_LOCK_INIT() ;
+#define LIBALIAS_LOCK_DESTROY() ;
+#define LIBALIAS_WLOCK_ASSERT() ;
static __inline void
-LIBALIAS_RLOCK(struct chain *chain __unused)
+LIBALIAS_RLOCK(void)
{
;
}
static __inline void
-LIBALIAS_RUNLOCK(struct chain *chain __unused)
+LIBALIAS_RUNLOCK(void)
{
;
}
static __inline void
-LIBALIAS_WLOCK(struct chain *chain __unused)
+LIBALIAS_WLOCK(void)
{
;
}
static __inline void
-LIBALIAS_WUNLOCK(struct chain *chain __unused)
+LIBALIAS_WUNLOCK(void)
{
;
}
static void
-_handler_chain_init(struct chain *c __unused) {
+_handler_chain_init(void) {
;
}
static void
-_handler_chain_destroy(struct chain *c __unused) {
+_handler_chain_destroy(void) {
;
}
@@ -153,12 +157,12 @@
void
handler_chain_init(void) {
- _handler_chain_init(&handler_chain);
+ _handler_chain_init();
}
void
handler_chain_destroy(void) {
- _handler_chain_destroy(&handler_chain);
+ _handler_chain_destroy();
}
static int
@@ -166,7 +170,7 @@
struct proto_handler **b;
int i = 0;
- LIBALIAS_WLOCK_ASSERT(c);
+ LIBALIAS_WLOCK_ASSERT();
b = (struct proto_handler **)&c->chain;
p->next = NULL; /* i'm paranoid... */
for(; *b != NULL; b = &((*b)->next), i++) {
@@ -186,7 +190,7 @@
_detach_handler(struct chain *c, struct proto_handler *p) {
struct proto_handler **b;
- LIBALIAS_WLOCK_ASSERT(c);
+ LIBALIAS_WLOCK_ASSERT();
b = (struct proto_handler **)&c->chain;
for(; (*b != NULL) && (*b != p); b = &((*b)->next))
;
@@ -199,13 +203,13 @@
attach_handlers(struct proto_handler *_p) {
int i, res = NOK;
- LIBALIAS_WLOCK(&handler_chain);
+ LIBALIAS_WLOCK();
for (i=0; 1; i++) {
if (*((int *)&_p[i]) == EOH) break;
res = _attach_handler(&handler_chain, &_p[i]);
if (res != OK) break;
}
- LIBALIAS_WUNLOCK(&handler_chain);
+ LIBALIAS_WUNLOCK();
return (res);
}
@@ -213,13 +217,13 @@
detach_handlers(struct proto_handler *_p) {
int i, res = NOK;
- LIBALIAS_WLOCK(&handler_chain);
+ LIBALIAS_WLOCK();
for (i=0; 1; i++) {
if (*((int *)&_p[i]) == EOH) break;
res = _detach_handler(&handler_chain, &_p[i]);
if (res != OK) break;
}
- LIBALIAS_WUNLOCK(&handler_chain);
+ LIBALIAS_WUNLOCK();
return (res);
}
@@ -227,9 +231,9 @@
detach_handler(struct proto_handler *_p) {
int res = NOK;
- LIBALIAS_WLOCK(&handler_chain);
+ LIBALIAS_WLOCK();
res = _detach_handler(&handler_chain, _p);
- LIBALIAS_WUNLOCK(&handler_chain);
+ LIBALIAS_WUNLOCK();
return (res);
}
@@ -238,14 +242,14 @@
struct proto_handler *p;
int err;
- LIBALIAS_RLOCK(&handler_chain);
+ LIBALIAS_RLOCK();
for (p = handler_chain.chain, err = EHDNOF; p != NULL; p = p->next)
if ((p->dir & dir) && (p->proto & proto))
if (p->fingerprint(la, pip, ad) == OK) {
err = p->protohandler(la, pip, ad);
break;
}
- LIBALIAS_RUNLOCK(&handler_chain);
+ LIBALIAS_RUNLOCK();
return (err);
}
==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_mod.h#11 (text+ko) ====
@@ -32,10 +32,6 @@
#ifndef _ALIAS_MOD_H_
#define _ALIAS_MOD_H_
-#include <sys/param.h>
-#include <sys/lock.h>
-#include <sys/rwlock.h>
-
/* Protocol handlers struct & function. */
/* Packet flow direction. */
@@ -83,7 +79,6 @@
// XXX - convert it to use queue(3)
struct chain {
void *chain;
- struct rwlock rw;
};
/*
More information about the p4-projects
mailing list