示例#1
0
Error RWLockWindows::write_try_lock() {
	if (TryAcquireSRWLockExclusive(&lock) == 0) {
		return ERR_BUSY;
	} else {
		return OK;
	}
}
示例#2
0
文件: CWLock.cpp 项目: winest/CWUtils
BOOL CRWLockSlim::AcquireWriterLock( DWORD dwTimeout )
{
    BOOL bRet = FALSE;

#if ( _WIN32_WINNT_WIN7 <= _WIN32_WINNT )
    if ( INFINITE == dwTimeout || FALSE == m_bWin7AndLater )
    {
        AcquireSRWLockExclusive( &m_srwLock );
        bRet = TRUE;
    }
    else
    {
        LARGE_INTEGER lnCurr , lnEnd;
        QueryPerformanceCounter( &lnCurr );
        lnEnd.QuadPart = lnCurr.QuadPart + dwTimeout * ( m_lnFreq.QuadPart / 1000 );
        do
        {
            QueryPerformanceCounter( &lnCurr );
            bRet = (BOOL)TryAcquireSRWLockExclusive( &m_srwLock );
        } while ( lnCurr.QuadPart < lnEnd.QuadPart );
    }
#else
    AcquireSRWLockExclusive( &m_srwLock );
    bRet = TRUE;
#endif

    return bRet;
}
示例#3
0
/// <summary>
/// Tries to acquire write lock (now). Returns true if succeeded, false if failed.
/// </summary>
/// <returns></returns>
bool RWLock::TryLockWrite()
{
#ifdef PLATFORM_WIN
	return (TryAcquireSRWLockExclusive( &mRwlock ) > 0);
#else
	return (pthread_rwlock_trywrlock( &mRwlock ) == 0);
#endif
}
示例#4
0
int
pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock)
{
	if (TryAcquireSRWLockExclusive(&rwlock->rwlock)) {
		rwlock->exclusive_locked = GetCurrentThreadId();
		return (0);
	}

	return (EBUSY);
}
示例#5
0
bool TRI_TryWriteLockReadWriteLock (TRI_read_write_lock_t* lock) {
#if TRI_WINDOWS_VISTA_LOCKS
  BOOL result;
  // ...........................................................................
  // Here we use TryEnterCriticalSection instead of EnterCriticalSection
  // There could already be a write lock - which will actuall block from this
  // point on.
  // ...........................................................................

  result = TryEnterCriticalSection(&lock->_lockWriter);

  if (result == 0) {
    // appears some other writer is writing
    return false;
  }

  // ...........................................................................
  // Wait until the lock->_writerEvent is in a 'signalled' state
  // This might fail because a reader is just about to read
  // ...........................................................................

  if (WaitForSingleObject(lock->_writerEvent, 0) != WAIT_OBJECT_0) {
    LeaveCriticalSection(&lock->_lockWriter);
    return false;
  }

  // ...........................................................................
  // Set _writeEvent as nonsignalled -- this will block other read/write
  // lockers
  // ...........................................................................

  ResetEvent(lock->_writerEvent);

  // ...........................................................................
  // If there are ANY read locks outstanding, leave
  // ...........................................................................

  if (WaitForSingleObject(lock->_readersEvent, 0) != WAIT_OBJECT_0) {
    LeaveCriticalSection(&lock->_lockWriter);
    SetEvent(lock->_writerEvent);
    return false;
  }

  // ...........................................................................
  // Allow other threads to access this function
  // ...........................................................................

  LeaveCriticalSection(&lock->_lockWriter);

  return true;
#else
  return (TryAcquireSRWLockExclusive(&lock->_lock) != 0);
#endif
}
示例#6
0
int qemu_mutex_trylock_impl(QemuMutex *mutex, const char *file, const int line)
{
    int owned;

    assert(mutex->initialized);
    owned = TryAcquireSRWLockExclusive(&mutex->lock);
    if (owned) {
        trace_qemu_mutex_locked(mutex, file, line);
        return 0;
    }
    return -EBUSY;
}
示例#7
0
bool ReadWriteLock::TryBeginWrite()
{
	return TryAcquireSRWLockExclusive(&mLock) == TRUE;
}
示例#8
0
 bool tryLockWrite()
 {
     return TryAcquireSRWLockExclusive(&this->_rwlock) != 0;
 }
示例#9
0
bool TRI_TryWriteLockReadWriteLock (TRI_read_write_lock_t* lock) {
  return (TryAcquireSRWLockExclusive(&lock->_lock) != 0);
}
示例#10
0
bool	RWMutex::tryWriteLock()
{
	return TryAcquireSRWLockExclusive(&_mutex);
}
示例#11
0
文件: rwlock.hpp 项目: Ribtoks/xpiks
 bool trywrlock()
 {
     return TryAcquireSRWLockExclusive(&rwlock_);
 }
示例#12
0
 BOOLEAN try_lock ()
 {
    return TryAcquireSRWLockExclusive ( &_lock ) ;
 }
bool WinReadWriteLock::tryLockForWrite()
{
	return TryAcquireSRWLockExclusive(&m_lock);
}
bool SlimReaderWriterLock::try_lock()
{
   return TryAcquireSRWLockExclusive( &mSrwlock ) != 0;
}