[WTF] Use m_suspendCount instead of m_suspended flag in Thread
[WebKit-https.git] / Source / JavaScriptCore / heap / DeferGC.h
index 02a1489..52b9ef0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#ifndef DeferGC_h
-#define DeferGC_h
+#pragma once
 
+#include "DisallowScope.h"
 #include "Heap.h"
-#include <wtf/Noncopyable.h>
 #include <wtf/ThreadSpecific.h>
 
 namespace JSC {
@@ -68,35 +67,41 @@ private:
     Heap& m_heap;
 };
 
-#ifndef NDEBUG
-class DisallowGC {
+class DisallowGC : public DisallowScope<DisallowGC> {
     WTF_MAKE_NONCOPYABLE(DisallowGC);
+    typedef DisallowScope<DisallowGC> Base;
 public:
-    DisallowGC()
-    {
-        WTF::threadSpecificSet(s_isGCDisallowedOnCurrentThread, reinterpret_cast<void*>(true));
-    }
+#ifdef NDEBUG
+
+    ALWAYS_INLINE DisallowGC(bool = false) { }
+    ALWAYS_INLINE static void initialize() { }
+
+#else // not NDEBUG
 
-    ~DisallowGC()
+    DisallowGC(bool enabled = true)
+        : Base(enabled)
+    { }
+
+    static void initialize()
     {
-        WTF::threadSpecificSet(s_isGCDisallowedOnCurrentThread, reinterpret_cast<void*>(false));
+        WTF::threadSpecificKeyCreate(&s_scopeReentryCount, 0);
     }
 
-    static bool isGCDisallowedOnCurrentThread()
+private:
+    static uintptr_t scopeReentryCount()
     {
-        return !!WTF::threadSpecificGet(s_isGCDisallowedOnCurrentThread);
+        return reinterpret_cast<uintptr_t>(WTF::threadSpecificGet(s_scopeReentryCount));
     }
-    static void initialize()
+    static void setScopeReentryCount(uintptr_t value)
     {
-        WTF::threadSpecificKeyCreate(&s_isGCDisallowedOnCurrentThread, 0);
+        WTF::threadSpecificSet(s_scopeReentryCount, reinterpret_cast<void*>(value));
     }
+    
+    JS_EXPORT_PRIVATE static WTF::ThreadSpecificKey s_scopeReentryCount;
 
-private:
-    JS_EXPORT_PRIVATE static WTF::ThreadSpecificKey s_isGCDisallowedOnCurrentThread;
-};
 #endif // NDEBUG
+    
+    friend class DisallowScope<DisallowGC>;
+};
 
 } // namespace JSC
-
-#endif // DeferGC_h
-