Remove atomicIncrement/atomicDecrement
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 25 Jan 2014 21:16:42 +0000 (21:16 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 25 Jan 2014 21:16:42 +0000 (21:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=127625

Reviewed by Andreas Kling.

Replace atomicIncrement/atomicDecrement with std::atomic.

Source/JavaScriptCore:

* bytecode/Watchpoint.h:
* ftl/FTLLowerDFGToLLVM.cpp:
(JSC::FTL::LowerDFGToLLVM::lower):
* profiler/ProfilerDatabase.cpp:
(JSC::Profiler::Database::Database):
(JSC::Profiler::Database::addDatabaseToAtExit):

Source/WebCore:

* Modules/webaudio/AudioContext.cpp:
(WebCore::AudioContext::incrementActiveSourceCount):
(WebCore::AudioContext::decrementActiveSourceCount):
* Modules/webaudio/AudioContext.h:
* Modules/webaudio/AudioNode.cpp:
(WebCore::AudioNode::~AudioNode):
(WebCore::AudioNode::ref):
(WebCore::AudioNode::finishDeref):
* Modules/webaudio/AudioNode.h:
* Modules/webdatabase/OriginLock.h:

Source/WebKit2:

* Platform/IPC/Connection.cpp:
(IPC::Connection::createSyncMessageEncoder):
* Shared/mac/SecItemShim.cpp:
(WebKit::generateSecItemRequestID):
* UIProcess/StatisticsRequest.cpp:
(WebKit::StatisticsRequest::addOutstandingRequest):

Source/WTF:

* wtf/Atomics.h:
* wtf/RefCountedLeakCounter.cpp:
(WTF::RefCountedLeakCounter::~RefCountedLeakCounter):
(WTF::RefCountedLeakCounter::increment):
(WTF::RefCountedLeakCounter::decrement):
* wtf/RefCountedLeakCounter.h:
* wtf/ThreadSafeRefCounted.h:
(WTF::ThreadSafeRefCountedBase::ref):
(WTF::ThreadSafeRefCountedBase::refCount):
(WTF::ThreadSafeRefCountedBase::derefBase):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@162777 268f45cc-cd09-0410-ab3c-d52691b4dbfc

19 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/bytecode/Watchpoint.h
Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp
Source/JavaScriptCore/profiler/ProfilerDatabase.cpp
Source/WTF/ChangeLog
Source/WTF/wtf/Atomics.h
Source/WTF/wtf/RefCountedLeakCounter.cpp
Source/WTF/wtf/RefCountedLeakCounter.h
Source/WTF/wtf/ThreadSafeRefCounted.h
Source/WebCore/ChangeLog
Source/WebCore/Modules/webaudio/AudioContext.cpp
Source/WebCore/Modules/webaudio/AudioContext.h
Source/WebCore/Modules/webaudio/AudioNode.cpp
Source/WebCore/Modules/webaudio/AudioNode.h
Source/WebCore/Modules/webdatabase/OriginLock.h
Source/WebKit2/ChangeLog
Source/WebKit2/Platform/IPC/Connection.cpp
Source/WebKit2/Shared/mac/SecItemShim.cpp
Source/WebKit2/UIProcess/StatisticsRequest.cpp

index b3e805d..7afd468 100644 (file)
@@ -1,3 +1,19 @@
+2014-01-25  Anders Carlsson  <andersca@apple.com>
+
+        Remove atomicIncrement/atomicDecrement
+        https://bugs.webkit.org/show_bug.cgi?id=127625
+
+        Reviewed by Andreas Kling.
+
+        Replace atomicIncrement/atomicDecrement with std::atomic.
+
+        * bytecode/Watchpoint.h:
+        * ftl/FTLLowerDFGToLLVM.cpp:
+        (JSC::FTL::LowerDFGToLLVM::lower):
+        * profiler/ProfilerDatabase.cpp:
+        (JSC::Profiler::Database::Database):
+        (JSC::Profiler::Database::addDatabaseToAtExit):
+
 2014-01-24  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: Move InspectorRuntimeAgent into JavaScriptCore
index 07b1b01..8790f4e 100644 (file)
@@ -26,6 +26,7 @@
 #ifndef Watchpoint_h
 #define Watchpoint_h
 
+#include <wtf/Atomics.h>
 #include <wtf/SentinelLinkedList.h>
 #include <wtf/ThreadSafeRefCounted.h>
 
index 09c7e64..be2a40c 100644 (file)
 #include "OperandsInlines.h"
 #include "Operations.h"
 #include "VirtualRegister.h"
-
+#include <atomic>
 #include <wtf/ProcessID.h>
 
 namespace JSC { namespace FTL {
 
 using namespace DFG;
 
-static int compileCounter;
+static std::atomic<int> compileCounter;
 
 // Using this instead of typeCheck() helps to reduce the load on LLVM, by creating
 // significantly less dead code.
@@ -81,7 +81,7 @@ public:
         CString name;
         if (verboseCompilationEnabled()) {
             name = toCString(
-                "jsBody_", atomicIncrement(&compileCounter), "_", codeBlock()->inferredName(),
+                "jsBody_", ++compileCounter, "_", codeBlock()->inferredName(),
                 "_", codeBlock()->hash());
         } else
             name = "jsBody";
index 4c5e055..f83652d 100644 (file)
 
 namespace JSC { namespace Profiler {
 
-#if COMPILER(MINGW) || COMPILER(MSVC7_OR_LOWER) || OS(WINCE)
-static int databaseCounter;
-#else
-static volatile int databaseCounter;
-#endif
+static std::atomic<int> databaseCounter;
+
 static SpinLock registrationLock = SPINLOCK_INITIALIZER;
-static int didRegisterAtExit;
+static std::atomic<int> didRegisterAtExit;
 static Database* firstDatabase;
 
 Database::Database(VM& vm)
-    : m_databaseID(atomicIncrement(&databaseCounter))
+    : m_databaseID(++databaseCounter)
     , m_vm(vm)
     , m_shouldSaveAtExit(false)
     , m_nextRegisteredDatabase(0)
@@ -138,7 +135,7 @@ void Database::registerToSaveAtExit(const char* filename)
 
 void Database::addDatabaseToAtExit()
 {
-    if (atomicIncrement(&didRegisterAtExit) == 1)
+    if (++didRegisterAtExit == 1)
         atexit(atExitCallback);
     
     TCMalloc_SpinLockHolder holder(&registrationLock);
index 27a8104..ecf0de4 100644 (file)
@@ -1,5 +1,25 @@
 2014-01-25  Anders Carlsson  <andersca@apple.com>
 
+        Remove atomicIncrement/atomicDecrement
+        https://bugs.webkit.org/show_bug.cgi?id=127625
+
+        Reviewed by Andreas Kling.
+
+        Replace atomicIncrement/atomicDecrement with std::atomic.
+
+        * wtf/Atomics.h:
+        * wtf/RefCountedLeakCounter.cpp:
+        (WTF::RefCountedLeakCounter::~RefCountedLeakCounter):
+        (WTF::RefCountedLeakCounter::increment):
+        (WTF::RefCountedLeakCounter::decrement):
+        * wtf/RefCountedLeakCounter.h:
+        * wtf/ThreadSafeRefCounted.h:
+        (WTF::ThreadSafeRefCountedBase::ref):
+        (WTF::ThreadSafeRefCountedBase::refCount):
+        (WTF::ThreadSafeRefCountedBase::derefBase):
+
+2014-01-25  Anders Carlsson  <andersca@apple.com>
+
         Modernize HashTable threading code
         https://bugs.webkit.org/show_bug.cgi?id=127621
 
index 82960f9..3d18e3e 100644 (file)
@@ -73,35 +73,6 @@ extern "C" void _ReadWriteBarrier(void);
 namespace WTF {
 
 #if OS(WINDOWS)
-
-#if OS(WINCE)
-inline int atomicIncrement(int* addend) { return InterlockedIncrement(reinterpret_cast<long*>(addend)); }
-inline int atomicDecrement(int* addend) { return InterlockedDecrement(reinterpret_cast<long*>(addend)); }
-#elif COMPILER(MINGW)
-inline int atomicIncrement(int* addend) { return InterlockedIncrement(reinterpret_cast<long*>(addend)); }
-inline int atomicDecrement(int* addend) { return InterlockedDecrement(reinterpret_cast<long*>(addend)); }
-
-inline int64_t atomicIncrement(int64_t* addend) { return InterlockedIncrement64(reinterpret_cast<long long*>(addend)); }
-inline int64_t atomicDecrement(int64_t* addend) { return InterlockedDecrement64(reinterpret_cast<long long*>(addend)); }
-#else
-inline int atomicIncrement(int volatile* addend) { return InterlockedIncrement(reinterpret_cast<long volatile*>(addend)); }
-inline int atomicDecrement(int volatile* addend) { return InterlockedDecrement(reinterpret_cast<long volatile*>(addend)); }
-
-inline int64_t atomicIncrement(int64_t volatile* addend) { return InterlockedIncrement64(reinterpret_cast<long long volatile*>(addend)); }
-inline int64_t atomicDecrement(int64_t volatile* addend) { return InterlockedDecrement64(reinterpret_cast<long long volatile*>(addend)); }
-#endif
-
-#elif COMPILER(GCC)
-
-inline int atomicIncrement(int volatile* addend) { return __sync_add_and_fetch(addend, 1); }
-inline int atomicDecrement(int volatile* addend) { return __sync_sub_and_fetch(addend, 1); }
-
-inline int64_t atomicIncrement(int64_t volatile* addend) { return __sync_add_and_fetch(addend, 1); }
-inline int64_t atomicDecrement(int64_t volatile* addend) { return __sync_sub_and_fetch(addend, 1); }
-
-#endif
-
-#if OS(WINDOWS)
 inline bool weakCompareAndSwap(volatile unsigned* location, unsigned expected, unsigned newValue)
 {
 #if OS(WINCE)
@@ -343,7 +314,4 @@ inline bool weakCompareAndSwap(uint8_t* location, uint8_t expected, uint8_t newV
 
 } // namespace WTF
 
-using WTF::atomicDecrement;
-using WTF::atomicIncrement;
-
 #endif // Atomics_h
index 7283135..721fa9f 100644 (file)
@@ -68,7 +68,7 @@ RefCountedLeakCounter::~RefCountedLeakCounter()
     static bool loggedSuppressionReason;
     if (m_count) {
         if (!leakMessageSuppressionReasons || leakMessageSuppressionReasons->isEmpty())
-            LOG(RefCountedLeaks, "LEAK: %u %s", m_count, m_description);
+            LOG(RefCountedLeaks, "LEAK: %u %s", m_count.load(), m_description);
         else if (!loggedSuppressionReason) {
             // This logs only one reason. Later we could change it so we log all the reasons.
             LOG(RefCountedLeaks, "No leak checking done: %s", leakMessageSuppressionReasons->begin()->key);
@@ -79,12 +79,12 @@ RefCountedLeakCounter::~RefCountedLeakCounter()
 
 void RefCountedLeakCounter::increment()
 {
-    atomicIncrement(&m_count);
+    ++m_count;
 }
 
 void RefCountedLeakCounter::decrement()
 {
-    atomicDecrement(&m_count);
+    --m_count;
 }
 
 #endif
index 48edd05..303f78c 100644 (file)
  
 #ifndef RefCountedLeakCounter_h
 #define RefCountedLeakCounter_h
+
+#include <atomic>
 #include <wtf/Assertions.h>
-#include <wtf/Threading.h>
 
 namespace WTF {
     
-    struct RefCountedLeakCounter {
-        WTF_EXPORT_PRIVATE static void suppressMessages(const char*);
-        WTF_EXPORT_PRIVATE static void cancelMessageSuppression(const char*);
-        
-        WTF_EXPORT_PRIVATE explicit RefCountedLeakCounter(const char* description);
-        WTF_EXPORT_PRIVATE ~RefCountedLeakCounter();
+struct RefCountedLeakCounter {
+    WTF_EXPORT_PRIVATE static void suppressMessages(const char*);
+    WTF_EXPORT_PRIVATE static void cancelMessageSuppression(const char*);
+    
+    WTF_EXPORT_PRIVATE explicit RefCountedLeakCounter(const char* description);
+    WTF_EXPORT_PRIVATE ~RefCountedLeakCounter();
 
-        WTF_EXPORT_PRIVATE void increment();
-        WTF_EXPORT_PRIVATE void decrement();
+    WTF_EXPORT_PRIVATE void increment();
+    WTF_EXPORT_PRIVATE void decrement();
 
 #ifndef NDEBUG
-    private:
-#if COMPILER(MINGW) || OS(WINCE)
-        int m_count;
-#else
-        volatile int m_count;
-#endif
-        const char* m_description;
+private:
+    std::atomic<int> m_count;
+    const char* m_description;
 #endif
-    };
+};
 
 }  // namespace WTF
 
index 22ff99e..de87785 100644 (file)
 #ifndef ThreadSafeRefCounted_h
 #define ThreadSafeRefCounted_h
 
-#include <wtf/Platform.h>
-
-#include <wtf/Atomics.h>
+#include <atomic>
 #include <wtf/DynamicAnnotations.h>
-#include <wtf/ThreadingPrimitives.h>
+#include <wtf/Noncopyable.h>
 
 namespace WTF {
 
@@ -78,7 +76,7 @@ public:
 
     void ref()
     {
-        atomicIncrement(&m_refCount);
+        ++m_refCount;
     }
 
     bool hasOneRef()
@@ -88,7 +86,7 @@ public:
 
     int refCount() const
     {
-        return static_cast<int const volatile&>(m_refCount);
+        return m_refCount;
     }
 
 protected:
@@ -96,7 +94,7 @@ protected:
     bool derefBase()
     {
         WTF_ANNOTATE_HAPPENS_BEFORE(&m_refCount);
-        if (atomicDecrement(&m_refCount) <= 0) {
+        if (--m_refCount <= 0) {
             WTF_ANNOTATE_HAPPENS_AFTER(&m_refCount);
             return true;
         }
@@ -105,7 +103,7 @@ protected:
     }
 
 private:
-    int m_refCount;
+    std::atomic<int> m_refCount;
 };
 
 template<class T> class ThreadSafeRefCounted : public ThreadSafeRefCountedBase {
index d114d48..b398f13 100644 (file)
@@ -1,3 +1,23 @@
+2014-01-25  Anders Carlsson  <andersca@apple.com>
+
+        Remove atomicIncrement/atomicDecrement
+        https://bugs.webkit.org/show_bug.cgi?id=127625
+
+        Reviewed by Andreas Kling.
+
+        Replace atomicIncrement/atomicDecrement with std::atomic.
+
+        * Modules/webaudio/AudioContext.cpp:
+        (WebCore::AudioContext::incrementActiveSourceCount):
+        (WebCore::AudioContext::decrementActiveSourceCount):
+        * Modules/webaudio/AudioContext.h:
+        * Modules/webaudio/AudioNode.cpp:
+        (WebCore::AudioNode::~AudioNode):
+        (WebCore::AudioNode::ref):
+        (WebCore::AudioNode::finishDeref):
+        * Modules/webaudio/AudioNode.h:
+        * Modules/webdatabase/OriginLock.h:
+
 2014-01-25  Alex Christensen  <achristensen@webkit.org>
 
         Unreviewed build fix for WinCairo.
index 76fd4f1..4854ff0 100644 (file)
@@ -1001,12 +1001,12 @@ void AudioContext::fireCompletionEvent()
 
 void AudioContext::incrementActiveSourceCount()
 {
-    atomicIncrement(&m_activeSourceCount);
+    ++m_activeSourceCount;
 }
 
 void AudioContext::decrementActiveSourceCount()
 {
-    atomicDecrement(&m_activeSourceCount);
+    --m_activeSourceCount;
 }
 
 } // namespace WebCore
index ee0e0df..1e965d9 100644 (file)
@@ -32,6 +32,7 @@
 #include "EventListener.h"
 #include "EventTarget.h"
 #include "MediaCanStartListener.h"
+#include <atomic>
 #include <wtf/HashSet.h>
 #include <wtf/MainThread.h>
 #include <wtf/PassRefPtr.h>
@@ -361,7 +362,7 @@ private:
     enum { MaxNumberOfChannels = 32 };
 
     // Number of AudioBufferSourceNodes that are active (playing).
-    int m_activeSourceCount;
+    std::atomic<int> m_activeSourceCount;
 
     BehaviorRestrictions m_restrictions;
 };
index 305eda5..514ec7a 100644 (file)
@@ -69,7 +69,7 @@ AudioNode::~AudioNode()
 {
 #if DEBUG_AUDIONODE_REFERENCES
     --s_nodeCount[nodeType()];
-    fprintf(stderr, "%p: %d: AudioNode::~AudioNode() %d %d\n", this, nodeType(), m_normalRefCount, m_connectionRefCount);
+    fprintf(stderr, "%p: %d: AudioNode::~AudioNode() %d %d\n", this, nodeType(), m_normalRefCount.load(), m_connectionRefCount);
 #endif
 }
 
@@ -411,10 +411,10 @@ void AudioNode::ref(RefType refType)
 {
     switch (refType) {
     case RefTypeNormal:
-        atomicIncrement(&m_normalRefCount);
+        ++m_normalRefCount;
         break;
     case RefTypeConnection:
-        atomicIncrement(&m_connectionRefCount);
+        ++m_connectionRefCount;
         break;
     default:
         ASSERT_NOT_REACHED();
@@ -473,11 +473,11 @@ void AudioNode::finishDeref(RefType refType)
     switch (refType) {
     case RefTypeNormal:
         ASSERT(m_normalRefCount > 0);
-        atomicDecrement(&m_normalRefCount);
+        --m_normalRefCount;
         break;
     case RefTypeConnection:
         ASSERT(m_connectionRefCount > 0);
-        atomicDecrement(&m_connectionRefCount);
+        --m_connectionRefCount;
         break;
     default:
         ASSERT_NOT_REACHED();
index c930493..1536056 100644 (file)
@@ -207,8 +207,8 @@ private:
     double m_lastNonSilentTime;
 
     // Ref-counting
-    volatile int m_normalRefCount;
-    volatile int m_connectionRefCount;
+    std::atomic<int> m_normalRefCount;
+    std::atomic<int> m_connectionRefCount;
     
     bool m_isMarkedForDeletion;
     bool m_isDisabled;
index 543eb06..791a56a 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "FileSystem.h"
 #include <wtf/ThreadSafeRefCounted.h>
+#include <wtf/ThreadingPrimitives.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
index d1db3bc..8d36d6a 100644 (file)
@@ -1,5 +1,21 @@
 2014-01-25  Anders Carlsson  <andersca@apple.com>
 
+        Remove atomicIncrement/atomicDecrement
+        https://bugs.webkit.org/show_bug.cgi?id=127625
+
+        Reviewed by Andreas Kling.
+
+        Replace atomicIncrement/atomicDecrement with std::atomic.
+
+        * Platform/IPC/Connection.cpp:
+        (IPC::Connection::createSyncMessageEncoder):
+        * Shared/mac/SecItemShim.cpp:
+        (WebKit::generateSecItemRequestID):
+        * UIProcess/StatisticsRequest.cpp:
+        (WebKit::StatisticsRequest::addOutstandingRequest):
+
+2014-01-25  Anders Carlsson  <andersca@apple.com>
+
         Modernize HashTable threading code
         https://bugs.webkit.org/show_bug.cgi?id=127621
 
index 46d138c..615e707 100644 (file)
@@ -344,7 +344,6 @@ std::unique_ptr<MessageEncoder> Connection::createSyncMessageEncoder(StringRefer
     encoder->setIsSyncMessage(true);
 
     // Encode the sync request ID.
-    COMPILE_ASSERT(sizeof(m_syncRequestID) == sizeof(int64_t), CanUseAtomicIncrement);
     syncRequestID = ++m_syncRequestID;
     *encoder << syncRequestID;
 
index 3b88728..cda70a5 100644 (file)
@@ -36,6 +36,7 @@
 #include "SecItemShimMessages.h"
 #include "SecItemShimProxyMessages.h"
 #include <Security/Security.h>
+#include <atomic>
 #include <dlfcn.h>
 #include <mutex>
 
@@ -73,8 +74,8 @@ SecItemShim::SecItemShim()
 
 static uint64_t generateSecItemRequestID()
 {
-    static int64_t uniqueSecItemRequestID;
-    return atomicIncrement(&uniqueSecItemRequestID);
+    static std::atomic<int64_t> uniqueSecItemRequestID;
+    return ++uniqueSecItemRequestID;
 }
 
 static std::unique_ptr<SecItemResponseData> sendSecItemRequest(SecItemRequestData::Type requestType, CFDictionaryRef query, CFDictionaryRef attributesToMatch = 0)
index 9c5aad1..3223da5 100644 (file)
@@ -28,7 +28,6 @@
 
 #include "APIArray.h"
 #include "MutableDictionary.h"
-#include <wtf/Atomics.h>
 
 namespace WebKit {
 
@@ -45,9 +44,9 @@ StatisticsRequest::~StatisticsRequest()
 
 uint64_t StatisticsRequest::addOutstandingRequest()
 {
-    static int64_t uniqueRequestID;
+    static std::atomic<int64_t> uniqueRequestID;
 
-    uint64_t requestID = atomicIncrement(&uniqueRequestID);
+    uint64_t requestID = ++uniqueRequestID;
     m_outstandingRequests.add(requestID);
     return requestID;
 }