From: VMware, Inc <> Date: Thu, 22 Dec 2011 00:17:18 +0000 (-0800) Subject: make FileIOAligned_PoolInit thread-safe X-Git-Tag: 2011.12.20-562307~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6feb467b94f8c09d91dc9554e50afad77fab343b;p=thirdparty%2Fopen-vm-tools.git make FileIOAligned_PoolInit thread-safe 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 --- diff --git a/open-vm-tools/lib/file/fileIOPosix.c b/open-vm-tools/lib/file/fileIOPosix.c index b01e8e901..0a74a94d6 100644 --- a/open-vm-tools/lib/file/fileIOPosix.c +++ b/open-vm-tools/lib/file/fileIOPosix.c @@ -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); }