Zero  0.1.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
w_pthread_lock_t Struct Reference

Wrapper for pthread mutexes, with a queue-based lock API. More...

#include <latches.h>

Public Member Functions

 w_pthread_lock_t ()
 
 ~w_pthread_lock_t ()
 
bool attempt (ext_qnode *me)
 Returns true if success. More...
 
void * acquire (ext_qnode *me)
 Acquire the lock and set the qnode to refer to this lock. More...
 
void release (ext_qnode &me)
 Release the lock and clear the qnode. More...
 
void release (ext_qnode_ptr me)
 Release the lock and clear the qnode. More...
 
bool is_mine (ext_qnode *me) const
 Return true if this thread holds the lock. More...
 

Private Member Functions

bool attempt (ext_qnode &me)
 Returns true if success. Helper for attempt(ext_qnode *). More...
 

Private Attributes

pthread_mutex_t _mutex
 
w_pthread_lock_t_holder
 Holder is this struct if acquire is successful. More...
 

Detailed Description

Wrapper for pthread mutexes, with a queue-based lock API.

When the storage manager is configured with the default, –enable-pthread-mutex, this lock uses a Pthreads mutex for the lock. In this case, it is not a true queue-based lock, since release doesn't inform the next node in the queue, and in fact the nodes aren't kept in a queue. It just gives pthread mutexes the same API as the other queue-based locks so that we use the same idioms for critical sections based on different kinds of locks. By configuring with pthreads mutexes implementing this class, the server can spawn any number of threads, regardless of the number of hardware contexts available; threads will block as necessary.

When the storage manager is configured with –disable-pthread-mutex, this lock uses an MCS (MCS1) queue-based lock for the lock. In this case, it is a true queue-based lock. By configuring with MCS locks implementing this class, if the server spawn many more threads than hardware contexts, time can be wasted spinning; threads will not block until the operating system (or underlying thread scheduler) determines to block the thread.

The idiom for using these locks is that the qnode is on a threads's stack, so the qnode implicitly identifies the owning thread.

This allows us to add an is_mine() capability that otherwise the pthread mutexen don't have.

Finally, using this class ensures that the pthread_mutex_init/destroy is done (in the –enable-pthread-mutex case).

See also: REFSYNC

Constructor & Destructor Documentation

§ w_pthread_lock_t()

w_pthread_lock_t::w_pthread_lock_t ( )
inline

§ ~w_pthread_lock_t()

w_pthread_lock_t::~w_pthread_lock_t ( )
inline

Member Function Documentation

§ acquire()

void* w_pthread_lock_t::acquire ( ext_qnode *  me)
inline

Acquire the lock and set the qnode to refer to this lock.

§ attempt() [1/2]

bool w_pthread_lock_t::attempt ( ext_qnode *  me)
inline

Returns true if success.

§ attempt() [2/2]

bool w_pthread_lock_t::attempt ( ext_qnode &  me)
inlineprivate

Returns true if success. Helper for attempt(ext_qnode *).

§ is_mine()

bool w_pthread_lock_t::is_mine ( ext_qnode *  me) const
inline

Return true if this thread holds the lock.

This method doesn't actually check for this pthread holding the lock, but it checks that the qnode reference is to this lock. The idiom for using these locks is that the qnode is on a threads's stack, so the qnode implicitly identifies the owning thread.

§ release() [1/2]

void w_pthread_lock_t::release ( ext_qnode &  me)
inline

Release the lock and clear the qnode.

§ release() [2/2]

void w_pthread_lock_t::release ( ext_qnode_ptr  me)
inline

Release the lock and clear the qnode.

Member Data Documentation

§ _holder

w_pthread_lock_t* w_pthread_lock_t::_holder
private

Holder is this struct if acquire is successful.

§ _mutex

pthread_mutex_t w_pthread_lock_t::_mutex
private

skip


The documentation for this struct was generated from the following file: