Date: Thursday, December 15, 2005 @ 18:18:51
  Author: gilles
    Path: /cvsroot/carob/carob/include

Modified: CriticalSection.hpp (1.4 -> 1.5)

Introduced LockScope class, a utility aimed to simplify critical section 
management inside a block (eg. a function)


---------------------+
 CriticalSection.hpp |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+)


Index: carob/include/CriticalSection.hpp
diff -u carob/include/CriticalSection.hpp:1.4 
carob/include/CriticalSection.hpp:1.5
--- carob/include/CriticalSection.hpp:1.4       Fri Dec  2 15:53:07 2005
+++ carob/include/CriticalSection.hpp   Thu Dec 15 18:18:51 2005
@@ -140,5 +140,37 @@
   void      operator=(CriticalSection &cs) {}
 };
 
+/**
+ * Utility class to lock a scope by entering the given critical section at
+ * creation time, and leaving it when destroyed
+ * Example usage:
+ * <code>
+ * void fct()
+ * {
+ *    LockScope ls(myCriticalSectionHandle);
+ *    //do what is critical
+ * } //no need to do anything else, the scope locker destructor is called
+ *   //automatically, releasing the lock
+ */
+class LockScope
+{
+public:
+  LockScope(CriticalSection* CSPtrPrm)
+  {
+    if (isVerboseEnabled())
+      logVerbose(L"LockScope", L"Entering critical section");
+    CSPtr = CSPtrPrm;
+    CSPtr->Enter();
+  }
+  ~LockScope()
+  {
+    if (isVerboseEnabled())
+      logVerbose(L"LockScope", L"Leaving critical section");
+    CSPtr->Leave();
+  }
+private:
+  CriticalSection *CSPtr;
+};
+
 } //namespace CarobNS
 #endif //_CRITICALSECTION_H_

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to