• Marko Mäkelä's avatar
    MDEV-25404: Optimize srw_mutex on Linux, OpenBSD, Windows · 040c16ab
    Marko Mäkelä authored
    On Linux, OpenBSD and Microsoft Windows, srw_mutex was an alias for a
    rw-lock while we only need mutex functionality. Let us implement a
    futex-based mutex with one bit for HOLDER and 31 bits for counting
    waiting requests.
    
    srw_lock::wr_unlock() can avoid waking up a waiter when no waiting
    requests exist. (Previously, we only had 1-bit rw_lock::WRITER_WAITING
    flag that could be wrongly cleared if multiple waiting wr_lock() exist.
    Now we have no problem with up to 2,147,483,648 conflicting threads.)
    
    On 64-bit Microsoft Windows, the advantage is that
    sizeof(srw_mutex) is 4, while sizeof(SRWLOCK) would be 8.
    
    Reviewed by: Vladislav Vaintroub
    040c16ab
srw_lock.cc 10.1 KB