]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
lib/lock: Make MXUser_CreateSingleton* an inline
authorOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:28 +0000 (11:23 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:28 +0000 (11:23 -0700)
This will speed up the common case nicely, protects type safety, and
provides data encapsulation.

open-vm-tools/lib/include/userlock.h
open-vm-tools/lib/lock/ulExcl.c
open-vm-tools/lib/lock/ulRW.c
open-vm-tools/lib/lock/ulRec.c

index 039f94659d567ec4fd7babfc8d370cf819c1983c..a85aa625e29c52a75e2ffa53fff943310d7386ba 100644 (file)
@@ -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
index 8a7a3b1097d4af08acc549c879f79f6bbdeba4c5..a12778b6a59025f31560cfc6ec7f2594d37565aa 100644 (file)
@@ -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;
 
index d16782fde239c234ed7949c1298aab6e305274eb..fc801f44e5c0d696be2f8275b9bc9bdb0734350c 100644 (file)
@@ -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;
 
index b057394699a35de039609417c31aa570fbed2fb5..e320946c3d791c4dcdbdef3f40c06af601203d39 100644 (file)
@@ -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;