latch_t Class Reference

Inherits sthread_named_base_t.

Collaboration diagram for latch_t:

Collaboration graph
[legend]
List of all members.

Detailed Description

A short-term hold (exclusive or shared) on a page.

A latch may be acquire()d multiple times by a single thread. The mode of subsequent acquire()s must be at or above the level of the currently held latch. Each of these individual locks must be released.

See also:
latch_holder_t

Definition at line 139 of file latch.h.

Public Member Functions

NORET latch_t (const char *const desc=0)
 Create a latch with the given name.
NORET ~latch_t ()
ostream & print (ostream &) const
const void * id () const
void setname (const char *const desc)
 Change the name of the latch.
w_rc_t latch_acquire (latch_mode_t m, sthread_t::timeout_in_ms timeout=sthread_base_t::WAIT_FOREVER)
 Acquire the latch in given mode.
w_rc_t upgrade_if_not_block (bool &would_block)
 Upgrade from SH to EX if it can be done w/o blocking.
void downgrade ()
 Convert atomically an EX latch into an SH latch.
int latch_release ()
 release the latch.
bool is_latched () const
 Unreliable, but helpful for some debugging.
int latch_cnt () const
 Number of acquires. A thread may hold more than once.
int num_holders () const
 How many threads hold the R/W lock.
bool is_mine () const
 True iff held in EX mode.
int held_by_me () const
 True iff held in EX or SH mode. Actually, it returns the.
latch_mode_t mode () const
 EX, SH, or NL (if not held at all).

Static Public Attributes

static const char *const latch_mode_str [3] = { "NL", "SH", "EX" }
 string names of modes.


Member Function Documentation

w_rc_t latch_t::latch_acquire ( latch_mode_t  m,
sthread_t::timeout_in_ms  timeout = sthread_base_t::WAIT_FOREVER 
)

Acquire the latch in given mode.

See also:
timeout_t.

Definition at line 348 of file latch.cpp.

References holder_search::value(), and w_assert1.

Here is the call graph for this function:

w_rc_t latch_t::upgrade_if_not_block ( bool &  would_block  ) 

Upgrade from SH to EX if it can be done w/o blocking.

Returns bool indicating if it would have blocked, in which case the upgrade did not occur. If it didn't have to block, the upgrade did occur.

Note:
Does not increment the count.

Definition at line 356 of file latch.cpp.

References DBGTHRD, w_rc_t::err_num(), w_rc_t::is_error(), RC_AUGMENT, RCOK, holder_search::value(), and w_assert3.

Here is the call graph for this function:

void latch_t::downgrade (  ) 

Convert atomically an EX latch into an SH latch.

Does not decrement the latch count.

Definition at line 507 of file latch.cpp.

References holder_search::value(), and w_assert3.

Here is the call graph for this function:

int latch_t::latch_release (  ) 

release the latch.

Decrements the latch count and releases only when it hits 0. Returns the resulting latch count.

Definition at line 388 of file latch.cpp.

References holder_search::value(), and w_assert2.

Here is the call graph for this function:


The documentation for this class was generated from the following files:
Generated on Wed Jul 7 17:22:43 2010 for Shore Storage Manager by  doxygen 1.4.7