Index: src/platform.h |
diff --git a/src/platform.h b/src/platform.h |
index 38e633a38081e155744d9e1942c9eee8fc73827f..50c62eb91b231207ebda63774e5cd18fa4fdb70d 100644 |
--- a/src/platform.h |
+++ b/src/platform.h |
@@ -79,6 +79,7 @@ int random(); |
#endif // WIN32 |
#include "atomicops.h" |
+#include "lazy-instance.h" |
#include "platform-tls.h" |
#include "utils.h" |
#include "v8globals.h" |
@@ -522,6 +523,24 @@ class Mutex { |
virtual bool TryLock() = 0; |
}; |
+struct CreateMutexTrait { |
+ static Mutex* Create() { |
+ return OS::CreateMutex(); |
+ } |
+}; |
+ |
+// POD Mutex initialized lazily (i.e. the first time Pointer() is called). |
+// Usage: |
+// static LazyMutex my_mutex = LAZY_MUTEX_INITIALIZER; |
+// |
+// void my_function() { |
+// ScopedLock my_lock(my_mutex.Pointer()); |
+// // Do something. |
+// } |
+// |
+typedef LazyDynamicInstance<Mutex, CreateMutexTrait>::type LazyMutex; |
+ |
+#define LAZY_MUTEX_INITIALIZER LAZY_DYNAMIC_INSTANCE_INITIALIZER |
// ---------------------------------------------------------------------------- |
// ScopedLock |
@@ -571,6 +590,30 @@ class Semaphore { |
virtual void Signal() = 0; |
}; |
+template <int InitialValue> |
+struct CreateSemaphoreTrait { |
+ static Semaphore* Create() { |
+ return OS::CreateSemaphore(InitialValue); |
+ } |
+}; |
+ |
+// POD Semaphore initialized lazily (i.e. the first time Pointer() is called). |
+// Usage: |
+// // The following semaphore starts at 0. |
+// static LazySemaphore<0>::type my_semaphore = LAZY_SEMAPHORE_INITIALIZER; |
+// |
+// void my_function() { |
+// // Do something with my_semaphore.Pointer(). |
+// } |
+// |
+template <int InitialValue> |
+struct LazySemaphore { |
+ typedef typename LazyDynamicInstance< |
+ Semaphore, CreateSemaphoreTrait<InitialValue> >::type type; |
+}; |
+ |
+#define LAZY_SEMAPHORE_INITIALIZER LAZY_DYNAMIC_INSTANCE_INITIALIZER |
+ |
// ---------------------------------------------------------------------------- |
// Socket |