Title: [115988] trunk/Source/WTF
Revision
115988
Author
[email protected]
Date
2012-05-03 10:18:11 -0700 (Thu, 03 May 2012)

Log Message

Mutex failure when HashTable is memory moved in debug build
https://bugs.webkit.org/show_bug.cgi?id=84970

Patch by Yong Li <[email protected]> on 2012-05-03
Reviewed by Rob Buis.

1. Replace m_mutex with OwnPtr<m_mutex> so HashTable is still
   memory movable in debug build.
2. Assert successes of pthread_mutex_init() and pthread_mutex_destroy().

* wtf/HashTable.h:
(HashTable):
(WTF::::HashTable):
(WTF::::invalidateIterators):
(WTF::addIterator):
(WTF::removeIterator):
* wtf/ThreadingPthreads.cpp:
(WTF::Mutex::Mutex):
(WTF::Mutex::~Mutex):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (115987 => 115988)


--- trunk/Source/WTF/ChangeLog	2012-05-03 17:10:55 UTC (rev 115987)
+++ trunk/Source/WTF/ChangeLog	2012-05-03 17:18:11 UTC (rev 115988)
@@ -1,3 +1,24 @@
+2012-05-03  Yong Li  <[email protected]>
+
+        Mutex failure when HashTable is memory moved in debug build
+        https://bugs.webkit.org/show_bug.cgi?id=84970
+
+        Reviewed by Rob Buis.
+
+        1. Replace m_mutex with OwnPtr<m_mutex> so HashTable is still
+           memory movable in debug build.
+        2. Assert successes of pthread_mutex_init() and pthread_mutex_destroy().
+
+        * wtf/HashTable.h:
+        (HashTable):
+        (WTF::::HashTable):
+        (WTF::::invalidateIterators):
+        (WTF::addIterator):
+        (WTF::removeIterator):
+        * wtf/ThreadingPthreads.cpp:
+        (WTF::Mutex::Mutex):
+        (WTF::Mutex::~Mutex):
+
 2012-05-02  Antti Koivisto  <[email protected]>
 
         Add temporary feature define for parsed stylesheet caching

Modified: trunk/Source/WTF/wtf/HashTable.h (115987 => 115988)


--- trunk/Source/WTF/wtf/HashTable.h	2012-05-03 17:10:55 UTC (rev 115987)
+++ trunk/Source/WTF/wtf/HashTable.h	2012-05-03 17:18:11 UTC (rev 115988)
@@ -30,6 +30,12 @@
 #include <wtf/Threading.h>
 #include <wtf/ValueCheck.h>
 
+#ifndef NDEBUG
+// Required for CHECK_HASHTABLE_ITERATORS.
+#include <wtf/OwnPtr.h>
+#include <wtf/PassOwnPtr.h>
+#endif
+
 namespace WTF {
 
 #define DUMP_HASHTABLE_STATS 0
@@ -441,7 +447,8 @@
     public:
         // All access to m_iterators should be guarded with m_mutex.
         mutable const_iterator* m_iterators;
-        mutable Mutex m_mutex;
+        // Use OwnPtr so HashTable can still be memmove'd or memcpy'ed.
+        mutable OwnPtr<Mutex> m_mutex;
 #endif
     };
 
@@ -454,6 +461,7 @@
         , m_deletedCount(0)
 #if CHECK_HASHTABLE_ITERATORS
         , m_iterators(0)
+        , m_mutex(adoptPtr(new Mutex))
 #endif
     {
     }
@@ -1006,6 +1014,7 @@
         , m_deletedCount(0)
 #if CHECK_HASHTABLE_ITERATORS
         , m_iterators(0)
+        , m_mutex(adoptPtr(new Mutex))
 #endif
     {
         // Copy the hash table the dumb way, by adding each element to the new table.
@@ -1099,7 +1108,7 @@
     template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits>
     void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::invalidateIterators()
     {
-        MutexLocker lock(m_mutex);
+        MutexLocker lock(*m_mutex);
         const_iterator* next;
         for (const_iterator* p = m_iterators; p; p = next) {
             next = p->m_next;
@@ -1121,7 +1130,7 @@
         if (!table) {
             it->m_next = 0;
         } else {
-            MutexLocker lock(table->m_mutex);
+            MutexLocker lock(*table->m_mutex);
             ASSERT(table->m_iterators != it);
             it->m_next = table->m_iterators;
             table->m_iterators = it;
@@ -1143,7 +1152,7 @@
             ASSERT(!it->m_next);
             ASSERT(!it->m_previous);
         } else {
-            MutexLocker lock(it->m_table->m_mutex);
+            MutexLocker lock(*it->m_table->m_mutex);
             if (it->m_next) {
                 ASSERT(it->m_next->m_previous == it);
                 it->m_next->m_previous = it->m_previous;

Modified: trunk/Source/WTF/wtf/ThreadingPthreads.cpp (115987 => 115988)


--- trunk/Source/WTF/wtf/ThreadingPthreads.cpp	2012-05-03 17:10:55 UTC (rev 115987)
+++ trunk/Source/WTF/wtf/ThreadingPthreads.cpp	2012-05-03 17:18:11 UTC (rev 115988)
@@ -288,14 +288,16 @@
     pthread_mutexattr_init(&attr);
     pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
 
-    pthread_mutex_init(&m_mutex, &attr);
+    int result = pthread_mutex_init(&m_mutex, &attr);
+    ASSERT_UNUSED(result, !result);
 
     pthread_mutexattr_destroy(&attr);
 }
 
 Mutex::~Mutex()
 {
-    pthread_mutex_destroy(&m_mutex);
+    int result = pthread_mutex_destroy(&m_mutex);
+    ASSERT_UNUSED(result, !result);
 }
 
 void Mutex::lock()
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to