Zero  0.1.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
latch_t Class Reference

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

#include <latch.h>

Public Member Functions

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

Static Public Member Functions

static void on_thread_destroy ()
 Destroy TLS structures. More...
 

Static Public Attributes

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

Private Member Functions

w_rc_t _acquire (latch_mode_t m, int timeout_in_ms, latch_holder_t *me)
 
int _release (latch_holder_t *me)
 
void _downgrade (latch_holder_t *me)
 
 latch_t (const latch_t &)
 
latch_toperator= (const latch_t &)
 

Private Attributes

srwlock_t _lock
 
uint32_t _total_count
 

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

Constructor & Destructor Documentation

§ latch_t() [1/2]

latch_t::latch_t ( )

Create a latch.

§ ~latch_t()

latch_t::~latch_t ( )

§ latch_t() [2/2]

latch_t::latch_t ( const latch_t )
private

Member Function Documentation

§ _acquire()

w_rc_t latch_t::_acquire ( latch_mode_t  m,
int  timeout_in_ms,
latch_holder_t me 
)
private

§ _downgrade()

void latch_t::_downgrade ( latch_holder_t me)
private

§ _release()

int latch_t::_release ( latch_holder_t me)
private

§ downgrade()

void latch_t::downgrade ( )

Convert atomically an EX latch into an SH latch.

Does not decrement the latch count.

§ held_by_me()

int latch_t::held_by_me ( ) const

True iff held in EX or SH mode. Actually, it returns the.

§ id()

const void* latch_t::id ( ) const
inline

§ is_latched()

bool latch_t::is_latched ( ) const
inline

Unreliable, but helpful for some debugging.

§ is_mine()

bool latch_t::is_mine ( ) const

True iff held in EX mode.

§ latch_acquire()

w_rc_t latch_t::latch_acquire ( latch_mode_t  m,
int  timeout = timeout_t::WAIT_FOREVER 
)

Acquire the latch in given mode.

See also
timeout_t.

§ latch_cnt()

int latch_t::latch_cnt ( ) const
inline

Number of acquires. A thread may hold more than once.

§ latch_release()

int latch_t::latch_release ( )

release the latch.

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

§ mode()

latch_mode_t latch_t::mode ( ) const
inline

EX, SH, or NL (if not held at all).

§ num_holders()

int latch_t::num_holders ( ) const
inline

How many threads hold the R/W lock.

§ on_thread_destroy()

void latch_t::on_thread_destroy ( )
static

Destroy TLS structures.

§ operator=()

latch_t& latch_t::operator= ( const latch_t )
private

§ print()

std::ostream & latch_t::print ( std::ostream &  out) const

§ setname()

void latch_t::setname ( const char *const  desc)
inline

Change the name of the latch.

§ upgrade_if_not_block()

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.

Member Data Documentation

§ _lock

srwlock_t latch_t::_lock
mutableprivate

§ _total_count

uint32_t latch_t::_total_count
private

§ latch_mode_str

const char *const latch_t::latch_mode_str = {"NL", "Q", "SH", "EX"}
static

string names of modes.


The documentation for this class was generated from the following files: