Initial commit
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <wfr/common/types/WfrTypes.h>
|
||||
#include <set>
|
||||
#include <queue>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
namespace wfr {
|
||||
|
||||
namespace resource {
|
||||
class Resource;
|
||||
class ComputingResource;
|
||||
}
|
||||
|
||||
namespace execution {
|
||||
|
||||
class ExecutionManager;
|
||||
class ExecutionHandle;
|
||||
class PThreadWorker;
|
||||
|
||||
class PThreadBackend {
|
||||
private:
|
||||
std::mutex objMutex;
|
||||
std::condition_variable workerCondVar;
|
||||
ExecutionManager& manager;
|
||||
std::set<PThreadWorker*> workers;
|
||||
std::set<PThreadWorker*> idleWorkers;
|
||||
std::set<resource::ComputingResource*> resources;
|
||||
std::queue<ExecutionHandle*> taskQueue;
|
||||
wfr_size_t maxWorkerCount;
|
||||
wfr_size_t currentTotalWorkerCount = 0;
|
||||
wfr_size_t currentBusyWorkerCount = 0;
|
||||
wfr_size_t occupiedSlotCount = 0;
|
||||
wfr_size_t slotsInQueue = 0;
|
||||
bool isShutdown = false;
|
||||
|
||||
public:
|
||||
PThreadBackend(ExecutionManager& manager, const std::set<resource::ComputingResource*>& resources);
|
||||
virtual ~PThreadBackend();
|
||||
|
||||
void notifyExecutionHandleUpdate(ExecutionHandle& handle, PThreadWorker& worker);
|
||||
|
||||
bool queueTaskExecution(ExecutionHandle& handle);
|
||||
|
||||
ExecutionHandle* popTaskExecution(PThreadWorker& worker);
|
||||
|
||||
wfr_size_t getBusyWorkerCount() { return currentBusyWorkerCount; }
|
||||
|
||||
wfr_size_t getTotalSlotCount() { return maxWorkerCount; }
|
||||
|
||||
};
|
||||
|
||||
} /* namespace execution */
|
||||
} /* namespace wfr */
|
||||
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <atomic>
|
||||
#include <wfr/common/types/WfsTypes.h>
|
||||
|
||||
|
||||
namespace wfr {
|
||||
|
||||
namespace resource {
|
||||
class Resource;
|
||||
}
|
||||
|
||||
namespace scheduling {
|
||||
class SchedulingDecision;
|
||||
}
|
||||
|
||||
namespace execution {
|
||||
|
||||
class PThreadBackend;
|
||||
class ExecutionHandle;
|
||||
|
||||
class PThreadWorker {
|
||||
private:
|
||||
/**
|
||||
* Static variable holding the next free threadID.
|
||||
**/
|
||||
static std::atomic<wfr_id_t> nextThreadID;
|
||||
|
||||
/**
|
||||
* Returns the next free threadID.
|
||||
*
|
||||
* @return next free threadID.
|
||||
*/
|
||||
static wfr_id_t getNextThreadID();
|
||||
|
||||
static void workerFunc(PThreadWorker* threadObj);
|
||||
|
||||
private:
|
||||
wfr_id_t threadID;
|
||||
bool stopThread;
|
||||
bool threadRunning;
|
||||
bool threadBusy;
|
||||
PThreadBackend& backend;
|
||||
std::mutex threadMutex;
|
||||
std::thread* thread;
|
||||
wfr_size_t usedSlotCount;
|
||||
wfs::ComputingResourceStatus status;
|
||||
|
||||
PThreadWorker(PThreadBackend& backend);
|
||||
|
||||
public:
|
||||
virtual ~PThreadWorker();
|
||||
|
||||
wfr_size_t getThreadID() { return threadID; }
|
||||
|
||||
bool isBusy() { return threadBusy; }
|
||||
|
||||
void setBusy(bool val) {threadBusy = val; }
|
||||
|
||||
wfr_size_t getUsedSlotCount() { return usedSlotCount; }
|
||||
|
||||
void setUsedSlotCount(wfr_size_t count) { usedSlotCount += count; }
|
||||
|
||||
void finishThread();
|
||||
|
||||
void join();
|
||||
|
||||
wfs::ComputingResourceStatus getStatus() { return status; }
|
||||
|
||||
void setStatus(wfs::ComputingResourceStatus status, std::shared_ptr<wfr::scheduling::SchedulingDecision> sd = nullptr);
|
||||
|
||||
static PThreadWorker* createNewThread(PThreadBackend& backend);
|
||||
};
|
||||
|
||||
} /* namespace execution */
|
||||
} /* namespace wfr */
|
||||
|
||||
Reference in New Issue
Block a user