51 #define PTHREAD_EXT_QNODE_INITIALIZER { NULL } 52 #define PTHREAD_EXT_QNODE_INITIALIZE(x) (x)._held = NULL 54 typedef ext_qnode
volatile* ext_qnode_ptr;
64 pthread_mutex_init(&_mutex, 0);
81 pthread_mutex_destroy(&_mutex);
100 return pthread_mutex_trylock(&_mutex) == 0;
109 pthread_mutex_lock(&_mutex);
112 #if W_DEBUG_LEVEL > 0 133 pthread_mutex_unlock(&_mutex);
134 #if W_DEBUG_LEVEL > 10 159 if (me->_held ==
this) {
200 #define QUEUE_BLOCK_EXT_QNODE_INITIALIZER PTHREAD_EXT_QNODE_INITIALIZER 202 #define QUEUE_BLOCK_EXT_QNODE_INITIALIZE(x) x._held = NULL 204 #ifdef USE_PTHREAD_MUTEX 208 #define QUEUE_SPIN_EXT_QNODE_INITIALIZER PTHREAD_EXT_QNODE_INITIALIZER 209 #define QUEUE_EXT_QNODE_INITIALIZER PTHREAD_EXT_QNODE_INITIALIZER 211 #define QUEUE_EXT_QNODE_INITIALIZE(x) x._held = NULL; 216 #define QUEUE_SPIN_EXT_QNODE_INITIALIZER MCS_EXT_QNODE_INITIALIZER 217 #define QUEUE_EXT_QNODE_INITIALIZER MCS_EXT_QNODE_INITIALIZER 219 #define QUEUE_EXT_QNODE_INITIALIZE(x) MCS_EXT_QNODE_INITIALIZE(x) 252 void acquire_write();
255 void release_write();
285 occ_rlock* read_lock() {
290 occ_wlock* write_lock() {
311 #define MUTEX_ACQUIRE(mutex) W_COERCE((mutex).acquire()); 312 #define MUTEX_RELEASE(mutex) (mutex).release(); 313 #define MUTEX_IS_MINE(mutex) (mutex).is_mine() 329 #ifndef USE_PTHREAD_MUTEX 334 SPECIALIZE_CS(occ_rwlock::occ_rlock,
int _dummy, (_dummy = 0),
337 SPECIALIZE_CS(occ_rwlock::occ_wlock,
int _dummy, (_dummy = 0),
383 int holders = *&_holders;
384 return (holders == WRITER) ? WRITER : (holders > 0) ? READER : NONE;
389 return (*&_holders) == 0 ?
false :
true;
394 int holders = *&_holders;
395 return (holders == WRITER) ? 1 : holders / 2;
400 return *&_holders & ~WRITER;
405 return *&_holders & WRITER;
418 bool attempt_write();
421 void acquire_write();
424 void release_write();
427 bool attempt_upgrade();
434 int _spin_on_writer();
437 void _spin_on_readers();
439 bool _attempt_write(
unsigned int expected);
441 void _add_when_writer_leaves(
int delta);
450 _lock->acquire_read();
454 _lock->release_read();
464 _lock->acquire_write();
468 _lock->release_write();
475 #endif // __LATCHES_H A multiple-reader/single-writer lock based on pthreads (blocking)
Definition: latches.h:240
void atomic_thread_fence(memory_order order)
Definition: AtomicCounter.hpp:223
w_pthread_lock_t()
Definition: latches.h:63
~spinlock_write_critical_section()
Definition: latches.h:467
pthread_mutex_t _mutex
Definition: latches.h:58
#define w_assert1(x)
Level 1 should not add significant extra time.
Definition: w_base.h:198
bool attempt(ext_qnode &me)
Returns true if success. Helper for attempt(ext_qnode *).
Definition: latches.h:96
occ_wlock _write_lock
Definition: latches.h:304
rwmode_t
Definition: latches.h:371
Definition: latches.h:461
SPECIALIZE_CS(tatas_lock, int _dummy,(_dummy=0), _mutex->acquire(), _mutex->release())
occ_rlock _read_lock
Definition: latches.h:302
Header file for lintel::Atomic class.
mcs_lock queue_based_lock_t
Definition: latches.h:215
w_pthread_lock_t * _holder
Holder is this struct if acquire is successful.
Definition: latches.h:60
Definition: latches.h:447
void acquire_write()
The normal way to acquire a write lock.
Definition: latches.cpp:60
bool has_reader() const
True iff has one or more readers.
Definition: latches.h:399
pthread_cond_t _write_cond
Definition: latches.h:308
rwmode_t mode() const
Return the mode in which this lock is held by anyone.
Definition: latches.h:382
srwlock_t * _lock
Definition: latches.h:458
unsigned int volatile _holders
Definition: latches.h:368
mcs_lock queue_based_spin_lock_t
Definition: latches.h:214
mcs_rwlock srwlock_t
Definition: latches.h:444
srwlock_t * _lock
Definition: latches.h:472
#define w_assert0(x)
Default assert/debug level is 0.
Definition: w_base.h:175
spinlock_read_critical_section(srwlock_t *lock)
Definition: latches.h:449
pthread_cond_t _read_cond
Definition: latches.h:307
void release(ext_qnode_ptr me)
Release the lock and clear the qnode.
Definition: latches.h:127
~mcs_rwlock()
Definition: latches.h:379
An MCS queuing spinlock.
Definition: mcs_lock.h:61
void * acquire(ext_qnode *me)
Acquire the lock and set the qnode to refer to this lock.
Definition: latches.h:105
void release_read()
The normal way to release a read lock.
Definition: latches.cpp:20
bool attempt(ext_qnode *me)
Returns true if success.
Definition: latches.h:85
A test-and-test-and-set spinlock.
Definition: tatas.h:25
void release(ext_qnode &me)
Release the lock and clear the qnode.
Definition: latches.h:122
queue_based_lock_t parent_lock
Definition: latches.h:351
void acquire_read()
The normal way to acquire a read lock.
Definition: latches.cpp:31
bool is_locked() const
True if locked in any mode.
Definition: latches.h:388
w_pthread_lock_t queue_based_block_lock_t
Definition: latches.h:199
int num_holders() const
1 if held in write mode, else it's the number of readers
Definition: latches.h:393
mcs_lock * _held
Definition: mcs_lock.h:79
mcs_rwlock()
Definition: latches.h:377
unsigned int volatile _active_count
Definition: latches.h:300
bool is_mine(ext_qnode *me) const
Return true if this thread holds the lock.
Definition: latches.h:158
~spinlock_read_critical_section()
Definition: latches.h:453
Wrapper for pthread mutexes, with a queue-based lock API.
Definition: latches.h:46
~w_pthread_lock_t()
Definition: latches.h:67
void release_write()
The normal way to release a write lock.
Definition: latches.cpp:53
pthread_mutex_t _read_write_mutex
Definition: latches.h:306
bool has_writer() const
True iff has a writer (never more than 1)
Definition: latches.h:404
Shore read-write lock:: many-reader/one-writer spin lock.
Definition: latches.h:350
Definition: mcs_lock.h:76
spinlock_write_critical_section(srwlock_t *lock)
Definition: latches.h:463
Definition: AtomicCounter.hpp:113