Windows: Interlocked ops for cell and scache allocation
authorJeffrey Altman <jaltman@your-file-system.com>
Wed, 31 Oct 2012 13:50:34 +0000 (09:50 -0400)
committerJeffrey Altman <jaltman@your-file-system.com>
Wed, 31 Oct 2012 22:16:49 +0000 (15:16 -0700)
Replace foo++ with InterlockedIncrement for cm_data cell and scache
counters which are used for allocating objects.

Change-Id: I09d2a536ef559d6d5873a3fdead4c8580bc93a0c
Reviewed-on: http://gerrit.openafs.org/8344
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Tested-by: Jeffrey Altman <jaltman@your-file-system.com>

src/WINNT/afsd/cm_cell.c
src/WINNT/afsd/cm_scache.c

index 7fb120c..f9c3ed4 100644 (file)
@@ -272,7 +272,7 @@ cm_cell_t *cm_GetCell_Gen(char *namep, char *newnamep, afs_uint32 flags)
             /* don't increment currentCells until we know that we
              * are going to keep this entry
              */
-            cp = &cm_data.cellBaseAddress[cm_data.currentCells];
+            cp = &cm_data.cellBaseAddress[InterlockedIncrement(&cm_data.currentCells) - 1];
             memset(cp, 0, sizeof(cm_cell_t));
             cp->magic = CM_CELL_MAGIC;
 
index dbfe277..44e6147 100644 (file)
@@ -390,7 +390,7 @@ cm_GetNewSCache(afs_uint32 locked)
     /* if we get here, we should allocate a new scache entry.  We either are below
      * quota or we have a leak and need to allocate a new one to avoid panicing.
      */
-    scp = cm_data.scacheBaseAddress + cm_data.currentSCaches;
+    scp = cm_data.scacheBaseAddress + InterlockedIncrement(&cm_data.currentSCaches) - 1;
     osi_assertx(scp >= cm_data.scacheBaseAddress && scp < (cm_scache_t *)cm_data.scacheHashTablep,
                 "invalid cm_scache_t address");
     memset(scp, 0, sizeof(cm_scache_t));
@@ -409,7 +409,6 @@ cm_GetNewSCache(afs_uint32 locked)
 
     /* and put it in the LRU queue */
     osi_QAddH((osi_queue_t **) &cm_data.scacheLRUFirstp, (osi_queue_t **)&cm_data.scacheLRULastp, &scp->q);
-    cm_data.currentSCaches++;
     cm_dnlcPurgedp(scp); /* make doubly sure that this is not in dnlc */
     cm_dnlcPurgevp(scp);
     scp->allNextp = cm_data.allSCachesp;