Remove use of std::mutex in gtest code.
authorDavid Neto <dneto@google.com>
Thu, 21 Apr 2016 19:46:11 +0000 (15:46 -0400)
committerDavid Neto <dneto@google.com>
Thu, 21 Apr 2016 19:56:33 +0000 (15:56 -0400)
Gtest runs in single-threaded mode.  So the GlslangInitializer
object in the test code doesn't have to do its own synchronization.

gtests/Initializer.h

index e8fa30d..3cd91a0 100644 (file)
@@ -35,8 +35,6 @@
 #ifndef GLSLANG_GTESTS_INITIALIZER_H
 #define GLSLANG_GTESTS_INITIALIZER_H
 
-#include <mutex>
-
 #include "glslang/Public/ShaderLang.h"
 
 namespace glslangtest {
@@ -63,55 +61,25 @@ public:
     // A token indicates that the glslang is reinitialized (if necessary) to the
     // required semantics. And that won't change until the token is destroyed.
     class InitializationToken {
-    public:
-        InitializationToken() : initializer(nullptr) {}
-        ~InitializationToken()
-        {
-            if (initializer) {
-                initializer->release();
-            }
-        }
-
-        InitializationToken(InitializationToken&& other)
-            : initializer(other.initializer)
-        {
-            other.initializer = nullptr;
-        }
-
-        InitializationToken(const InitializationToken&) = delete;
-
-    private:
-        InitializationToken(GlslangInitializer* initializer)
-            : initializer(initializer) {}
-
-        friend class GlslangInitializer;
-        GlslangInitializer* initializer;
     };
 
-    // Obtains exclusive access to the glslang state. The state remains
-    // exclusive until the Initialization Token has been destroyed.
     // Re-initializes glsl state iff the previous messages and the current
-    // messages are incompatible.
+    // messages are incompatible.  We assume external synchronization, i.e.
+    // there is at most one acquired token at any one time.
     InitializationToken acquire(EShMessages new_messages)
     {
-        stateLock.lock();
-
         if ((lastMessages ^ new_messages) &
             (EShMsgVulkanRules | EShMsgSpvRules)) {
             glslang::FinalizeProcess();
             glslang::InitializeProcess();
         }
         lastMessages = new_messages;
-        return InitializationToken(this);
+        return InitializationToken();
     }
 
 private:
-    void release() { stateLock.unlock(); }
-
-    friend class InitializationToken;
 
     EShMessages lastMessages;
-    std::mutex stateLock;
 };
 
 }  // namespace glslangtest