Changeset 44651 in webkit


Ignore:
Timestamp:
Jun 13, 2009 10:52:44 AM (15 years ago)
Author:
hyatt@apple.com
Message:

2009-06-12 Dave Hyatt <hyatt@apple.com>

Reviewed by Anders Carlsson.

https://bugs.webkit.org/show_bug.cgi?id=26373

Add a new class to Threading in wtf called ReadWriteLock that handles single writer/multiple reader locking.
Provide a pthreads-only implementation of the lock for now, as this class is only going to be used
on Snow Leopard at first.

  • wtf/Threading.h: (WTF::ReadWriteLock::impl):
  • wtf/ThreadingPthreads.cpp: (WTF::ReadWriteLock::ReadWriteLock): (WTF::ReadWriteLock::~ReadWriteLock): (WTF::ReadWriteLock::readLock): (WTF::ReadWriteLock::tryReadLock): (WTF::ReadWriteLock::writeLock): (WTF::ReadWriteLock::tryWriteLock): (WTF::ReadWriteLock::unlock):
Location:
trunk/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r44644 r44651  
     12009-06-12  Dave Hyatt  <hyatt@apple.com>
     2
     3        Reviewed by Anders Carlsson.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=26373
     6
     7        Add a new class to Threading in wtf called ReadWriteLock that handles single writer/multiple reader locking.
     8        Provide a pthreads-only implementation of the lock for now, as this class is only going to be used
     9        on Snow Leopard at first.
     10
     11        * wtf/Threading.h:
     12        (WTF::ReadWriteLock::impl):
     13        * wtf/ThreadingPthreads.cpp:
     14        (WTF::ReadWriteLock::ReadWriteLock):
     15        (WTF::ReadWriteLock::~ReadWriteLock):
     16        (WTF::ReadWriteLock::readLock):
     17        (WTF::ReadWriteLock::tryReadLock):
     18        (WTF::ReadWriteLock::writeLock):
     19        (WTF::ReadWriteLock::tryWriteLock):
     20        (WTF::ReadWriteLock::unlock):
     21
    1222009-06-12  Oliver Hunt  <oliver@apple.com>
    223
  • trunk/JavaScriptCore/wtf/Threading.h

    r43663 r44651  
    127127#if USE(PTHREADS)
    128128typedef pthread_mutex_t PlatformMutex;
     129typedef pthread_rwlock_t PlatformReadWriteLock;
    129130typedef pthread_cond_t PlatformCondition;
    130131#elif PLATFORM(GTK)
    131132typedef GOwnPtr<GMutex> PlatformMutex;
     133typedef void* PlatformReadWriteLock; // FIXME: Implement.
    132134typedef GOwnPtr<GCond> PlatformCondition;
    133135#elif PLATFORM(QT)
    134136typedef QT_PREPEND_NAMESPACE(QMutex)* PlatformMutex;
     137typedef void* PlatformReadWriteLock; // FIXME: Implement.
    135138typedef QT_PREPEND_NAMESPACE(QWaitCondition)* PlatformCondition;
    136139#elif PLATFORM(WIN_OS)
     
    139142    size_t m_recursionCount;
    140143};
     144typedef void* PlatformReadWriteLock; // FIXME: Implement.
    141145struct PlatformCondition {
    142146    size_t m_waitersGone;
     
    152156#else
    153157typedef void* PlatformMutex;
     158typedef void* PlatformReadWriteLock;
    154159typedef void* PlatformCondition;
    155160#endif
     
    171176
    172177typedef Locker<Mutex> MutexLocker;
     178
     179class ReadWriteLock : Noncopyable {
     180public:
     181    ReadWriteLock();
     182    ~ReadWriteLock();
     183
     184    void readLock();
     185    bool tryReadLock();
     186
     187    void writeLock();
     188    bool tryWriteLock();
     189   
     190    void unlock();
     191
     192private:
     193    PlatformReadWriteLock m_readWriteLock;
     194};
    173195
    174196class ThreadCondition : Noncopyable {
  • trunk/JavaScriptCore/wtf/ThreadingPthreads.cpp

    r44504 r44651  
    268268}
    269269
     270
     271ReadWriteLock::ReadWriteLock()
     272{
     273    pthread_rwlock_init(&m_readWriteLock, NULL);
     274}
     275
     276ReadWriteLock::~ReadWriteLock()
     277{
     278    pthread_rwlock_destroy(&m_readWriteLock);
     279}
     280
     281void ReadWriteLock::readLock()
     282{
     283    int result = pthread_rwlock_rdlock(&m_readWriteLock);
     284    ASSERT_UNUSED(result, !result);
     285}
     286
     287bool ReadWriteLock::tryReadLock()
     288{
     289    int result = pthread_rwlock_tryrdlock(&m_readWriteLock);
     290
     291    if (result == 0)
     292        return true;
     293    if (result == EBUSY || result == EAGAIN)
     294        return false;
     295
     296    ASSERT_NOT_REACHED();
     297    return false;
     298}
     299
     300void ReadWriteLock::writeLock()
     301{
     302    int result = pthread_rwlock_wrlock(&m_readWriteLock);
     303    ASSERT_UNUSED(result, !result);
     304}
     305
     306bool ReadWriteLock::tryWriteLock()
     307{
     308    int result = pthread_rwlock_trywrlock(&m_readWriteLock);
     309
     310    if (result == 0)
     311        return true;
     312    if (result == EBUSY || result == EAGAIN)
     313        return false;
     314
     315    ASSERT_NOT_REACHED();
     316    return false;
     317}
     318
     319void ReadWriteLock::unlock()
     320{
     321    int result = pthread_rwlock_unlock(&m_readWriteLock);
     322    ASSERT_UNUSED(result, !result);
     323}
     324
    270325ThreadCondition::ThreadCondition()
    271326{
Note: See TracChangeset for help on using the changeset viewer.