w_pthread_lock_t Struct Reference

Collaboration diagram for w_pthread_lock_t:

Collaboration graph
[legend]
List of all members.

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

Definition at line 416 of file sthread.h.

Public Member Functions

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


Member Function Documentation

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.

Definition at line 510 of file sthread.h.

References w_assert1.

Referenced by acquire().

Here is the caller graph for this function:


The documentation for this struct was generated from the following file:
Generated on Mon Jan 2 15:14:21 2012 for Shore Storage Manager by  doxygen 1.4.7