]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
make FileIOAligned_PoolInit thread-safe
authorVMware, Inc <>
Thu, 22 Dec 2011 00:17:18 +0000 (16:17 -0800)
committerMarcelo Vanzin <mvanzin@vmware.com>
Thu, 22 Dec 2011 00:17:18 +0000 (16:17 -0800)
This function actually does have to be thread-safe because its caller, FileIO_OptionalSafeInitialize, is not (and doesn't have to be since it just performs idempotent operations). Most straightforward solution is to turn alignedPool.lock into a singleton.

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/lib/file/fileIOPosix.c

index b01e8e901ce981b17eaf47b2036376142da6bbdf..0a74a94d6401b5229738e332466aa6ed64c031bb 100644 (file)
@@ -193,6 +193,7 @@ typedef struct AlignedPool {
    unsigned        numBusy;
 } AlignedPool;
 
+static Atomic_Ptr alignedPoolLockStorage;
 static AlignedPool alignedPool;
 #endif
 
@@ -2518,8 +2519,7 @@ FileIO_SupportsPrealloc(const char *pathName,  // IN:
  *
  * FileIOAligned_PoolInit --
  *
- *      Initialize alignedPool.  Must be called before FileIOAligned_PoolMalloc.
- *      This is not thread-safe and must be protected from multiple entry.
+ *      Initialize alignedPool. Must be called before FileIOAligned_PoolMalloc.
  *
  * Result:
  *      None.
@@ -2533,8 +2533,10 @@ FileIO_SupportsPrealloc(const char *pathName,  // IN:
 void
 FileIOAligned_PoolInit(void)
 {
-   ASSERT(!alignedPool.lock);
-   alignedPool.lock = MXUser_CreateExclLock("alignedPoolLock", RANK_LEAF);
+   alignedPool.lock = MXUser_CreateSingletonExclLock(&alignedPoolLockStorage,
+                                                     "alignedPoolLock",
+                                                     RANK_LEAF);
+   ASSERT_NOT_IMPLEMENTED(alignedPool.lock);
 }