mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add timeout to Semaphore::wait
This commit is contained in:
@@ -17,23 +17,6 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
Semaphore::WaitingThread::WaitingThread ()
|
||||
: m_event (false) // auto-reset
|
||||
{
|
||||
}
|
||||
|
||||
void Semaphore::WaitingThread::wait ()
|
||||
{
|
||||
m_event.wait ();
|
||||
}
|
||||
|
||||
void Semaphore::WaitingThread::signal ()
|
||||
{
|
||||
m_event.signal ();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
||||
Semaphore::Semaphore (int initialCount)
|
||||
: m_counter (initialCount)
|
||||
{
|
||||
@@ -75,8 +58,10 @@ void Semaphore::signal (int amount)
|
||||
}
|
||||
}
|
||||
|
||||
void Semaphore::wait ()
|
||||
bool Semaphore::wait (int timeOutMilliseconds)
|
||||
{
|
||||
bool signaled = true;
|
||||
|
||||
// Always prepare the WaitingThread object first, either
|
||||
// from the delete list or through a new allocation.
|
||||
//
|
||||
@@ -107,11 +92,34 @@ void Semaphore::wait ()
|
||||
if (waitingThread != nullptr)
|
||||
{
|
||||
// Yes so do it.
|
||||
waitingThread->wait ();
|
||||
signaled = waitingThread->wait (timeOutMilliseconds);
|
||||
|
||||
// If the wait is satisfied, then we've been taken off the
|
||||
// waiting list so put waitingThread back in the delete list.
|
||||
//
|
||||
m_deleteList.push_front (waitingThread);
|
||||
}
|
||||
|
||||
return signaled;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
Semaphore::WaitingThread::WaitingThread ()
|
||||
: m_event (false) // auto-reset
|
||||
{
|
||||
}
|
||||
|
||||
bool Semaphore::WaitingThread::wait (int timeOutMilliseconds)
|
||||
{
|
||||
return m_event.wait (timeOutMilliseconds);
|
||||
}
|
||||
|
||||
void Semaphore::WaitingThread::signal ()
|
||||
{
|
||||
m_event.signal ();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// VFALCO TODO Unit Tests!
|
||||
|
||||
@@ -49,8 +49,12 @@ public:
|
||||
void signal (int amount = 1);
|
||||
|
||||
/** Wait for a resource.
|
||||
|
||||
A negative time-out value means that the method will wait indefinitely.
|
||||
|
||||
@returns true if the event has been signalled, false if the timeout expires.
|
||||
*/
|
||||
void wait ();
|
||||
bool wait (int timeOutMilliseconds = -1);
|
||||
|
||||
private:
|
||||
class WaitingThread
|
||||
@@ -60,7 +64,7 @@ private:
|
||||
public:
|
||||
WaitingThread ();
|
||||
|
||||
void wait ();
|
||||
bool wait (int timeOutMilliseconds);
|
||||
void signal ();
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user