Refactor templates & submit doc

This commit is contained in:
3 changed files with 21 additions and 9 deletions

View File

@@ -28,10 +28,10 @@
* @brief A Queue that supports operations that wait for the queue to become non-empty when retrieving an element, and
* wait for space to become available in the queue when storing an element.
*/
template <typename T>
template <typename T, template<typename = T, typename...> class Queue_ = std::deque >
class PIBlockingDequeue {
public:
typedef typename std::deque<T> QueueType;
typedef Queue_<T> QueueType;
/**
* @brief Constructor

View File

@@ -62,7 +62,7 @@ public:
FunctionWrapper& operator=(const FunctionWrapper&) = delete;
};
template <typename Thread_, template<typename> class Dequeue_>
template <typename Thread_ = PIThread, typename Dequeue_ = PIBlockingDequeue<FunctionWrapper>>
class PIThreadPoolExecutorTemplate {
public:
NO_COPY_CLASS(PIThreadPoolExecutorTemplate)
@@ -121,7 +121,7 @@ public:
protected:
std::atomic_bool isShutdown_;
Dequeue_<FunctionWrapper> taskQueue;
Dequeue_ taskQueue;
PIVector<Thread_*> threadPool;
template<typename Function>
@@ -145,15 +145,13 @@ protected:
}
};
typedef PIThreadPoolExecutorTemplate<PIThread, PIBlockingDequeue> PIThreadPoolExecutor;
typedef PIThreadPoolExecutorTemplate<> PIThreadPoolExecutor;
#ifdef DOXYGEN
/**
* @brief Thread pools address two different problems: they usually provide improved performance when executing large
* numbers of asynchronous tasks, due to reduced per-task invocation overhead, and they provide a means of bounding and
* managing the resources, including threads, consumed when executing a collection of tasks.
*
* TODO adapt documentation to template
*/
class PIThreadPoolExecutor {
public:
@@ -161,14 +159,28 @@ public:
virtual ~PIThreadPoolExecutor();
/**
* @brief Submits a Runnable task for execution and returns a Future representing that task. The Future's get method
* will return null upon successful completion.
*
* @tparam FunctionType - custom type of function with operator() and return type
* @tparam R - derived from FunctionType return type
*
* @param callable - the task to submit
* @return a future representing pending completion of the task
*/
std::future<R> submit(FunctionType&& callable);
/**
* @brief Executes the given task sometime in the future. The task execute in an existing pooled thread. If the task
* cannot be submitted for execution, either because this executor has been shutdown or because its capacity has been
* reached.
*
* @tparam FunctionType - custom type of function with operator() and return type
*
* @param runnable not empty function for thread pool execution
*/
void execute(const std::function<void()> & runnable);
void execute(FunctionType&& runnable);
/**
* @brief Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be

View File

@@ -48,7 +48,7 @@ public:
MOCK_METHOD0(remainingCapacity, size_t());
};
typedef PIThreadPoolExecutorTemplate<NiceMock<MockThread>, MockDeque> PIThreadPoolExecutorMoc_t;
typedef PIThreadPoolExecutorTemplate<NiceMock<MockThread>, MockDeque<FunctionWrapper>> PIThreadPoolExecutorMoc_t;
class PIThreadPoolExecutorMoc : public PIThreadPoolExecutorMoc_t {
public: