Allocate and free backing store for event mutices
authorBen Kaduk <kaduk@mit.edu>
Thu, 11 Mar 2010 05:13:12 +0000 (00:13 -0500)
committerDerrick Brashear <shadow@dementia.org>
Wed, 17 Mar 2010 00:54:13 +0000 (17:54 -0700)
Actually get memory for the event mutex.  With this and a locking
tweak, afsd actually starts (with memcache; the UFS cache still
has some locking issues).
Note that struct mtx is small enough that we may want to just
include it inline in afs_event_t and avoid having to do a separate
allocation/free step.  However, Derrick wants to merge the FBSD and
DARWIN versions of this file, so stick with the more compatible
version for now.
I find that without the memset(), mtx_init() will (sometimes?) complain
that the mutex is already initialized.  The glock should ensure
serialization here, though, so that we only allocate and initialize
one mutex per event.
Also remove an unnecessary cast while here.

Change-Id: Ib304f4301a478a82f0fb8c9ae3bfee98a2a28acd
Reviewed-on: http://gerrit.openafs.org/1560
Reviewed-by: Simon Wilkinson <sxw@inf.ed.ac.uk>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>

src/afs/FBSD/osi_sleep.c

index 8a5bb6c..b70d3c4 100644 (file)
@@ -138,7 +138,9 @@ afs_getevent(char *event)
        evp = evp->next;
     }
     if (!newp) {
-       newp = (afs_event_t *) osi_AllocSmallSpace(sizeof(afs_event_t));
+       newp = osi_AllocSmallSpace(sizeof(afs_event_t));
+       newp->lck = osi_AllocSmallSpace(sizeof(struct mtx));
+       memset(newp->lck, 0, sizeof(struct mtx));
        afs_evhashcnt++;
        newp->next = afs_evhasht[hashcode];
        afs_evhasht[hashcode] = newp;
@@ -247,6 +249,7 @@ shutdown_osisleep(void) {
             if (evp->refcount == 0) {
                 EVTLOCK_DESTROY(evp);
                 *pevpp = evp->next;
+                osi_FreeSmallSpace(evp->lck);
                 osi_FreeSmallSpace(evp);
                 afs_evhashcnt--;
             } else {