Add a SmartScopedLock, and use it to simplify code.
[oota-llvm.git] / include / llvm / System / Mutex.h
index d8a18865f68054529fa05b80ddd9b8ea9f41f618..6f5614f701fe14dc63c00596a99cbf8ca2f1eebd 100644 (file)
@@ -115,6 +115,22 @@ namespace llvm
     
     /// Mutex - A standard, always enforced mutex.
     typedef SmartMutex<false> Mutex;
+    
+    template<bool mt_only>
+    class SmartScopedLock  {
+      SmartMutex<mt_only>* mtx;
+      
+    public:
+      SmartScopedLock(SmartMutex<mt_only>* m) : mtx(m) {
+        mtx->acquire();
+      }
+      
+      ~SmartScopedLock() {
+        mtx->release();
+      }
+    };
+    
+    typedef SmartScopedLock<false> ScopedLock;
   }
 }