From 4e9a583cd06270152f46a3efedbbe5af0cfe69e4 Mon Sep 17 00:00:00 2001 From: Guenter Obiltschnig Date: Tue, 1 May 2007 15:14:24 +0000 Subject: [PATCH] integrated latest changes from main rep --- Foundation/include/Poco/ActiveDispatcher.h | 9 +++++---- Foundation/include/Poco/ActiveMethod.h | 7 ++++--- Foundation/include/Poco/ActiveResult.h | 6 +++--- Foundation/include/Poco/ActiveRunnable.h | 18 ++++++++++++++---- Foundation/include/Poco/ActiveStarter.h | 11 +++++------ Foundation/src/ActiveDispatcher.cpp | 18 +++++++++--------- 6 files changed, 40 insertions(+), 29 deletions(-) diff --git a/Foundation/include/Poco/ActiveDispatcher.h b/Foundation/include/Poco/ActiveDispatcher.h index 664f22723..36bedb698 100644 --- a/Foundation/include/Poco/ActiveDispatcher.h +++ b/Foundation/include/Poco/ActiveDispatcher.h @@ -1,7 +1,7 @@ // // ActiveDispatcher.h // -// $Id: //poco/Main/Foundation/include/Poco/ActiveDispatcher.h#2 $ +// $Id: //poco/Main/Foundation/include/Poco/ActiveDispatcher.h#3 $ // // Library: Foundation // Package: Threading @@ -9,7 +9,7 @@ // // Definition of the ActiveDispatcher class. // -// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. +// Copyright (c) 2006-2007, Applied Informatics Software Engineering GmbH. // and Contributors. // // Permission is hereby granted, free of charge, to any person or organization @@ -44,6 +44,7 @@ #include "Poco/Runnable.h" #include "Poco/Thread.h" #include "Poco/ActiveStarter.h" +#include "Poco/ActiveRunnable.h" #include "Poco/NotificationQueue.h" @@ -102,7 +103,7 @@ public: virtual ~ActiveDispatcher(); /// Destroys the ActiveDispatcher. - void start(Runnable* pRunnable); + void start(ActiveRunnableBase::Ptr pRunnable); /// Adds the Runnable to the dispatch queue. void cancel(); @@ -124,7 +125,7 @@ class ActiveStarter /// for ActiveDispatcher. { public: - static void start(ActiveDispatcher* pOwner, Runnable* pRunnable) + static void start(ActiveDispatcher* pOwner, ActiveRunnableBase::Ptr pRunnable) { pOwner->start(pRunnable); } diff --git a/Foundation/include/Poco/ActiveMethod.h b/Foundation/include/Poco/ActiveMethod.h index f7ec1fa18..906e61ae0 100644 --- a/Foundation/include/Poco/ActiveMethod.h +++ b/Foundation/include/Poco/ActiveMethod.h @@ -1,7 +1,7 @@ // // ActiveMethod.h // -// $Id: //poco/Main/Foundation/include/Poco/ActiveMethod.h#2 $ +// $Id: //poco/Main/Foundation/include/Poco/ActiveMethod.h#3 $ // // Library: Foundation // Package: Threading @@ -9,7 +9,7 @@ // // Definition of the ActiveMethod class. // -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// Copyright (c) 2004-2007, Applied Informatics Software Engineering GmbH. // and Contributors. // // Permission is hereby granted, free of charge, to any person or organization @@ -44,6 +44,7 @@ #include "Poco/ActiveResult.h" #include "Poco/ActiveRunnable.h" #include "Poco/ActiveStarter.h" +#include "Poco/AutoPtr.h" namespace Poco { @@ -109,7 +110,7 @@ public: /// Invokes the ActiveMethod. { ActiveResultType result(new ActiveResultHolder()); - ActiveRunnableType* pRunnable = new ActiveRunnableType(_pOwner, _method, arg, result); + ActiveRunnableBase::Ptr pRunnable(new ActiveRunnableType(_pOwner, _method, arg, result)); StarterType::start(_pOwner, pRunnable); return result; } diff --git a/Foundation/include/Poco/ActiveResult.h b/Foundation/include/Poco/ActiveResult.h index 289763ba0..3fdd428b2 100644 --- a/Foundation/include/Poco/ActiveResult.h +++ b/Foundation/include/Poco/ActiveResult.h @@ -1,7 +1,7 @@ // // ActiveResult.h // -// $Id: //poco/Main/Foundation/include/Poco/ActiveResult.h#4 $ +// $Id: //poco/Main/Foundation/include/Poco/ActiveResult.h#5 $ // // Library: Foundation // Package: Threading @@ -9,7 +9,7 @@ // // Definition of the ActiveResult class. // -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// Copyright (c) 2004-2007, Applied Informatics Software Engineering GmbH. // and Contributors. // // Permission is hereby granted, free of charge, to any person or organization @@ -200,7 +200,7 @@ public: return *this; } - void swap(const ActiveResult& result) + void swap(ActiveResult& result) { using std::swap; swap(_pHolder, result._pHolder); diff --git a/Foundation/include/Poco/ActiveRunnable.h b/Foundation/include/Poco/ActiveRunnable.h index d77830960..52f8b5768 100644 --- a/Foundation/include/Poco/ActiveRunnable.h +++ b/Foundation/include/Poco/ActiveRunnable.h @@ -1,7 +1,7 @@ // // ActiveRunnable.h // -// $Id: //poco/Main/Foundation/include/Poco/ActiveRunnable.h#3 $ +// $Id: //poco/Main/Foundation/include/Poco/ActiveRunnable.h#4 $ // // Library: Foundation // Package: Threading @@ -9,7 +9,7 @@ // // Definition of the ActiveRunnable class. // -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// Copyright (c) 2004-2007, Applied Informatics Software Engineering GmbH. // and Contributors. // // Permission is hereby granted, free of charge, to any person or organization @@ -43,14 +43,24 @@ #include "Poco/Foundation.h" #include "Poco/ActiveResult.h" #include "Poco/Runnable.h" +#include "Poco/RefCountedObject.h" +#include "Poco/AutoPtr.h" #include "Poco/Exception.h" namespace Poco { +class ActiveRunnableBase: public Runnable, public RefCountedObject + /// The base class for all ActiveRunnable instantiations. +{ +public: + typedef AutoPtr Ptr; +}; + + template -class ActiveRunnable: public Runnable +class ActiveRunnable: public ActiveRunnableBase /// This class is used by ActiveMethod. /// See the ActiveMethod class for more information. { @@ -69,6 +79,7 @@ public: void run() { + ActiveRunnableBase::Ptr guard(this, false); // ensure automatic release when done try { _result.data(new ResultType((_pOwner->*_method)(_arg))); @@ -86,7 +97,6 @@ public: _result.error("unknown exception"); } _result.notify(); - delete this; } private: diff --git a/Foundation/include/Poco/ActiveStarter.h b/Foundation/include/Poco/ActiveStarter.h index d31f8ab72..86be3a7ca 100644 --- a/Foundation/include/Poco/ActiveStarter.h +++ b/Foundation/include/Poco/ActiveStarter.h @@ -1,7 +1,7 @@ // // ActiveStarter.h // -// $Id: //poco/Main/Foundation/include/Poco/ActiveStarter.h#2 $ +// $Id: //poco/Main/Foundation/include/Poco/ActiveStarter.h#3 $ // // Library: Foundation // Package: Threading @@ -9,7 +9,7 @@ // // Definition of the ActiveStarter class. // -// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. +// Copyright (c) 2006-2007, Applied Informatics Software Engineering GmbH. // and Contributors. // // Permission is hereby granted, free of charge, to any person or organization @@ -42,14 +42,12 @@ #include "Poco/Foundation.h" #include "Poco/ThreadPool.h" +#include "Poco/ActiveRunnable.h" namespace Poco { -class Runnable; - - template class ActiveStarter /// The default implementation of the StarterType @@ -58,9 +56,10 @@ class ActiveStarter /// thread pool. { public: - static void start(OwnerType* pOwner, Runnable* pRunnable) + static void start(OwnerType* pOwner, ActiveRunnableBase::Ptr pRunnable) { ThreadPool::defaultPool().start(*pRunnable); + pRunnable->duplicate(); // The runnable will release itself. } }; diff --git a/Foundation/src/ActiveDispatcher.cpp b/Foundation/src/ActiveDispatcher.cpp index c5e355a74..4fad088f6 100644 --- a/Foundation/src/ActiveDispatcher.cpp +++ b/Foundation/src/ActiveDispatcher.cpp @@ -1,13 +1,13 @@ // // ActiveDispatcher.cpp // -// $Id: //poco/Main/Foundation/src/ActiveDispatcher.cpp#4 $ +// $Id: //poco/Main/Foundation/src/ActiveDispatcher.cpp#5 $ // // Library: Foundation // Package: Threading // Module: ActiveObjects // -// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. +// Copyright (c) 2006-2007, Applied Informatics Software Engineering GmbH. // and Contributors. // // Permission is hereby granted, free of charge, to any person or organization @@ -47,18 +47,18 @@ namespace class MethodNotification: public Notification { public: - MethodNotification(Runnable* pRunnable): + MethodNotification(ActiveRunnableBase::Ptr pRunnable): _pRunnable(pRunnable) { } - Runnable* runnable() const + ActiveRunnableBase::Ptr runnable() const { return _pRunnable; } private: - Runnable* _pRunnable; + ActiveRunnableBase::Ptr _pRunnable; }; class StopNotification: public Notification @@ -92,7 +92,7 @@ ActiveDispatcher::~ActiveDispatcher() } -void ActiveDispatcher::start(Runnable* pRunnable) +void ActiveDispatcher::start(ActiveRunnableBase::Ptr pRunnable) { poco_check_ptr (pRunnable); @@ -113,9 +113,9 @@ void ActiveDispatcher::run() { MethodNotification* pMethodNf = dynamic_cast(pNf.get()); poco_check_ptr (pMethodNf); - Runnable* pRunnable = pMethodNf->runnable(); - poco_check_ptr (pRunnable); - pRunnable->run(); + ActiveRunnableBase::Ptr pRunnable = pMethodNf->runnable(); + pRunnable->duplicate(); // run will release + pRunnable->run(); pNf = _queue.waitDequeueNotification(); } }