From f099314535596f3d1119302d6921087c9bcd2946 Mon Sep 17 00:00:00 2001 From: Fredrik Holmqvist Date: Mon, 30 Jul 2012 17:21:18 +0200 Subject: [PATCH] Use a rw_lock instead of a mutex. This however doesn't seem to improve performance here. Need to investigate lock contention I think. --- .../compat/freebsd_network/compat/net/if_var.h | 16 ++++++++-------- src/libs/compat/freebsd_network/mutex.c | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/libs/compat/freebsd_network/compat/net/if_var.h b/src/libs/compat/freebsd_network/compat/net/if_var.h index ee915fa8fb..3fa502e705 100644 --- a/src/libs/compat/freebsd_network/compat/net/if_var.h +++ b/src/libs/compat/freebsd_network/compat/net/if_var.h @@ -610,14 +610,14 @@ __unused static void ifa_free(struct ifaddr *ifa) {} __unused static void ifa_init(struct ifaddr *ifa) {} __unused static void ifa_ref(struct ifaddr *ifa) {} -extern struct mtx ifnet_lock; -#define IFNET_LOCK_INIT() -#define IFNET_WLOCK() mtx_lock(&ifnet_lock) -#define IFNET_WUNLOCK() mtx_unlock(&ifnet_lock) -#define IFNET_RLOCK() IFNET_WLOCK() -#define IFNET_RLOCK_NOSLEEP() IFNET_WLOCK() -#define IFNET_RUNLOCK() IFNET_WUNLOCK() -#define IFNET_RUNLOCK_NOSLEEP() IFNET_WUNLOCK() +extern struct rw_lock ifnet_rwlock; +#define IFNET_LOCK_INIT() rw_lock_init(&ifnet_rwlock, "ifnet rwlock") +#define IFNET_WLOCK() rw_lock_write_lock(&ifnet_rwlock) +#define IFNET_WUNLOCK() rw_lock_write_unlock(&ifnet_rwlock) +#define IFNET_RLOCK() rw_lock_read_lock(&ifnet_rwlock) +#define IFNET_RLOCK_NOSLEEP() rw_lock_read_lock(&ifnet_rwlock) +#define IFNET_RUNLOCK() rw_lock_read_unlock(&ifnet_rwlock) +#define IFNET_RUNLOCK_NOSLEEP() rw_lock_read_unlock(&ifnet_rwlock) struct ifnet *ifnet_byindex(u_short idx); struct ifnet *ifnet_byindex_locked(u_short idx); diff --git a/src/libs/compat/freebsd_network/mutex.c b/src/libs/compat/freebsd_network/mutex.c index 82333ac1f2..3944e60b27 100644 --- a/src/libs/compat/freebsd_network/mutex.c +++ b/src/libs/compat/freebsd_network/mutex.c @@ -13,7 +13,7 @@ // these methods are bit unfriendly, a bit too much panic() around struct mtx Giant; -struct mtx ifnet_lock; +struct rw_lock ifnet_rwlock; struct mtx gIdStoreLock; @@ -48,7 +48,7 @@ status_t init_mutexes() { mtx_init(&Giant, "Banana Giant", NULL, MTX_DEF); - mtx_init(&ifnet_lock, "gDevices", NULL, MTX_DEF); + rw_lock_init(&ifnet_rwlock, "gDevices"); mtx_init(&gIdStoreLock, "Identity Store", NULL, MTX_DEF); return B_OK; @@ -59,6 +59,6 @@ void uninit_mutexes() { mtx_destroy(&Giant); - mtx_destroy(&ifnet_lock); + rw_lock_destroy(&ifnet_rwlock); mtx_destroy(&gIdStoreLock); }