static void lock_W() { LockState& ls = lockState(); if( ls.threadState == 't' ) { DEV warning() << "W locking inside a temprelease, seems nonideal" << endl; } else if( ls.threadState ) { log() << "can't lock_W, threadState=" << (int) ls.threadState << endl; fassert(0,false); } getDur().commitIfNeeded(); // check before locking - will use an R lock for the commit if need to do one, which is better than W threadState() = 'W'; { Acquiring a('W'); q.lock_W(); } locked_W(); }
Lock::GlobalWrite::GlobalWrite(bool sg, int timeoutms) : ScopedLock('W') { char ts = threadState(); noop = false; if( ts == 'W' ) { noop = true; return; } dassert( ts == 0 ); Acquiring a(this,lockState()); if ( timeoutms != -1 ) { bool success = qlk.lock_W_try( timeoutms ); if ( !success ) throw DBTryLockTimeoutException(); } else { qlk.lock_W(); } }
void Lock::GlobalRead::_tempRelease() { fassert(16127, !noop); char ts = threadState(); fassert(16128, ts == 'R'); qlk.unlock_R(); }
bool Lock::isR() { return threadState() == 'R'; }
bool Lock::isW() { return threadState() == 'W'; }
bool Lock::isRW() { return threadState() == 'W' || threadState() == 'R'; }
static void unlock_w() { unlocking_w(); wassert( threadState() == 'w' ); threadState() = 0; q.unlock_w(); }
int KNMusicStandardBackend::state() const { return threadState(m_main); }
int Lock::isLocked() { return threadState(); }
void Lock::ThreadSpanningOp::handoffR() { threadState() = 0; }
void Lock::ThreadSpanningOp::unsetR() { assert( threadState() == 'R' || threadState() == 0 ); q.unlock_R(); q.start_greed(); threadState() = 0; }
void Lock::ThreadSpanningOp::unsetW() { // note there is no unlocking_W() call here assert( threadState() == 'W' ); q.unlock_W(); q.start_greed(); threadState() = 0; }
void Lock::ThreadSpanningOp::W_to_R() { assert( threadState() == 'W' ); dur::assertNothingSpooled(); q.W_to_R(); threadState() = 'R'; }
// these are safe for use ACROSS threads. i.e. one thread can lock and // another unlock void Lock::ThreadSpanningOp::setWLockedNongreedy() { assert( threadState() == 0 ); // as this spans threads the tls wouldn't make sense lock_W_stop_greed(); }
static void unlock_r() { wassert( threadState() == 'r' ); threadState() = 0; q.unlock_r(); }
void Lock::GlobalWrite::downgrade() { verify( !noop ); verify( threadState() == 'W' ); qlk.W_to_R(); lockState().changeLockState( 'R' ); }
// you will deadlock if 2 threads doing this void Lock::GlobalWrite::upgrade() { verify( !noop ); verify( threadState() == 'R' ); qlk.R_to_W(); lockState().changeLockState( 'W' ); }
int Lock::isReadLocked() { return threadState() == 'R' || threadState() == 'r'; }
int KNMusicStandardBackend::previewState() const { return threadState(m_preview); }
int Lock::somethingWriteLocked() { return threadState() == 'W' || threadState() == 'w'; }