#include <latch.h> // these are defined outside of class latch_t due to bugs in // some C++ compilers enum latch_mode_t { LATCH_NL = 0, LATCH_SH = 1, LATCH_EX = 2 }; class latch_t : public sthread_named_base_t { public: NORET latch_t(const char* const desc = 0); NORET ~latch_t() {}; #ifdef DEBUG friend ostream& operator<<(ostream&, const latch_t& l); #endif inline void setname(const char *const desc); w_rc_t acquire( latch_mode_t m, int timeout = sthread_base_t::WAIT_FOREVER); w_rc_t upgrade_if_not_block( bool& would_block); void release(); bool is_locked() const; bool is_hot() const; int lock_cnt() const; int num_holders() const; int held_by(const sthread_t* t) const; bool is_mine() const; private: // disabled methods NORET latch_t(const latch_t&); latch_t& operator=(const latch_t&); };
Latches are a read/write synchronization mechanism for threads, as opposed to locks which are used for synchronizing transactions. Latches are much lighter weight than locks, have no symbolic names, and have no deadlock detection.
latch_t(desc)