mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-18 03:29:47 +02:00
remove sleep calls from Runnable
This commit is contained in:
@@ -58,11 +58,6 @@ public:
|
|||||||
virtual void run() = 0;
|
virtual void run() = 0;
|
||||||
/// Do whatever the thread needs to do. Must
|
/// Do whatever the thread needs to do. Must
|
||||||
/// be overridden by subclasses.
|
/// be overridden by subclasses.
|
||||||
|
|
||||||
protected:
|
|
||||||
void sleep(long milliseconds);
|
|
||||||
|
|
||||||
bool trySleep(long milliseconds);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -187,7 +187,7 @@ public:
|
|||||||
bool isRunning() const;
|
bool isRunning() const;
|
||||||
/// Returns true if the thread is running.
|
/// Returns true if the thread is running.
|
||||||
|
|
||||||
bool trySleep(long milliseconds);
|
static bool trySleep(long milliseconds);
|
||||||
/// Starts an interruptible sleep. When trySleep() is called,
|
/// Starts an interruptible sleep. When trySleep() is called,
|
||||||
/// the thread will remain suspended until:
|
/// the thread will remain suspended until:
|
||||||
/// - the timeout expires or
|
/// - the timeout expires or
|
||||||
|
@@ -51,16 +51,4 @@ Runnable::~Runnable()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Runnable::sleep(long milliseconds)
|
|
||||||
{
|
|
||||||
Thread::sleep(milliseconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Runnable::trySleep(long milliseconds)
|
|
||||||
{
|
|
||||||
return Thread::current()->trySleep(milliseconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
@@ -126,9 +126,12 @@ bool Thread::tryJoin(long milliseconds)
|
|||||||
|
|
||||||
bool Thread::trySleep(long milliseconds)
|
bool Thread::trySleep(long milliseconds)
|
||||||
{
|
{
|
||||||
return !_event.tryWait(milliseconds);
|
Thread* pT = Thread::current();
|
||||||
|
poco_check_ptr(pT);
|
||||||
|
return !(pT->_event.tryWait(milliseconds));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Thread::wakeUp()
|
void Thread::wakeUp()
|
||||||
{
|
{
|
||||||
_event.set();
|
_event.set();
|
||||||
|
@@ -143,11 +143,11 @@ public:
|
|||||||
|
|
||||||
void run()
|
void run()
|
||||||
{
|
{
|
||||||
_sleepy = !trySleep(300000);
|
_sleepy = !Thread::trySleep(300000);
|
||||||
++_counter;
|
++_counter;
|
||||||
_sleepy = !trySleep(300000);
|
_sleepy = !Thread::trySleep(300000);
|
||||||
++_counter;
|
++_counter;
|
||||||
_sleepy = !trySleep(10);
|
_sleepy = !Thread::trySleep(10);
|
||||||
++_counter;
|
++_counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user