mirror of
https://github.com/pocoproject/poco.git
synced 2025-03-04 07:27:23 +01:00
- fixed PS build script environment vars generation
- fixed MongoDB 64-bit std::size_t warnings - added Thread::trySleep()/wakeUp() and tests
This commit is contained in:
parent
89fc463186
commit
46b5785d98
@ -58,6 +58,11 @@ public:
|
||||
virtual void run() = 0;
|
||||
/// Do whatever the thread needs to do. Must
|
||||
/// be overridden by subclasses.
|
||||
|
||||
protected:
|
||||
void sleep(long milliseconds);
|
||||
|
||||
void trySleep(long milliseconds);
|
||||
};
|
||||
|
||||
|
||||
|
@ -41,6 +41,7 @@
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/Event.h"
|
||||
#include "Poco/Mutex.h"
|
||||
|
||||
|
||||
@ -186,6 +187,23 @@ 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 fnctions should be used with
|
||||
/// understanding that this 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).
|
||||
|
||||
void wakeUp();
|
||||
/// Wakes up the thread which is in the state of interruptible
|
||||
/// sleep. For threads that are not suspended, calling this
|
||||
/// function has the effect of preventing the subsequent
|
||||
/// trySleep() call to put thread in a suspended state.
|
||||
|
||||
static void sleep(long milliseconds);
|
||||
/// Suspends the current thread for the specified
|
||||
/// amount of time.
|
||||
@ -220,6 +238,7 @@ private:
|
||||
int _id;
|
||||
std::string _name;
|
||||
ThreadLocalStorage* _pTLS;
|
||||
Event _event;
|
||||
mutable FastMutex _mutex;
|
||||
|
||||
friend class ThreadLocalStorage;
|
||||
|
@ -35,6 +35,7 @@
|
||||
|
||||
|
||||
#include "Poco/Runnable.h"
|
||||
#include "Poco/Thread.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@ -50,4 +51,16 @@ Runnable::~Runnable()
|
||||
}
|
||||
|
||||
|
||||
void Runnable::sleep(long milliseconds)
|
||||
{
|
||||
Thread::sleep(milliseconds);
|
||||
}
|
||||
|
||||
|
||||
void Runnable::trySleep(long milliseconds)
|
||||
{
|
||||
Thread::current()->trySleep(milliseconds);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
@ -62,6 +62,7 @@ Thread::Thread():
|
||||
_name(makeName()),
|
||||
_pTLS(0)
|
||||
{
|
||||
_event.reset();
|
||||
}
|
||||
|
||||
|
||||
@ -70,6 +71,7 @@ Thread::Thread(const std::string& name):
|
||||
_name(name),
|
||||
_pTLS(0)
|
||||
{
|
||||
_event.reset();
|
||||
}
|
||||
|
||||
|
||||
@ -122,6 +124,18 @@ bool Thread::tryJoin(long milliseconds)
|
||||
}
|
||||
|
||||
|
||||
void Thread::trySleep(long milliseconds)
|
||||
{
|
||||
_event.tryWait(milliseconds);
|
||||
_event.reset();
|
||||
}
|
||||
|
||||
void Thread::wakeUp()
|
||||
{
|
||||
_event.set();
|
||||
}
|
||||
|
||||
|
||||
ThreadLocalStorage& Thread::tls()
|
||||
{
|
||||
if (!_pTLS)
|
||||
|
@ -134,6 +134,33 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class TrySleepRunnable : public Runnable
|
||||
{
|
||||
public:
|
||||
TrySleepRunnable() : _counter(0)
|
||||
{
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
trySleep(300000);
|
||||
++_counter;
|
||||
trySleep(300000);
|
||||
++_counter;
|
||||
trySleep(10);
|
||||
++_counter;
|
||||
}
|
||||
|
||||
int counter() const
|
||||
{
|
||||
return _counter;
|
||||
}
|
||||
|
||||
private:
|
||||
int _counter;
|
||||
};
|
||||
|
||||
|
||||
ThreadTest::ThreadTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
@ -264,6 +291,33 @@ void ThreadTest::testNotJoin()
|
||||
}
|
||||
|
||||
|
||||
void ThreadTest::testTrySleep()
|
||||
{
|
||||
Thread thread;
|
||||
TrySleepRunnable r;
|
||||
assert(!thread.isRunning());
|
||||
assert(r.counter() == 0);
|
||||
thread.start(r);
|
||||
assert(thread.isRunning());
|
||||
assert(r.counter() == 0);
|
||||
Thread::sleep(100);
|
||||
assert(r.counter() == 0);
|
||||
thread.wakeUp();
|
||||
Thread::sleep(10);
|
||||
assert(r.counter() == 1);
|
||||
Thread::sleep(100);
|
||||
assert(r.counter() == 1);
|
||||
thread.wakeUp();
|
||||
Thread::sleep(10);
|
||||
assert(r.counter() == 2);
|
||||
Thread::sleep(100);
|
||||
assert(r.counter() == 3);
|
||||
assert(!thread.isRunning());
|
||||
thread.wakeUp();
|
||||
assert(!thread.isRunning());
|
||||
}
|
||||
|
||||
|
||||
void ThreadTest::testNotRun()
|
||||
{
|
||||
Thread thread;
|
||||
@ -389,6 +443,7 @@ CppUnit::Test* ThreadTest::suite()
|
||||
CppUnit_addTest(pSuite, ThreadTest, testNotJoin);
|
||||
CppUnit_addTest(pSuite, ThreadTest, testNotRun);
|
||||
CppUnit_addTest(pSuite, ThreadTest, testNotRunJoin);
|
||||
CppUnit_addTest(pSuite, ThreadTest, testTrySleep);
|
||||
CppUnit_addTest(pSuite, ThreadTest, testThreadTarget);
|
||||
CppUnit_addTest(pSuite, ThreadTest, testThreadFunction);
|
||||
CppUnit_addTest(pSuite, ThreadTest, testThreadStackSize);
|
||||
|
@ -54,6 +54,7 @@ public:
|
||||
void testNotJoin();
|
||||
void testNotRun();
|
||||
void testNotRunJoin();
|
||||
void testTrySleep();
|
||||
void testThreadTarget();
|
||||
void testThreadFunction();
|
||||
void testThreadStackSize();
|
||||
|
@ -68,7 +68,7 @@ public:
|
||||
protected:
|
||||
MessageHeader _header;
|
||||
|
||||
void messageLength(std::size_t length);
|
||||
void messageLength(Poco::Int32 length);
|
||||
/// Sets the message length in the message header
|
||||
};
|
||||
|
||||
@ -79,8 +79,9 @@ inline MessageHeader& Message::header()
|
||||
}
|
||||
|
||||
|
||||
inline void Message::messageLength(std::size_t length)
|
||||
inline void Message::messageLength(Poco::Int32 length)
|
||||
{
|
||||
poco_assert(length > 0);
|
||||
_header.setMessageLength(length);
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ void RequestMessage::send(std::ostream& ostr)
|
||||
buildRequest(requestWriter);
|
||||
requestWriter.flush();
|
||||
|
||||
messageLength(static_cast<std::size_t>(ss.tellp()));
|
||||
messageLength(static_cast<Poco::Int32>(ss.tellp()));
|
||||
|
||||
BinaryWriter socketWriter(ostr, BinaryWriter::LITTLE_ENDIAN_BYTE_ORDER);
|
||||
_header.write(socketWriter);
|
||||
|
18
buildwin.ps1
18
buildwin.ps1
@ -64,8 +64,12 @@ function Add-Env-Var([string] $lib, [string] $var)
|
||||
{
|
||||
if ((${Env:$var} -eq $null) -or (-not ${Env:$var}.Contains(${Env:$lib_$var"})))
|
||||
{
|
||||
${Env:$var} = ${Env:$lib_$var;$Env:$var}
|
||||
$libvar = "$lib" + "_" + "$var"
|
||||
$envvar = [Environment]::GetEnvironmentVariable($libvar, "Process")
|
||||
[Environment]::SetEnvironmentVariable($var, $envvar, "Process")
|
||||
$envvar = [Environment]::GetEnvironmentVariable($var, "Process")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -88,17 +92,20 @@ function Set-Environment
|
||||
}
|
||||
}
|
||||
|
||||
if (-Not $Env:PATH.Contains("$Env:POCO_BASE\bin64;$Env:POCO_BASE\bin;"))
|
||||
{ $Env:PATH = "$Env:POCO_BASE\bin64;$Env:POCO_BASE\bin;$Env:PATH" }
|
||||
|
||||
if ($openssl_base -eq '')
|
||||
{
|
||||
if ($platform -eq 'x64') { $script:openssl_base = 'C:\OpenSSL-Win64' }
|
||||
else { $script:openssl_base = 'C:\OpenSSL-Win32' }
|
||||
}
|
||||
|
||||
|
||||
$Env:OPENSSL_DIR = "$openssl_base"
|
||||
$Env:OPENSSL_INCLUDE = "$Env:OPENSSL_DIR\include"
|
||||
$Env:OPENSSL_LIB = "$Env:OPENSSL_DIR\lib;$Env:OPENSSL_DIR\lib\VC"
|
||||
Add-Env-Var "OPENSSL", "INCLUDE"
|
||||
Add-Env-Var "OPENSSL", "LIB"
|
||||
Add-Env-Var "OPENSSL" "INCLUDE"
|
||||
Add-Env-Var "OPENSSL" "LIB"
|
||||
|
||||
if ($mysql_base -ne '')
|
||||
{
|
||||
@ -109,9 +116,6 @@ function Set-Environment
|
||||
Add-Env-Var "MYSQL", "LIB"
|
||||
}
|
||||
|
||||
if (-Not $Env:PATH.Contains("$Env:POCO_BASE\bin64;$Env:POCO_BASE\bin;"))
|
||||
{ $Env:PATH = "$Env:POCO_BASE\bin64;$Env:POCO_BASE\bin;$Env:PATH" }
|
||||
|
||||
$vsct = "VS$($vs_version)COMNTOOLS"
|
||||
$vsdir = (Get-Item Env:$vsct).Value
|
||||
$Command = ''
|
||||
|
Loading…
x
Reference in New Issue
Block a user