From d6a627d1e5e90c54c14bb0e915a32483645fa9d4 Mon Sep 17 00:00:00 2001 From: Marc Dionne Date: Wed, 19 Jan 2011 21:52:04 -0500 Subject: [PATCH] ubik: add lock initialization function Add a new lock initialization function and call it from the initialization sequence. Users of the locks can assume that they are already initialized. Change-Id: I8e86f460cb705c8de12bac9367358c93f1423591 Reviewed-on: http://gerrit.openafs.org/4141 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- src/ubik/lock.c | 28 +++++++++++----------------- src/ubik/ubik.c | 1 + src/ubik/ubik.p.h | 1 + 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/ubik/lock.c b/src/ubik/lock.c index d44b1162fe..a158d65f07 100644 --- a/src/ubik/lock.c +++ b/src/ubik/lock.c @@ -54,7 +54,15 @@ ((((lock)->excl_locked & WRITE_LOCK) || (lock)->readers_reading) ? 0 : 1) struct Lock rwlock; -int rwlockinit = 1; + +/*! + * \Initialize locks + */ +void +ulock_Init(void) +{ + Lock_Init(&rwlock); +} /*! * \brief Set a transaction lock. @@ -69,12 +77,6 @@ ulock_getLock(struct ubik_trans *atrans, int atype, int await) { struct ubik_dbase *dbase = atrans->dbase; - /* On first pass, initialize the lock */ - if (rwlockinit) { - Lock_Init(&rwlock); - rwlockinit = 0; - } - if ((atype != LOCKREAD) && (atype != LOCKWRITE)) return EINVAL; @@ -135,9 +137,6 @@ ulock_getLock(struct ubik_trans *atrans, int atype, int await) void ulock_relLock(struct ubik_trans *atrans) { - if (rwlockinit) - return; - if (atrans->locktype == LOCKWRITE && (atrans->flags & TRREADWRITE)) { ubik_print("Ubik: Internal Error: unlocking write lock with " "TRREADWRITE?\n"); @@ -167,11 +166,6 @@ ulock_relLock(struct ubik_trans *atrans) void ulock_Debug(struct ubik_debug *aparm) { - if (rwlockinit) { - aparm->anyReadLocks = 0; - aparm->anyWriteLocks = 0; - } else { - aparm->anyReadLocks = rwlock.readers_reading; - aparm->anyWriteLocks = ((rwlock.excl_locked == WRITE_LOCK) ? 1 : 0); - } + aparm->anyReadLocks = rwlock.readers_reading; + aparm->anyWriteLocks = ((rwlock.excl_locked == WRITE_LOCK) ? 1 : 0); } diff --git a/src/ubik/ubik.c b/src/ubik/ubik.c index a2d6fc0ca6..60aac9612b 100644 --- a/src/ubik/ubik.c +++ b/src/ubik/ubik.c @@ -424,6 +424,7 @@ ubik_ServerInitCommon(afs_uint32 myHost, short myPort, return code; udisk_Init(ubik_nBuffers); + ulock_Init(); ubik_callPortal = myPort; /* try to get an additional security object */ diff --git a/src/ubik/ubik.p.h b/src/ubik/ubik.p.h index eb24e9dbe5..3eafd72c94 100644 --- a/src/ubik/ubik.p.h +++ b/src/ubik/ubik.p.h @@ -437,6 +437,7 @@ extern int udisk_end(struct ubik_trans *atrans); /*\}*/ /*! \name lock.c */ +extern void ulock_Init(void); extern int ulock_getLock(struct ubik_trans *atrans, int atype, int await); extern void ulock_relLock(struct ubik_trans *atrans); extern void ulock_Debug(struct ubik_debug *aparm);