This commit is contained in:
Matthias
2017-07-24 16:27:50 +02:00
parent ec80b339e2
commit 3d4bb80dae
46 changed files with 1388 additions and 158 deletions
@@ -5,6 +5,8 @@
#include <set>
#include <queue>
#include <mutex>
#include <map>
#include <memory>
#include <condition_variable>
namespace wfr {
@@ -18,16 +20,18 @@ namespace execution {
class ExecutionManager;
class ExecutionHandle;
class PThreadBackend;
class PThreadWorker;
class PThreadBackend {
class PThreadDevice {
private:
std::mutex objMutex;
std::condition_variable workerCondVar;
ExecutionManager& manager;
PThreadBackend& backend;
std::set<PThreadWorker*> workers;
std::set<PThreadWorker*> idleWorkers;
std::set<resource::ComputingResource*> resources;
resource::ComputingResource* resource;
std::queue<ExecutionHandle*> taskQueue;
wfr_size_t maxWorkerCount;
wfr_size_t currentTotalWorkerCount = 0;
@@ -37,19 +41,47 @@ private:
bool isShutdown = false;
public:
PThreadBackend(ExecutionManager& manager, const std::set<resource::ComputingResource*>& resources);
virtual ~PThreadBackend();
PThreadDevice(PThreadBackend& backend, resource::ComputingResource* resource);
virtual ~PThreadDevice();
void notifyExecutionHandleUpdate(ExecutionHandle& handle, PThreadWorker& worker);
bool queueTaskExecution(ExecutionHandle& handle);
wfr_id_t getDeviceId();
ExecutionHandle* popTaskExecution(PThreadWorker& worker);
wfr_size_t getBusyWorkerCount() { return currentBusyWorkerCount; }
wfr_size_t getTotalSlotCount() { return maxWorkerCount; }
wfr_size_t getFreeSlotCount() { return maxWorkerCount - currentBusyWorkerCount; }
};
class PThreadBackend {
private:
std::mutex objMutex;
ExecutionManager& manager;
std::map<resource::ComputingResource*, std::shared_ptr<PThreadDevice>> devices;
public:
PThreadBackend(ExecutionManager& manager, const std::set<resource::ComputingResource*>& resources);
virtual ~PThreadBackend();
void notifyExecutionHandleUpdate(ExecutionHandle& handle, PThreadWorker& worker);
bool queueTaskExecution(ExecutionHandle& handle);
wfr_size_t getDeviceCount();
wfr_size_t getBusyWorkerCount();
wfr_size_t getTotalSlotCount();
wfr_size_t getFreeSlotCount();
};
} /* namespace execution */
@@ -21,6 +21,7 @@ class SchedulingDecision;
namespace execution {
class PThreadBackend;
class PThreadDevice;
class ExecutionHandle;
class PThreadWorker {
@@ -44,13 +45,13 @@ private:
bool stopThread;
bool threadRunning;
bool threadBusy;
PThreadBackend& backend;
PThreadDevice& device;
std::mutex threadMutex;
std::thread* thread;
wfr_size_t usedSlotCount;
wfs::ComputingResourceStatus status;
PThreadWorker(PThreadBackend& backend);
PThreadWorker(PThreadDevice& device);
public:
virtual ~PThreadWorker();
@@ -73,7 +74,7 @@ public:
void setStatus(wfs::ComputingResourceStatus status, std::shared_ptr<wfr::scheduling::SchedulingDecision> sd = nullptr);
static PThreadWorker* createNewThread(PThreadBackend& backend);
static PThreadWorker* createNewThread(PThreadDevice& device);
};
} /* namespace execution */