[WTF] Use m_suspendCount instead of m_suspended flag in Thread
[WebKit-https.git] / Source / JavaScriptCore / heap / DeferGC.h
index 8169518..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 {
 
@@ -67,7 +67,41 @@ private:
     Heap& m_heap;
 };
 
-} // namespace JSC
+class DisallowGC : public DisallowScope<DisallowGC> {
+    WTF_MAKE_NONCOPYABLE(DisallowGC);
+    typedef DisallowScope<DisallowGC> Base;
+public:
+#ifdef NDEBUG
+
+    ALWAYS_INLINE DisallowGC(bool = false) { }
+    ALWAYS_INLINE static void initialize() { }
+
+#else // not NDEBUG
+
+    DisallowGC(bool enabled = true)
+        : Base(enabled)
+    { }
+
+    static void initialize()
+    {
+        WTF::threadSpecificKeyCreate(&s_scopeReentryCount, 0);
+    }
+
+private:
+    static uintptr_t scopeReentryCount()
+    {
+        return reinterpret_cast<uintptr_t>(WTF::threadSpecificGet(s_scopeReentryCount));
+    }
+    static void setScopeReentryCount(uintptr_t value)
+    {
+        WTF::threadSpecificSet(s_scopeReentryCount, reinterpret_cast<void*>(value));
+    }
+    
+    JS_EXPORT_PRIVATE static WTF::ThreadSpecificKey s_scopeReentryCount;
 
-#endif // DeferGC_h
+#endif // NDEBUG
+    
+    friend class DisallowScope<DisallowGC>;
+};
 
+} // namespace JSC