PERFORCE change 100560 for review
Paolo Pisati
piso at FreeBSD.org
Tue Jul 4 13:56:59 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=100560
Change 100560 by piso at piso_newluxor on 2006/07/04 13:56:03
Use rwlock(9) instead of my own read-write lock.
Affected files ...
.. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_mod.c#8 edit
.. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_mod.h#7 edit
Differences ...
==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_mod.c#8 (text+ko) ====
@@ -28,6 +28,8 @@
#ifdef _KERNEL
#include <sys/libkern.h>
#include <sys/param.h>
+#include <sys/lock.h>
+#include <sys/rwlock.h>
#include <sys/proc.h>
#else
#include <stdio.h>
@@ -63,61 +65,47 @@
#ifdef _KERNEL
#define LIBALIAS_LOCK_INIT(_chain) \
- mtx_init(&(_chain)->mtx, "libalias list of proto-handlers", NULL, \
- MTX_DEF | MTX_RECURSE)
-#define LIBALIAS_LOCK_DESTROY(_chain) mtx_destroy(&(_chain)->mtx)
-#define LIBALIAS_WLOCK_ASSERT(_chain) do { \
- mtx_assert(&(_chain)->mtx, MA_OWNED); \
- NET_ASSERT_GIANT(); \
-} while (0)
+ 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)
static __inline void
LIBALIAS_RLOCK(struct chain *chain)
{
- mtx_lock(&chain->mtx);
- chain->busy_count++;
- mtx_unlock(&chain->mtx);
+ rw_rlock(&chain->rw);
}
static __inline void
LIBALIAS_RUNLOCK(struct chain *chain)
{
- mtx_lock(&chain->mtx);
- chain->busy_count--;
- if (chain->busy_count == 0 && chain->want_write)
- cv_signal(&chain->cv);
- mtx_unlock(&chain->mtx);
+ rw_runlock(&chain->rw);
}
static __inline void
LIBALIAS_WLOCK(struct chain *chain)
{
- mtx_lock(&chain->mtx);
- chain->want_write++;
- while (chain->busy_count > 0)
- cv_wait(&chain->cv, &chain->mtx);
+ rw_wlock(&chain->rw);
}
static __inline void
LIBALIAS_WUNLOCK(struct chain *chain)
{
- chain->want_write--;
- cv_signal(&chain->cv);
- mtx_unlock(&chain->mtx);
+ rw_wunlock(&chain->rw);
}
static void
-_handler_chain_init(struct chain *c) {
+_handler_chain_init(struct chain *chain) {
- if (!mtx_initialized(&c->mtx))
- LIBALIAS_LOCK_INIT(c);
+ if (!rw_initialized(&chain->rw))
+ LIBALIAS_LOCK_INIT(chain);
}
static void
-_handler_chain_destroy(struct chain *c) {
+_handler_chain_destroy(struct chain *chain) {
- if (mtx_initialized(&c->mtx))
- LIBALIAS_LOCK_DESTROY(c);
+ if (rw_initialized(&chain->rw))
+ LIBALIAS_LOCK_DESTROY(chain);
}
#else
==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_mod.h#7 (text+ko) ====
@@ -32,6 +32,10 @@
#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. */
@@ -76,13 +80,10 @@
};
#ifdef _KERNEL
-// XXX - convert it to use queue(3) and rwlock(9)
+// XXX - convert it to use queue(3)
struct chain {
void *chain;
- struct mtx mtx; /* Lock guarding list. */
- int busy_count; /* Busy count for rw locks. */
- int want_write;
- struct cv cv;
+ struct rwlock rw;
};
#else
// XXX - convert it to use queue(3)
More information about the p4-projects
mailing list