Changeset 167526 in webkit


Ignore:
Timestamp:
Apr 18, 2014 8:23:03 PM (10 years ago)
Author:
ggaren@apple.com
Message:

bmalloc: AsyncTask should use Mutex instead of std::mutex
https://bugs.webkit.org/show_bug.cgi?id=131865

Reviewed by Gavin Barraclough.

std::mutex is so slow that it makes parallelizing simple tasks through
AsyncTask a net regression. Mutex fixes this.

  • bmalloc/AsyncTask.h:

(bmalloc::Function>::AsyncTask):
(bmalloc::Function>::join):
(bmalloc::Function>::runSlowCase):
(bmalloc::Function>::entryPoint):

  • bmalloc/Mutex.h:

(bmalloc::Mutex::init):

Location:
trunk/Source/bmalloc
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/bmalloc/ChangeLog

    r167502 r167526  
     12014-04-18  Geoffrey Garen  <ggaren@apple.com>
     2
     3        bmalloc: AsyncTask should use Mutex instead of std::mutex
     4        https://bugs.webkit.org/show_bug.cgi?id=131865
     5
     6        Reviewed by Gavin Barraclough.
     7
     8        std::mutex is so slow that it makes parallelizing simple tasks through
     9        AsyncTask a net regression. Mutex fixes this.
     10
     11        * bmalloc/AsyncTask.h:
     12        (bmalloc::Function>::AsyncTask):
     13        (bmalloc::Function>::join):
     14        (bmalloc::Function>::runSlowCase):
     15        (bmalloc::Function>::entryPoint):
     16        * bmalloc/Mutex.h:
     17        (bmalloc::Mutex::init):
     18
    1192014-04-18  Geoffrey Garen  <ggaren@apple.com>
    220
  • trunk/Source/bmalloc/bmalloc/AsyncTask.h

    r166956 r167526  
    2929#include "BAssert.h"
    3030#include "Inline.h"
     31#include "Mutex.h"
    3132#include <atomic>
    3233#include <condition_variable>
     
    5657    std::atomic<State> m_state;
    5758
    58     std::mutex m_conditionMutex;
    59     std::condition_variable m_condition;
     59    Mutex m_conditionMutex;
     60    std::condition_variable_any m_condition;
    6061    pthread_t m_thread;
    6162
     
    7475    , m_function(function)
    7576{
     77    m_conditionMutex.init();
    7678}
    7779
     
    8284        return;
    8385
    84     { std::lock_guard<std::mutex> lock(m_conditionMutex); }
     86    { std::lock_guard<Mutex> lock(m_conditionMutex); }
    8587    m_condition.notify_one();
    8688
     
    105107
    106108    if (oldState == Sleeping) {
    107         { std::lock_guard<std::mutex> lock(m_conditionMutex); }
     109        { std::lock_guard<Mutex> lock(m_conditionMutex); }
    108110        m_condition.notify_one();
    109111        return;
     
    132134        expectedState = Running;
    133135        if (m_state.compare_exchange_weak(expectedState, Sleeping)) {
    134             std::unique_lock<std::mutex> lock(m_conditionMutex);
     136            std::unique_lock<Mutex> lock(m_conditionMutex);
    135137            m_condition.wait_for(lock, exitDelay, [=]() { return this->m_state != Sleeping; });
    136138        }
  • trunk/Source/bmalloc/bmalloc/Mutex.h

    r166910 r167526  
    3434namespace bmalloc {
    3535
    36 class Mutex {
     36struct Mutex {
    3737public:
     38    void init();
     39
    3840    void lock();
    3941    bool try_lock();
     
    4547    std::atomic_flag m_flag;
    4648};
     49
     50inline void Mutex::init()
     51{
     52    m_flag.clear();
     53}
    4754
    4855inline bool Mutex::try_lock()
Note: See TracChangeset for help on using the changeset viewer.