/*---------------------------------------------------------------------- | NPT_PSPSharedVariable::SetValue +---------------------------------------------------------------------*/ NPT_Result NPT_PSPSharedVariable::SetValue(NPT_Integer value) { m_Lock.Lock(); m_Value = value; m_Lock.Unlock(); return NPT_SUCCESS; }
/*---------------------------------------------------------------------- | NPT_Win32SharedVariable::SetValue +---------------------------------------------------------------------*/ void NPT_Win32SharedVariable::SetValue(int value) { m_Lock.Lock(); if (value != m_Value) { m_Value = value; m_Event.Signal(); } m_Lock.Unlock(); }
/*---------------------------------------------------------------------- | NPT_PSPAtomicVariable::Decrement +---------------------------------------------------------------------*/ NPT_Integer NPT_PSPAtomicVariable::Decrement() { NPT_Integer value; m_Mutex.Lock(); value = --m_Value; m_Mutex.Unlock(); return value; }
/*---------------------------------------------------------------------- | NPT_Win32SharedVariable::WaitWhileEquals +---------------------------------------------------------------------*/ NPT_Result NPT_Win32SharedVariable::WaitWhileEquals(int value, NPT_Timeout timeout) { do { m_Lock.Lock(); if (m_Value != value) { break; } m_Lock.Unlock(); { NPT_Result result = m_Event.Wait(timeout); if (NPT_FAILED(result)) return result; } } while (1); m_Lock.Unlock(); return NPT_SUCCESS; }
/*---------------------------------------------------------------------- | NPT_PSPSharedVariable::WaitWhileEquals +---------------------------------------------------------------------*/ NPT_Result NPT_PSPSharedVariable::WaitWhileEquals(NPT_Integer value, NPT_Timeout timeout) { NPT_Timeout sleep = 0; do { m_Lock.Lock(); if (m_Value != value) { break; } m_Lock.Unlock(); NPT_System::GetSystem()->Sleep(50000); sleep += 50000; if (timeout != NPT_TIMEOUT_INFINITE && sleep > timeout) { return NPT_FAILURE; } } while (1); m_Lock.Unlock(); return NPT_SUCCESS; }