mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-15 07:14:46 +02:00
integrated latest changes from main rep
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// ActiveDispatcher.h
|
// ActiveDispatcher.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/Main/Foundation/include/Poco/ActiveDispatcher.h#2 $
|
// $Id: //poco/Main/Foundation/include/Poco/ActiveDispatcher.h#3 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Threading
|
// Package: Threading
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
//
|
//
|
||||||
// Definition of the ActiveDispatcher class.
|
// Definition of the ActiveDispatcher class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006-2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
@@ -44,6 +44,7 @@
|
|||||||
#include "Poco/Runnable.h"
|
#include "Poco/Runnable.h"
|
||||||
#include "Poco/Thread.h"
|
#include "Poco/Thread.h"
|
||||||
#include "Poco/ActiveStarter.h"
|
#include "Poco/ActiveStarter.h"
|
||||||
|
#include "Poco/ActiveRunnable.h"
|
||||||
#include "Poco/NotificationQueue.h"
|
#include "Poco/NotificationQueue.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -102,7 +103,7 @@ public:
|
|||||||
virtual ~ActiveDispatcher();
|
virtual ~ActiveDispatcher();
|
||||||
/// Destroys the ActiveDispatcher.
|
/// Destroys the ActiveDispatcher.
|
||||||
|
|
||||||
void start(Runnable* pRunnable);
|
void start(ActiveRunnableBase::Ptr pRunnable);
|
||||||
/// Adds the Runnable to the dispatch queue.
|
/// Adds the Runnable to the dispatch queue.
|
||||||
|
|
||||||
void cancel();
|
void cancel();
|
||||||
@@ -124,7 +125,7 @@ class ActiveStarter<ActiveDispatcher>
|
|||||||
/// for ActiveDispatcher.
|
/// for ActiveDispatcher.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void start(ActiveDispatcher* pOwner, Runnable* pRunnable)
|
static void start(ActiveDispatcher* pOwner, ActiveRunnableBase::Ptr pRunnable)
|
||||||
{
|
{
|
||||||
pOwner->start(pRunnable);
|
pOwner->start(pRunnable);
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// ActiveMethod.h
|
// ActiveMethod.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/Main/Foundation/include/Poco/ActiveMethod.h#2 $
|
// $Id: //poco/Main/Foundation/include/Poco/ActiveMethod.h#3 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Threading
|
// Package: Threading
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
//
|
//
|
||||||
// Definition of the ActiveMethod class.
|
// 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.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
@@ -44,6 +44,7 @@
|
|||||||
#include "Poco/ActiveResult.h"
|
#include "Poco/ActiveResult.h"
|
||||||
#include "Poco/ActiveRunnable.h"
|
#include "Poco/ActiveRunnable.h"
|
||||||
#include "Poco/ActiveStarter.h"
|
#include "Poco/ActiveStarter.h"
|
||||||
|
#include "Poco/AutoPtr.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
@@ -109,7 +110,7 @@ public:
|
|||||||
/// Invokes the ActiveMethod.
|
/// Invokes the ActiveMethod.
|
||||||
{
|
{
|
||||||
ActiveResultType result(new ActiveResultHolder<ResultType>());
|
ActiveResultType result(new ActiveResultHolder<ResultType>());
|
||||||
ActiveRunnableType* pRunnable = new ActiveRunnableType(_pOwner, _method, arg, result);
|
ActiveRunnableBase::Ptr pRunnable(new ActiveRunnableType(_pOwner, _method, arg, result));
|
||||||
StarterType::start(_pOwner, pRunnable);
|
StarterType::start(_pOwner, pRunnable);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// ActiveResult.h
|
// ActiveResult.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/Main/Foundation/include/Poco/ActiveResult.h#4 $
|
// $Id: //poco/Main/Foundation/include/Poco/ActiveResult.h#5 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Threading
|
// Package: Threading
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
//
|
//
|
||||||
// Definition of the ActiveResult class.
|
// 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.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
@@ -200,7 +200,7 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void swap(const ActiveResult& result)
|
void swap(ActiveResult& result)
|
||||||
{
|
{
|
||||||
using std::swap;
|
using std::swap;
|
||||||
swap(_pHolder, result._pHolder);
|
swap(_pHolder, result._pHolder);
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// ActiveRunnable.h
|
// ActiveRunnable.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/Main/Foundation/include/Poco/ActiveRunnable.h#3 $
|
// $Id: //poco/Main/Foundation/include/Poco/ActiveRunnable.h#4 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Threading
|
// Package: Threading
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
//
|
//
|
||||||
// Definition of the ActiveRunnable class.
|
// 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.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
@@ -43,14 +43,24 @@
|
|||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "Poco/ActiveResult.h"
|
#include "Poco/ActiveResult.h"
|
||||||
#include "Poco/Runnable.h"
|
#include "Poco/Runnable.h"
|
||||||
|
#include "Poco/RefCountedObject.h"
|
||||||
|
#include "Poco/AutoPtr.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
|
class ActiveRunnableBase: public Runnable, public RefCountedObject
|
||||||
|
/// The base class for all ActiveRunnable instantiations.
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef AutoPtr<ActiveRunnableBase> Ptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class ResultType, class ArgType, class OwnerType>
|
template <class ResultType, class ArgType, class OwnerType>
|
||||||
class ActiveRunnable: public Runnable
|
class ActiveRunnable: public ActiveRunnableBase
|
||||||
/// This class is used by ActiveMethod.
|
/// This class is used by ActiveMethod.
|
||||||
/// See the ActiveMethod class for more information.
|
/// See the ActiveMethod class for more information.
|
||||||
{
|
{
|
||||||
@@ -69,6 +79,7 @@ public:
|
|||||||
|
|
||||||
void run()
|
void run()
|
||||||
{
|
{
|
||||||
|
ActiveRunnableBase::Ptr guard(this, false); // ensure automatic release when done
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_result.data(new ResultType((_pOwner->*_method)(_arg)));
|
_result.data(new ResultType((_pOwner->*_method)(_arg)));
|
||||||
@@ -86,7 +97,6 @@ public:
|
|||||||
_result.error("unknown exception");
|
_result.error("unknown exception");
|
||||||
}
|
}
|
||||||
_result.notify();
|
_result.notify();
|
||||||
delete this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// ActiveStarter.h
|
// ActiveStarter.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/Main/Foundation/include/Poco/ActiveStarter.h#2 $
|
// $Id: //poco/Main/Foundation/include/Poco/ActiveStarter.h#3 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Threading
|
// Package: Threading
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
//
|
//
|
||||||
// Definition of the ActiveStarter class.
|
// Definition of the ActiveStarter class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006-2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
@@ -42,14 +42,12 @@
|
|||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "Poco/ThreadPool.h"
|
#include "Poco/ThreadPool.h"
|
||||||
|
#include "Poco/ActiveRunnable.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
class Runnable;
|
|
||||||
|
|
||||||
|
|
||||||
template <class OwnerType>
|
template <class OwnerType>
|
||||||
class ActiveStarter
|
class ActiveStarter
|
||||||
/// The default implementation of the StarterType
|
/// The default implementation of the StarterType
|
||||||
@@ -58,9 +56,10 @@ class ActiveStarter
|
|||||||
/// thread pool.
|
/// thread pool.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void start(OwnerType* pOwner, Runnable* pRunnable)
|
static void start(OwnerType* pOwner, ActiveRunnableBase::Ptr pRunnable)
|
||||||
{
|
{
|
||||||
ThreadPool::defaultPool().start(*pRunnable);
|
ThreadPool::defaultPool().start(*pRunnable);
|
||||||
|
pRunnable->duplicate(); // The runnable will release itself.
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -1,13 +1,13 @@
|
|||||||
//
|
//
|
||||||
// ActiveDispatcher.cpp
|
// ActiveDispatcher.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/Main/Foundation/src/ActiveDispatcher.cpp#4 $
|
// $Id: //poco/Main/Foundation/src/ActiveDispatcher.cpp#5 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Threading
|
// Package: Threading
|
||||||
// Module: ActiveObjects
|
// Module: ActiveObjects
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006-2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
@@ -47,18 +47,18 @@ namespace
|
|||||||
class MethodNotification: public Notification
|
class MethodNotification: public Notification
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MethodNotification(Runnable* pRunnable):
|
MethodNotification(ActiveRunnableBase::Ptr pRunnable):
|
||||||
_pRunnable(pRunnable)
|
_pRunnable(pRunnable)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Runnable* runnable() const
|
ActiveRunnableBase::Ptr runnable() const
|
||||||
{
|
{
|
||||||
return _pRunnable;
|
return _pRunnable;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Runnable* _pRunnable;
|
ActiveRunnableBase::Ptr _pRunnable;
|
||||||
};
|
};
|
||||||
|
|
||||||
class StopNotification: public Notification
|
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);
|
poco_check_ptr (pRunnable);
|
||||||
|
|
||||||
@@ -113,8 +113,8 @@ void ActiveDispatcher::run()
|
|||||||
{
|
{
|
||||||
MethodNotification* pMethodNf = dynamic_cast<MethodNotification*>(pNf.get());
|
MethodNotification* pMethodNf = dynamic_cast<MethodNotification*>(pNf.get());
|
||||||
poco_check_ptr (pMethodNf);
|
poco_check_ptr (pMethodNf);
|
||||||
Runnable* pRunnable = pMethodNf->runnable();
|
ActiveRunnableBase::Ptr pRunnable = pMethodNf->runnable();
|
||||||
poco_check_ptr (pRunnable);
|
pRunnable->duplicate(); // run will release
|
||||||
pRunnable->run();
|
pRunnable->run();
|
||||||
pNf = _queue.waitDequeueNotification();
|
pNf = _queue.waitDequeueNotification();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user