Changeset 92523 in webkit


Ignore:
Timestamp:
Aug 5, 2011 3:36:51 PM (13 years ago)
Author:
mrowe@apple.com
Message:

<http://webkit.org/b/65785> ThreadRestrictionVerifier needs a mode where an object
is tied to a particular dispatch queue

A RefCounted object can be opted in to this mode by calling setDispatchQueueForVerifier
with the dispatch queue it will be tied to. This will cause ThreadRestrictionVerifier
to ensure that all operations are performed on the given dispatch queue.

Reviewed by Anders Carlsson.

  • wtf/RefCounted.h:

(WTF::RefCountedBase::setDispatchQueueForVerifier):

  • wtf/ThreadRestrictionVerifier.h:

(WTF::ThreadRestrictionVerifier::ThreadRestrictionVerifier):
(WTF::ThreadRestrictionVerifier::~ThreadRestrictionVerifier):
(WTF::ThreadRestrictionVerifier::setDispatchQueueMode):
(WTF::ThreadRestrictionVerifier::setShared):
(WTF::ThreadRestrictionVerifier::isSafeToUse):

Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r92498 r92523  
     12011-08-05  Mark Rowe  <mrowe@apple.com>
     2
     3        <http://webkit.org/b/65785> ThreadRestrictionVerifier needs a mode where an object
     4        is tied to a particular dispatch queue
     5
     6        A RefCounted object can be opted in to this mode by calling setDispatchQueueForVerifier
     7        with the dispatch queue it will be tied to. This will cause ThreadRestrictionVerifier
     8        to ensure that all operations are performed on the given dispatch queue.
     9
     10        Reviewed by Anders Carlsson.
     11
     12        * wtf/RefCounted.h:
     13        (WTF::RefCountedBase::setDispatchQueueForVerifier):
     14        * wtf/ThreadRestrictionVerifier.h:
     15        (WTF::ThreadRestrictionVerifier::ThreadRestrictionVerifier):
     16        (WTF::ThreadRestrictionVerifier::~ThreadRestrictionVerifier):
     17        (WTF::ThreadRestrictionVerifier::setDispatchQueueMode):
     18        (WTF::ThreadRestrictionVerifier::setShared):
     19        (WTF::ThreadRestrictionVerifier::isSafeToUse):
     20
    1212011-08-05  Oliver Hunt  <oliver@apple.com>
    222
  • trunk/Source/JavaScriptCore/wtf/RefCounted.h

    r92254 r92523  
    7272    void setMutexForVerifier(Mutex&);
    7373
     74#if HAVE(DISPATCH_H)
     75    void setDispatchQueueForVerifier(dispatch_queue_t);
     76#endif
     77
    7478    // Turns off verification. Use of this method is discouraged (instead extend
    7579    // ThreadRestrictionVerifier to verify your case).
     
    213217#endif
    214218
     219#if HAVE(DISPATCH_H)
     220#ifdef NDEBUG
     221inline void RefCountedBase::setDispatchQueueForVerifier(dispatch_queue_t) { }
     222#else
     223inline void RefCountedBase::setDispatchQueueForVerifier(dispatch_queue_t queue)
     224{
     225    m_verifier.setDispatchQueueMode(queue);
     226}
     227#endif // NDEBUG
     228#endif // HAVE(DISPATCH_H)
     229
    215230} // namespace WTF
    216231
  • trunk/Source/JavaScriptCore/wtf/ThreadRestrictionVerifier.h

    r92254 r92523  
    3636#include <wtf/ThreadingPrimitives.h>
    3737
     38#if HAVE(DISPATCH_H)
     39#include <dispatch/dispatch.h>
     40#endif
     41
    3842#ifndef NDEBUG
    3943
     
    5155        , m_owningThread(0)
    5256        , m_mutex(0)
     57#if HAVE(DISPATCH_H)
     58        , m_owningQueue(0)
     59#endif
    5360    {
    5461    }
     62
     63#if HAVE(DISPATCH_H)
     64    ~ThreadRestrictionVerifier()
     65    {
     66        if (m_owningQueue)
     67            dispatch_release(m_owningQueue);
     68    }
     69#endif
    5570
    5671    void setMutexMode(Mutex& mutex)
     
    6075        m_mutex = &mutex;
    6176    }
     77
     78#if HAVE(DISPATCH_H)
     79    void setDispatchQueueMode(dispatch_queue_t queue)
     80    {
     81        ASSERT(m_mode == SingleThreadVerificationMode);
     82        m_mode = SingleDispatchQueueVerificationMode;
     83        m_owningQueue = queue;
     84        dispatch_retain(m_owningQueue);
     85    }
     86#endif
    6287
    6388    void turnOffVerification()
     
    83108            return;
    84109
     110#if HAVE(DISPATCH_H)
     111        case SingleDispatchQueueVerificationMode:
     112#endif
    85113        case MutexVerificationMode:
    86114        case NoVerificationMode:
     
    106134            return false;
    107135
     136#if HAVE(DISPATCH_H)
     137        case SingleDispatchQueueVerificationMode:
     138            return m_owningQueue == dispatch_get_current_queue();
     139#endif
     140
    108141        case NoVerificationMode:
    109142            return true;
     
    117150        SingleThreadVerificationMode,
    118151        MutexVerificationMode,
    119         NoVerificationMode
     152        NoVerificationMode,
     153#if HAVE(DISPATCH_H)
     154        SingleDispatchQueueVerificationMode,
     155#endif
    120156    };
    121157
     
    128164    // Used by MutexVerificationMode.
    129165    Mutex* m_mutex;
     166
     167#if HAVE(DISPATCH_H)
     168    // Used by SingleDispatchQueueVerificationMode.
     169    dispatch_queue_t m_owningQueue;
     170#endif
    130171};
    131172
Note: See TracChangeset for help on using the changeset viewer.