summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2016-07-08 14:29:53 +0200
committerNoel Grandin <noelgrandin@gmail.com>2016-07-18 06:49:09 +0000
commit76ad32bec8e2c00c21247041b16d9e09e73d2504 (patch)
tree7b2b1277151bc7904ff63684ebd7e3d6d8a7d661 /include
parent9bf9f88e4c7e0b182ec6d8b4aefb7d735bb0653b (diff)
add tagging to ThreadTasks so we don't need more one pool
If more than one place in the code submits tasks to the shared pool, then waitTillDone() becomes unreliable. Add a tagging mechanism, so different callsites can wait on different sets of tasks. Also try to protect our worker threads against exceptions from the thread tasks code. Change-Id: Idde664ab50008d31a2dd73910bb22f50e62ae22f Reviewed-on: https://gerrit.libreoffice.org/27042 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'include')
-rw-r--r--include/comphelper/threadpool.hxx19
1 files changed, 15 insertions, 4 deletions
diff --git a/include/comphelper/threadpool.hxx b/include/comphelper/threadpool.hxx
index 2f726f0b406f..93f6b59ee9de 100644
--- a/include/comphelper/threadpool.hxx
+++ b/include/comphelper/threadpool.hxx
@@ -15,17 +15,24 @@
#include <osl/mutex.hxx>
#include <osl/conditn.hxx>
#include <rtl/ref.hxx>
-#include <vector>
#include <comphelper/comphelperdllapi.h>
+#include <vector>
+#include <memory>
namespace comphelper
{
+class ThreadTaskTag;
+class ThreadPool;
class COMPHELPER_DLLPUBLIC ThreadTask
{
+friend class ThreadPool;
+ std::shared_ptr<ThreadTaskTag> mpTag;
public:
+ ThreadTask(const std::shared_ptr<ThreadTaskTag>& pTag);
virtual ~ThreadTask() {}
virtual void doWork() = 0;
+ const std::shared_ptr<ThreadTaskTag>& getTag() { return mpTag; }
};
/// A very basic thread pool implementation
@@ -36,20 +43,24 @@ public:
/// count for the CPU
static ThreadPool& getSharedOptimalPool();
+ static std::shared_ptr<ThreadTaskTag> createThreadTaskTag();
+
+ static bool isTaskTagDone(const std::shared_ptr<ThreadTaskTag>&);
+
/// returns a configurable max-concurrency
/// limit to avoid spawning an unnecessarily
/// large number of threads on high-core boxes.
/// MAX_CONCURRENCY envar controls the cap.
static sal_Int32 getPreferredConcurrency();
- ThreadPool( sal_Int32 nWorkers );
+ ThreadPool( sal_Int32 nWorkers );
virtual ~ThreadPool();
/// push a new task onto the work queue
void pushTask( ThreadTask *pTask /* takes ownership */ );
- /// wait until all queued tasks are completed
- void waitUntilEmpty();
+ /// wait until all queued tasks associated with the tag are completed
+ void waitUntilDone(const std::shared_ptr<ThreadTaskTag>&);
/// return the number of live worker threads
sal_Int32 getWorkerCount() const { return maWorkers.size(); }