diff --git a/Foundation/include/Poco/ActiveResult.h b/Foundation/include/Poco/ActiveResult.h index c71a39bd8..2c02d4c2f 100644 --- a/Foundation/include/Poco/ActiveResult.h +++ b/Foundation/include/Poco/ActiveResult.h @@ -43,7 +43,7 @@ public: ActiveResultHolder(): _pData(0), _pExc(0), - _event(false) + _event(Event::EVENT_MANUALRESET) /// Creates an ActiveResultHolder. { } @@ -149,7 +149,7 @@ class ActiveResultHolder: public RefCountedObject public: ActiveResultHolder(): _pExc(0), - _event(false) + _event(Event::EVENT_MANUALRESET) /// Creates an ActiveResultHolder. { } diff --git a/Foundation/include/Poco/Activity.h b/Foundation/include/Poco/Activity.h index 3aded9fca..a466f8a3f 100644 --- a/Foundation/include/Poco/Activity.h +++ b/Foundation/include/Poco/Activity.h @@ -84,7 +84,7 @@ public: _runnable(*pOwner, method), _stopped(true), _running(false), - _done(false) + _done(Event::EVENT_MANUALRESET) /// Creates the activity. Call start() to /// start it. { diff --git a/Foundation/include/Poco/Event.h b/Foundation/include/Poco/Event.h index dcb9e53de..73956909a 100644 --- a/Foundation/include/Poco/Event.h +++ b/Foundation/include/Poco/Event.h @@ -46,11 +46,23 @@ class Foundation_API Event: private EventImpl /// for an event to become signalled. { public: - Event(bool autoReset = true); + enum EventType + { + EVENT_MANUALRESET = EVENT_MANUALRESET_IMPL, /// Manual reset event + EVENT_AUTORESET = EVENT_AUTORESET_IMPL, /// Auto-reset event + }; + + Event(EventType type = EVENT_AUTORESET); + /// Creates the event. If type is EVENT_AUTORESET, + /// the event is automatically reset after + /// a wait() successfully returns. + + Event(bool autoReset); + //@ deprecated /// Creates the event. If autoReset is true, /// the event is automatically reset after /// a wait() successfully returns. - + ~Event(); /// Destroys the event. diff --git a/Foundation/include/Poco/Event_POSIX.h b/Foundation/include/Poco/Event_POSIX.h index 1ebd2aa21..7c79140ae 100644 --- a/Foundation/include/Poco/Event_POSIX.h +++ b/Foundation/include/Poco/Event_POSIX.h @@ -31,8 +31,15 @@ namespace Poco { class Foundation_API EventImpl { +public: + enum EventTypeImpl + { + EVENT_MANUALRESET_IMPL, + EVENT_AUTORESET_IMPL, + }; + protected: - EventImpl(bool autoReset); + EventImpl(EventTypeImpl type); ~EventImpl(); void setImpl(); void waitImpl(); diff --git a/Foundation/include/Poco/Event_VX.h b/Foundation/include/Poco/Event_VX.h index f1bf90487..6b7d8d87b 100644 --- a/Foundation/include/Poco/Event_VX.h +++ b/Foundation/include/Poco/Event_VX.h @@ -30,8 +30,15 @@ namespace Poco { class Foundation_API EventImpl { +public: + enum EventTypeImpl + { + EVENT_MANUALRESET_IMPL, + EVENT_AUTORESET_IMPL, + }; + protected: - EventImpl(bool autoReset); + EventImpl(EventTypeImpl type); ~EventImpl(); void setImpl(); void waitImpl(); diff --git a/Foundation/include/Poco/Event_WIN32.h b/Foundation/include/Poco/Event_WIN32.h index 94f03d2ba..52ab66ec7 100644 --- a/Foundation/include/Poco/Event_WIN32.h +++ b/Foundation/include/Poco/Event_WIN32.h @@ -30,8 +30,15 @@ namespace Poco { class Foundation_API EventImpl { +public: + enum EventTypeImpl + { + EVENT_MANUALRESET_IMPL, + EVENT_AUTORESET_IMPL, + }; + protected: - EventImpl(bool autoReset); + EventImpl(EventTypeImpl type); ~EventImpl(); void setImpl(); void waitImpl(); diff --git a/Foundation/include/Poco/Thread_POSIX.h b/Foundation/include/Poco/Thread_POSIX.h index 5bfae4a28..7c2f1c55b 100644 --- a/Foundation/include/Poco/Thread_POSIX.h +++ b/Foundation/include/Poco/Thread_POSIX.h @@ -120,7 +120,7 @@ private: thread(0), prio(PRIO_NORMAL_IMPL), policy(SCHED_OTHER), - done(false), + done(Event::EVENT_MANUALRESET), stackSize(POCO_THREAD_STACK_SIZE), started(false), joined(false) diff --git a/Foundation/samples/Benchmark/src/Benchmark.cpp b/Foundation/samples/Benchmark/src/Benchmark.cpp index 02b843c5b..3c57a0b18 100644 --- a/Foundation/samples/Benchmark/src/Benchmark.cpp +++ b/Foundation/samples/Benchmark/src/Benchmark.cpp @@ -50,12 +50,12 @@ int main(int argc, char** argv) { Poco::Mutex mtx(Poco::Mutex::MUTEX_RECURSIVE); - Benchmark(mtx, "Mutex(true)"); + Benchmark(mtx, "Mutex(MUTEX_RECURSIVE)"); } { Poco::Mutex mtx(Poco::Mutex::MUTEX_NONRECURSIVE); - Benchmark(mtx, "Mutex(false)"); + Benchmark(mtx, "Mutex(MUTEX_NONRECURSIVE)"); } { diff --git a/Foundation/src/Event.cpp b/Foundation/src/Event.cpp index cf4a52f1c..d692652b5 100644 --- a/Foundation/src/Event.cpp +++ b/Foundation/src/Event.cpp @@ -29,7 +29,12 @@ namespace Poco { -Event::Event(bool autoReset): EventImpl(autoReset) +Event::Event(EventType type): EventImpl((EventTypeImpl) type) +{ +} + + +Event::Event(bool autoReset): EventImpl(autoReset ? EVENT_AUTORESET_IMPL : EVENT_MANUALRESET_IMPL) { } diff --git a/Foundation/src/Event_POSIX.cpp b/Foundation/src/Event_POSIX.cpp index 8dd8ce907..ef67e22fd 100644 --- a/Foundation/src/Event_POSIX.cpp +++ b/Foundation/src/Event_POSIX.cpp @@ -26,7 +26,7 @@ namespace Poco { -EventImpl::EventImpl(bool autoReset): _auto(autoReset), _state(false) +EventImpl::EventImpl(EventTypeImpl type): _auto(type == EVENT_AUTORESET_IMPL), _state(false) { #if defined(POCO_VXWORKS) // This workaround is for VxWorks 5.x where diff --git a/Foundation/src/Event_VX.cpp b/Foundation/src/Event_VX.cpp index 6324e901f..086182cce 100644 --- a/Foundation/src/Event_VX.cpp +++ b/Foundation/src/Event_VX.cpp @@ -21,7 +21,7 @@ namespace Poco { -EventImpl::EventImpl(bool autoReset): _auto(autoReset), _state(false) +EventImpl::EventImpl(EventTypeImpl type): _auto(type == EVENT_AUTORESET_IMPL), _state(false) { _sem = semCCreate(SEM_Q_PRIORITY, 0); if (_sem == 0) diff --git a/Foundation/src/Event_WIN32.cpp b/Foundation/src/Event_WIN32.cpp index 10f0f1308..f5459ecf1 100644 --- a/Foundation/src/Event_WIN32.cpp +++ b/Foundation/src/Event_WIN32.cpp @@ -20,9 +20,9 @@ namespace Poco { -EventImpl::EventImpl(bool autoReset) +EventImpl::EventImpl(EventTypeImpl type) { - _event = CreateEventW(NULL, autoReset ? FALSE : TRUE, FALSE, NULL); + _event = CreateEventW(NULL, type == EVENT_AUTORESET_IMPL ? FALSE : TRUE, FALSE, NULL); if (!_event) throw SystemException("cannot create event"); } diff --git a/Foundation/src/Task.cpp b/Foundation/src/Task.cpp index c8289d1ec..e085eefaa 100644 --- a/Foundation/src/Task.cpp +++ b/Foundation/src/Task.cpp @@ -27,7 +27,7 @@ Task::Task(const std::string& name): _pOwner(0), _progress(0), _state(TASK_IDLE), - _cancelEvent(false) + _cancelEvent(Event::EVENT_MANUALRESET) { } diff --git a/Foundation/src/Thread.cpp b/Foundation/src/Thread.cpp index e4a87dad0..8c518ba5b 100644 --- a/Foundation/src/Thread.cpp +++ b/Foundation/src/Thread.cpp @@ -93,7 +93,7 @@ Thread::Thread(): _id(uniqueId()), _name(makeName()), _pTLS(0), - _event(true) + _event() { } @@ -102,7 +102,7 @@ Thread::Thread(const std::string& name): _id(uniqueId()), _name(name), _pTLS(0), - _event(true) + _event() { } diff --git a/Foundation/src/ThreadPool.cpp b/Foundation/src/ThreadPool.cpp index 32af4d9d8..e8df55c9d 100644 --- a/Foundation/src/ThreadPool.cpp +++ b/Foundation/src/ThreadPool.cpp @@ -65,7 +65,10 @@ PooledThread::PooledThread(const std::string& name, int stackSize): _pTarget(0), _name(name), _thread(name), - _targetCompleted(false) + _targetReady(), + _targetCompleted(Event::EVENT_MANUALRESET), + _started(), + _mutex() { poco_assert_dbg (stackSize >= 0); _thread.setStackSize(stackSize); diff --git a/Foundation/testsuite/src/ThreadPoolTest.cpp b/Foundation/testsuite/src/ThreadPoolTest.cpp index 59da2160b..3083f90f0 100644 --- a/Foundation/testsuite/src/ThreadPoolTest.cpp +++ b/Foundation/testsuite/src/ThreadPoolTest.cpp @@ -19,12 +19,13 @@ #include "Poco/Thread.h" +using Poco::Event; using Poco::ThreadPool; using Poco::RunnableAdapter; using Poco::Thread; -ThreadPoolTest::ThreadPoolTest(const std::string& name): CppUnit::TestCase(name), _event(false) +ThreadPoolTest::ThreadPoolTest(const std::string& name): CppUnit::TestCase(name), _event(Event::EVENT_MANUALRESET) { }