#pragma once #include "cDefs.hpp" #include #include #include #include #include #include #include #include #include #include "cThread.hpp" using namespace std; namespace fpga { class cArbiter { private: bool run; condition_variable cv; thread arbiter_thread; unordered_map> cthreads; mutex mtx; queue> request_queue; void processRequests(); public: cArbiter() {} ~cArbiter(); // Threads bool addCThread(int32_t ctid, int32_t vfid, pid_t pid); void removeCThread(int32_t ctid); cThread* getCThread(int32_t ctid); // Start arbitration void start(); // Getters inline auto isRunning() { return run; } // Send a task void scheduleTask(std::unique_ptr ctask) { lock_guard lck2(mtx); request_queue.emplace(std::move(ctask)); } cmplEv getCompletedNext(int32_t ctid); inline auto getCompletedCnt() { int32_t tmp = 0; for(auto& it: cthreads) { tmp += (it.second->getCompletedCnt()); } return tmp; } }; }