From: VMware, Inc <> Date: Mon, 21 Nov 2011 22:46:37 +0000 (-0800) Subject: lib/lock: trivial code move X-Git-Tag: 2011.11.20-535097~90 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6ba5195ab397ce09d61154663edebdb93edae54b;p=thirdparty%2Fopen-vm-tools.git lib/lock: trivial code move Move a function - no forward reference. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/lock/ul.c b/open-vm-tools/lib/lock/ul.c index 1340480f5..0fb403295 100644 --- a/open-vm-tools/lib/lock/ul.c +++ b/open-vm-tools/lib/lock/ul.c @@ -48,6 +48,54 @@ typedef struct { static Atomic_Ptr hashTableMem; +/* + *----------------------------------------------------------------------------- + * + * MXUserInternalSingleton -- + * + * A "singleton" function for the MXUser internal recursive lock. + * + * Internal MXUser recursive locks have no statistics gathering or + * tracking abilities. They need to used with care and rarely. + * + * Results: + * NULL Failure + * !NULL A pointer to an initialized MXRecLock + * + * Side effects: + * Manifold. + * + *----------------------------------------------------------------------------- + */ + +MXRecLock * +MXUserInternalSingleton(Atomic_Ptr *storage) // IN: +{ + MXRecLock *lock = (MXRecLock *) Atomic_ReadPtr(storage); + + if (UNLIKELY(lock == NULL)) { + MXRecLock *newLock = Util_SafeMalloc(sizeof(MXRecLock)); + + if (MXRecLockInit(newLock)) { + lock = (MXRecLock *) Atomic_ReadIfEqualWritePtr(storage, NULL, + (void *) newLock); + + if (lock) { + MXRecLockDestroy(newLock); + free(newLock); + } else { + lock = Atomic_ReadPtr(storage); + } + } else { + free(newLock); + lock = Atomic_ReadPtr(storage); // maybe another thread succeeded + } + } + + return lock; +} + + /* *----------------------------------------------------------------------------- * @@ -418,54 +466,6 @@ MXUser_TryAcquireFailureControl(Bool (*func)(const char *name)) // IN: #endif -/* - *----------------------------------------------------------------------------- - * - * MXUserInternalSingleton -- - * - * A "singleton" function for the MXUser internal recursive lock. - * - * Internal MXUser recursive locks have no statistics gathering or - * tracking abilities. They need to used with care and rarely. - * - * Results: - * NULL Failure - * !NULL A pointer to an initialized MXRecLock - * - * Side effects: - * Manifold. - * - *----------------------------------------------------------------------------- - */ - -MXRecLock * -MXUserInternalSingleton(Atomic_Ptr *storage) // IN: -{ - MXRecLock *lock = (MXRecLock *) Atomic_ReadPtr(storage); - - if (UNLIKELY(lock == NULL)) { - MXRecLock *newLock = Util_SafeMalloc(sizeof(MXRecLock)); - - if (MXRecLockInit(newLock)) { - lock = (MXRecLock *) Atomic_ReadIfEqualWritePtr(storage, NULL, - (void *) newLock); - - if (lock) { - MXRecLockDestroy(newLock); - free(newLock); - } else { - lock = Atomic_ReadPtr(storage); - } - } else { - free(newLock); - lock = Atomic_ReadPtr(storage); // maybe another thread succeeded - } - } - - return lock; -} - - /* *----------------------------------------------------------------------------- *