mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-13 10:32:57 +01:00
- return bool from Thread::trySleep()
- updated documentiation - amended tests - updated CHANGELOG
This commit is contained in:
parent
0d58de8bc8
commit
63850e8778
19
CHANGELOG
19
CHANGELOG
@ -33,10 +33,27 @@ Release 1.5.3 (2014-05-xx)
|
||||
- fixed GH #380: SecureSocket+DialogSocket crashes with SIGSEGV when timeout occours
|
||||
- Improve RSADigestEngine, using Poco::Crypto::DigestEngine to calculate hash before signing
|
||||
- added Poco::PBKDF2Engine
|
||||
- Fixed GH #380: SecureSocket+DialogSocket crashes with SIGSEGV when timeout occours
|
||||
- added support for a 'Priority' attribute on cookies.
|
||||
- GH #386: fixed bug in MailMessage without content-transfer-encoding header
|
||||
- GH #384: ew hash algorithms support for RSADigestEngine
|
||||
|
||||
- fixed Clock overflow bug on Windows
|
||||
- Poco::ByteOrder now uses intrinsics, if available
|
||||
- CMake: added /bigobj option for msvc
|
||||
- Fix typo to restore Net/TestSuite_x64_vs120 build
|
||||
- correct path for CONFIGURE_FILE in CMakeLists.txt
|
||||
- Building Poco 1.5.2 for Synology RS812+ (Intel Atom) (honor POCO_NO_INOTIFY)
|
||||
- added WEC2013 support to buildwin.cmd and buildwin.ps1
|
||||
- HTMLForm: in URL encoding, percent-encode more characters
|
||||
- Fixed #include <linux/if.h> conflict with other libraries
|
||||
- Poco::Net::X509Certificate::verify() no longer uses DNS reverse lookups to validate host names
|
||||
- cert hostname validation is case insensitive and stricter for wildcard certificates
|
||||
- TCPServer: do not reduce the capacity of the default ThreadPool
|
||||
- added POCO_LOG_DEBUG flag
|
||||
- Zip: fixed a crash caused by an I/O error
|
||||
- added runtest script for windows
|
||||
- added SQlite Full Text Search support
|
||||
- added Thread::trySleep() and Thread::wakeUp()
|
||||
|
||||
Release 1.5.2 (2013-09-16)
|
||||
==========================
|
||||
|
@ -62,7 +62,7 @@ public:
|
||||
protected:
|
||||
void sleep(long milliseconds);
|
||||
|
||||
void trySleep(long milliseconds);
|
||||
bool trySleep(long milliseconds);
|
||||
};
|
||||
|
||||
|
||||
|
@ -187,16 +187,27 @@ public:
|
||||
bool isRunning() const;
|
||||
/// Returns true if the thread is running.
|
||||
|
||||
void trySleep(long milliseconds);
|
||||
/// Starts an interruptible sleep. Thread will remain suspended
|
||||
/// until (a) the timeout expires or (b) wakeUp() is called.
|
||||
/// The trySleep()/wakeUp() pair of functions should be used with
|
||||
/// understanding that this suspended state is not a true sleep,
|
||||
bool trySleep(long milliseconds);
|
||||
/// Starts an interruptible sleep. When trySleep() is called,
|
||||
/// the thread will remain suspended until:
|
||||
/// - the timeout expires or
|
||||
/// - wakeUp() is called
|
||||
///
|
||||
/// Function returns true if sleep attempt was completed, false
|
||||
/// if sleep was interrupted by a wakeUp() call.
|
||||
/// A frequent scenario where trySleep()/wakeUp() pair of functions
|
||||
/// is useful is with threads spending most of the time idle,
|
||||
/// with periodic activity between the idle times; trying to sleep
|
||||
/// (as opposed to sleeping) allows immediate ending of idle thread
|
||||
/// from the outside.
|
||||
///
|
||||
/// The trySleep() and wakeUp() calls should be used with
|
||||
/// understanding that the suspended state is not a true sleep,
|
||||
/// but rather a state of waiting for an event, with timeout
|
||||
/// expiration. This in essence means that calling wakeUp()
|
||||
/// before calling trySleep() will prevent the next trySleep()
|
||||
/// call to actually suspend the thread (which, in some scenarios,
|
||||
/// may be desirable behavior).
|
||||
/// expiration. This makes order of calls significantant; calling
|
||||
/// wakeUp() before calling trySleep() will prevent the next
|
||||
/// trySleep() call to actually suspend the thread (which, in
|
||||
/// some scenarios, may be desirable behavior).
|
||||
|
||||
void wakeUp();
|
||||
/// Wakes up the thread which is in the state of interruptible
|
||||
|
@ -57,9 +57,9 @@ void Runnable::sleep(long milliseconds)
|
||||
}
|
||||
|
||||
|
||||
void Runnable::trySleep(long milliseconds)
|
||||
bool Runnable::trySleep(long milliseconds)
|
||||
{
|
||||
Thread::current()->trySleep(milliseconds);
|
||||
return Thread::current()->trySleep(milliseconds);
|
||||
}
|
||||
|
||||
|
||||
|
@ -60,18 +60,18 @@ namespace Poco {
|
||||
Thread::Thread():
|
||||
_id(uniqueId()),
|
||||
_name(makeName()),
|
||||
_pTLS(0)
|
||||
_pTLS(0),
|
||||
_event(true)
|
||||
{
|
||||
_event.reset();
|
||||
}
|
||||
|
||||
|
||||
Thread::Thread(const std::string& name):
|
||||
_id(uniqueId()),
|
||||
_name(name),
|
||||
_pTLS(0)
|
||||
_pTLS(0),
|
||||
_event(true)
|
||||
{
|
||||
_event.reset();
|
||||
}
|
||||
|
||||
|
||||
@ -124,10 +124,9 @@ bool Thread::tryJoin(long milliseconds)
|
||||
}
|
||||
|
||||
|
||||
void Thread::trySleep(long milliseconds)
|
||||
bool Thread::trySleep(long milliseconds)
|
||||
{
|
||||
_event.tryWait(milliseconds);
|
||||
_event.reset();
|
||||
return !_event.tryWait(milliseconds);
|
||||
}
|
||||
|
||||
void Thread::wakeUp()
|
||||
|
@ -137,17 +137,17 @@ private:
|
||||
class TrySleepRunnable : public Runnable
|
||||
{
|
||||
public:
|
||||
TrySleepRunnable() : _counter(0)
|
||||
TrySleepRunnable() : _counter(0), _sleepy(true)
|
||||
{
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
trySleep(300000);
|
||||
_sleepy = !trySleep(300000);
|
||||
++_counter;
|
||||
trySleep(300000);
|
||||
_sleepy = !trySleep(300000);
|
||||
++_counter;
|
||||
trySleep(10);
|
||||
_sleepy = !trySleep(10);
|
||||
++_counter;
|
||||
}
|
||||
|
||||
@ -156,8 +156,14 @@ public:
|
||||
return _counter;
|
||||
}
|
||||
|
||||
bool isSleepy() const
|
||||
{
|
||||
return _sleepy;
|
||||
}
|
||||
|
||||
private:
|
||||
int _counter;
|
||||
bool _sleepy;
|
||||
};
|
||||
|
||||
|
||||
@ -295,23 +301,27 @@ void ThreadTest::testTrySleep()
|
||||
{
|
||||
Thread thread;
|
||||
TrySleepRunnable r;
|
||||
assert(r.isSleepy());
|
||||
assert(!thread.isRunning());
|
||||
assert(r.counter() == 0);
|
||||
thread.start(r);
|
||||
assert(thread.isRunning());
|
||||
assert(r.counter() == 0);
|
||||
assert(r.isSleepy());
|
||||
Thread::sleep(100);
|
||||
assert(r.counter() == 0);
|
||||
thread.wakeUp();
|
||||
Thread::sleep(10);
|
||||
assert(r.isSleepy());
|
||||
thread.wakeUp(); Thread::sleep(10);
|
||||
assert(r.counter() == 1);
|
||||
assert(r.isSleepy());
|
||||
Thread::sleep(100);
|
||||
assert(r.counter() == 1);
|
||||
thread.wakeUp();
|
||||
Thread::sleep(10);
|
||||
thread.wakeUp(); Thread::sleep(10);
|
||||
assert(r.counter() == 2);
|
||||
assert(r.isSleepy());
|
||||
Thread::sleep(100);
|
||||
assert(r.counter() == 3);
|
||||
assert(!r.isSleepy());
|
||||
assert(!thread.isRunning());
|
||||
thread.wakeUp();
|
||||
assert(!thread.isRunning());
|
||||
|
Loading…
Reference in New Issue
Block a user