summaryrefslogtreecommitdiff
path: root/scheduler.h
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2018-08-29 22:51:58 +0200
committertomsmeding <tom.smeding@gmail.com>2018-08-29 22:51:58 +0200
commit34ab0451bdd1e7496d607acb6ee209586ee7e86e (patch)
treeadf3a587581418bf381fd3b98f38fc55d192b0f2 /scheduler.h
parent9da9ab3e4517328ffe0fd0aaf23e2056b705ad76 (diff)
Rename job.{cpp,h} to scheduler
Diffstat (limited to 'scheduler.h')
-rw-r--r--scheduler.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/scheduler.h b/scheduler.h
new file mode 100644
index 0000000..95da7c7
--- /dev/null
+++ b/scheduler.h
@@ -0,0 +1,40 @@
+#pragma once
+
+#include <functional>
+#include <queue>
+#include <vector>
+#include <thread>
+#include <mutex>
+
+using namespace std;
+
+
+class Scheduler {
+ struct Job {
+ function<void()> callback;
+
+ Job(const function<void()> callback)
+ : callback(callback) {}
+ };
+
+ queue<Job*> jobs;
+ bool finishFlag = false;
+ mutex commMut;
+
+ bool hasJoined = false;
+
+ vector<thread> workers;
+
+ void workerEntry();
+
+public:
+ const int nthreads;
+
+ Scheduler(int nthreads);
+ ~Scheduler();
+
+ // func is run in child thread
+ void submit(const function<void()> &func);
+
+ void finish();
+};