From: Oliver Kurth Date: Fri, 15 Sep 2017 18:23:28 +0000 (-0700) Subject: lib/lock: Make MXUser_CreateSingleton* an inline X-Git-Tag: stable-10.2.0~317 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c94d3ba624d5f3911977b028148357c178c68d8b;p=thirdparty%2Fopen-vm-tools.git lib/lock: Make MXUser_CreateSingleton* an inline This will speed up the common case nicely, protects type safety, and provides data encapsulation. --- diff --git a/open-vm-tools/lib/include/userlock.h b/open-vm-tools/lib/include/userlock.h index 039f94659..a85aa625e 100644 --- a/open-vm-tools/lib/include/userlock.h +++ b/open-vm-tools/lib/include/userlock.h @@ -57,9 +57,29 @@ void MXUser_ReleaseExclLock(MXUserExclLock *lock); void MXUser_DestroyExclLock(MXUserExclLock *lock); Bool MXUser_IsCurThreadHoldingExclLock(MXUserExclLock *lock); -MXUserExclLock *MXUser_CreateSingletonExclLock(Atomic_Ptr *lockStorage, - const char *name, - MX_Rank rank); +/* Use only when necessary */ +MXUserExclLock *MXUser_CreateSingletonExclLockInt(Atomic_Ptr *lockStorage, + const char *name, + MX_Rank rank); + +/* This is the public interface */ +static INLINE MXUserExclLock * +MXUser_CreateSingletonExclLock(Atomic_Ptr *lockStorage, + const char *name, + MX_Rank rank) +{ + MXUserExclLock *lock; + + ASSERT(lockStorage); + + lock = (MXUserExclLock *) Atomic_ReadPtr(lockStorage); + + if (UNLIKELY(lock == NULL)) { + lock = MXUser_CreateSingletonExclLockInt(lockStorage, name, rank); + } + + return lock; +} MXUserCondVar *MXUser_CreateCondVarExclLock(MXUserExclLock *lock); @@ -98,9 +118,29 @@ void MXUser_ReleaseRecLock(MXUserRecLock *lock); void MXUser_DestroyRecLock(MXUserRecLock *lock); Bool MXUser_IsCurThreadHoldingRecLock(MXUserRecLock *lock); -MXUserRecLock *MXUser_CreateSingletonRecLock(Atomic_Ptr *lockStorage, - const char *name, - MX_Rank rank); +/* Use only when necessary */ +MXUserRecLock *MXUser_CreateSingletonRecLockInt(Atomic_Ptr *lockStorage, + const char *name, + MX_Rank rank); + +/* This is the public interface */ +static INLINE MXUserRecLock * +MXUser_CreateSingletonRecLock(Atomic_Ptr *lockStorage, + const char *name, + MX_Rank rank) +{ + MXUserRecLock *lock; + + ASSERT(lockStorage); + + lock = (MXUserRecLock *) Atomic_ReadPtr(lockStorage); + + if (UNLIKELY(lock == NULL)) { + lock = MXUser_CreateSingletonRecLockInt(lockStorage, name, rank); + } + + return lock; +} void MXUser_DumpRecLock(MXUserRecLock *lock); @@ -152,9 +192,29 @@ void MXUser_DestroyRWLock(MXUserRWLock *lock); Bool MXUser_IsCurThreadHoldingRWLock(MXUserRWLock *lock, uint32 queryType); -MXUserRWLock *MXUser_CreateSingletonRWLock(Atomic_Ptr *lockStorage, - const char *name, - MX_Rank rank); +/* Use only when necessary */ +MXUserRWLock *MXUser_CreateSingletonRWLockInt(Atomic_Ptr *lockStorage, + const char *name, + MX_Rank rank); + +/* This is the public interface */ +static INLINE MXUserRWLock * +MXUser_CreateSingletonRWLock(Atomic_Ptr *lockStorage, + const char *name, + MX_Rank rank) +{ + MXUserRWLock *lock; + + ASSERT(lockStorage); + + lock = (MXUserRWLock *) Atomic_ReadPtr(lockStorage); + + if (UNLIKELY(lock == NULL)) { + lock = MXUser_CreateSingletonRWLockInt(lockStorage, name, rank); + } + + return lock; +} /* * Stateful auto-reset event diff --git a/open-vm-tools/lib/lock/ulExcl.c b/open-vm-tools/lib/lock/ulExcl.c index 8a7a3b109..a12778b6a 100644 --- a/open-vm-tools/lib/lock/ulExcl.c +++ b/open-vm-tools/lib/lock/ulExcl.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2009-2016 VMware, Inc. All rights reserved. + * Copyright (C) 2009-2017 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -638,7 +638,7 @@ MXUser_IsCurThreadHoldingExclLock(MXUserExclLock *lock) // IN: /* *----------------------------------------------------------------------------- * - * MXUser_CreateSingletonExclLock -- + * MXUser_CreateSingletonExclLockInt -- * * Ensures that the specified backing object (Atomic_Ptr) contains a * exclusive lock. This is useful for modules that need to protect @@ -655,9 +655,9 @@ MXUser_IsCurThreadHoldingExclLock(MXUserExclLock *lock) // IN: */ MXUserExclLock * -MXUser_CreateSingletonExclLock(Atomic_Ptr *lockStorage, // IN/OUT: - const char *name, // IN: - MX_Rank rank) // IN: +MXUser_CreateSingletonExclLockInt(Atomic_Ptr *lockStorage, // IN/OUT: + const char *name, // IN: + MX_Rank rank) // IN: { MXUserExclLock *lock; diff --git a/open-vm-tools/lib/lock/ulRW.c b/open-vm-tools/lib/lock/ulRW.c index d16782fde..fc801f44e 100644 --- a/open-vm-tools/lib/lock/ulRW.c +++ b/open-vm-tools/lib/lock/ulRW.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2009-2016 VMware, Inc. All rights reserved. + * Copyright (C) 2009-2017 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -865,7 +865,7 @@ MXUser_ReleaseRWLock(MXUserRWLock *lock) // IN/OUT: /* *----------------------------------------------------------------------------- * - * MXUser_CreateSingletonRWLock -- + * MXUser_CreateSingletonRWLockInt -- * * Ensures that the specified backing object (Atomic_Ptr) contains a * RW lock. This is useful for modules that need to protect something @@ -882,9 +882,9 @@ MXUser_ReleaseRWLock(MXUserRWLock *lock) // IN/OUT: */ MXUserRWLock * -MXUser_CreateSingletonRWLock(Atomic_Ptr *lockStorage, // IN/OUT: - const char *name, // IN: - MX_Rank rank) // IN: +MXUser_CreateSingletonRWLockInt(Atomic_Ptr *lockStorage, // IN/OUT: + const char *name, // IN: + MX_Rank rank) // IN: { MXUserRWLock *lock; diff --git a/open-vm-tools/lib/lock/ulRec.c b/open-vm-tools/lib/lock/ulRec.c index b05739469..e320946c3 100644 --- a/open-vm-tools/lib/lock/ulRec.c +++ b/open-vm-tools/lib/lock/ulRec.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2009-2016 VMware, Inc. All rights reserved. + * Copyright (C) 2009-2017 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -715,7 +715,7 @@ MXUser_IsCurThreadHoldingRecLock(MXUserRecLock *lock) // IN: /* *----------------------------------------------------------------------------- * - * MXUser_CreateSingletonRecLock -- + * MXUser_CreateSingletonRecLockInt -- * * Ensures that the specified backing object (Atomic_Ptr) contains a * recursive lock. This is useful for modules that need to protect @@ -732,9 +732,9 @@ MXUser_IsCurThreadHoldingRecLock(MXUserRecLock *lock) // IN: */ MXUserRecLock * -MXUser_CreateSingletonRecLock(Atomic_Ptr *lockStorage, // IN/OUT: - const char *name, // IN: - MX_Rank rank) // IN: +MXUser_CreateSingletonRecLockInt(Atomic_Ptr *lockStorage, // IN/OUT: + const char *name, // IN: + MX_Rank rank) // IN: { MXUserRecLock *lock;