mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-27 02:53:10 +01:00
Add thread affinity support to taskmanager
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include "Poco/NotificationCenter.h"
|
||||
#include "Poco/Timestamp.h"
|
||||
#include "Poco/ThreadPool.h"
|
||||
#include <list>
|
||||
|
||||
|
||||
@@ -33,7 +34,6 @@ namespace Poco {
|
||||
|
||||
|
||||
class Notification;
|
||||
class ThreadPool;
|
||||
class Exception;
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
typedef AutoPtr<Task> TaskPtr;
|
||||
typedef std::list<TaskPtr> TaskList;
|
||||
|
||||
TaskManager();
|
||||
TaskManager(ThreadPool::ThreadAffinityPolicy affinityPolicy = ThreadPool::OS_DEFAULT);
|
||||
/// Creates the TaskManager, using the
|
||||
/// default ThreadPool.
|
||||
|
||||
@@ -63,10 +63,10 @@ public:
|
||||
~TaskManager();
|
||||
/// Destroys the TaskManager.
|
||||
|
||||
void start(Task* pTask);
|
||||
void start(Task* pTask, int cpu = -1);
|
||||
/// Starts the given task in a thread obtained
|
||||
/// from the thread pool.
|
||||
///
|
||||
/// from the thread pool,
|
||||
/// on specified cpu.
|
||||
/// The TaskManager takes ownership of the Task object
|
||||
/// and deletes it when it it finished.
|
||||
|
||||
|
||||
@@ -100,6 +100,12 @@ public:
|
||||
int getStackSize() const;
|
||||
/// Returns the stack size used to create new threads.
|
||||
|
||||
void setAffinityPolicy(ThreadAffinityPolicy affinityPolicy);
|
||||
/// Sets the thread affinity policy for newly created threads
|
||||
|
||||
ThreadAffinityPolicy getAffinityPolicy();
|
||||
/// Returns the thread affinity policy used to create new thread
|
||||
|
||||
int used() const;
|
||||
/// Returns the number of currently used threads.
|
||||
|
||||
@@ -165,7 +171,7 @@ public:
|
||||
/// or an empty string if no name has been
|
||||
/// specified in the constructor.
|
||||
|
||||
static ThreadPool& defaultPool();
|
||||
static ThreadPool& defaultPool(ThreadAffinityPolicy affinityPolicy = OS_DEFAULT);
|
||||
/// Returns a reference to the default
|
||||
/// thread pool.
|
||||
|
||||
@@ -209,6 +215,15 @@ inline int ThreadPool::getStackSize() const
|
||||
return _stackSize;
|
||||
}
|
||||
|
||||
inline void ThreadPool::setAffinityPolicy(ThreadPool::ThreadAffinityPolicy affinityPolicy)
|
||||
{
|
||||
_affinityPolicy = affinityPolicy;
|
||||
}
|
||||
|
||||
inline ThreadPool::ThreadAffinityPolicy ThreadPool::getAffinityPolicy()
|
||||
{
|
||||
return _affinityPolicy;
|
||||
}
|
||||
|
||||
inline const std::string& ThreadPool::name() const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user