Skip to content
This repository has been archived by the owner on Sep 17, 2022. It is now read-only.

Commit

Permalink
Document - Class DispatchQueue (#48)
Browse files Browse the repository at this point in the history
* feat: document DQ.hpp

* fix: typedef -> using =

* fix: move include

* fix: separate unused

* fix: private -> protected

* fix: construct

* fix: remove unsed include
  • Loading branch information
Rexezuge authored Dec 9, 2021
1 parent 119d255 commit 5687bcf
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
53 changes: 47 additions & 6 deletions Backend/include/EasyContact/DispatchQueue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,77 @@
// C++ Standard Library
#include <condition_variable>
#include <functional>
#include <iostream>
#include <mutex>
#include <string>
#include <thread>
// Standard Template Library
#include <queue>
#include <utility>
#include <vector>
// EasyContact Header Files
#include <EasyContact/SingleUser.hpp>
class DispatchQueue {
typedef std::function<void(void)> Functor;
using Functor = std::function<void(void)>;

private:
bool inServices;
size_t JobID;
std::mutex Lock;
std::vector<std::thread> Threads;
std::queue<Functor> Queue;
std::condition_variable CV;
bool inServices = true;

protected:
void Dispatch_Hander(void);

public:
/**
* Default Class Constructor
* @param NumThreads : Number of Threads to Create
*/
explicit DispatchQueue(const size_t& NumThreads);
/**
* Default Class Destructor
*/
~DispatchQueue();
/**
* Add Task to Dispatch Queue
* @param Operation : Task Expressed in Lambda Expression
* @return std::pair<size_t, size_t> : Your Task ID, Number of Tasks Before
* Your Task
*/
std::pair<size_t, size_t> Dispatch(const Functor& Operation);
/**
* Add Task to Dispatch Queue
* @param Operation : Task Expressed in Lambda Expression
* @return std::pair<size_t, size_t> : Your Task ID, Number of Tasks Before
* Your Task
*/
std::pair<size_t, size_t> Dispatch(Functor&& Operation);

public:
/**
* This Funtion Call Is Not Allowed &
* Will Delete Left Hand Side Instance
* @param RHS : Another Instance of Current Class
*/
DispatchQueue(const DispatchQueue& RHS) = delete;
/**
* This Funtion Call Is Not Allowed &
* Will Delete Left Hand Side Instance
* @param RHS : Another Instance of Current Class
* @return DispatchQueue : Reference to SELF
*/
DispatchQueue& operator=(const DispatchQueue& RHS) = delete;
/**
* This Funtion Call Is Not Allowed &
* Will Delete Left Hand Side Instance
* @param RHS : Another Instance of Current Class
*/
DispatchQueue(DispatchQueue&& RHS) = delete;
/**
* This Funtion Call Is Not Allowed &
* Will Delete Left Hand Side Instance
* @param RHS : Another Instance of Current Class
* @return DispatchQueue : Reference to SELF
*/
DispatchQueue& operator=(DispatchQueue&& RHS) = delete;
};
#endif // BACKEND_INCLUDE_EASYCONTACT_DISPATCHQUEUE_HPP_
4 changes: 3 additions & 1 deletion Backend/src/DispatchQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
*/
#ifndef BACKEND_SRC_DISPATCHQUEUE_CPP_
#define BACKEND_SRC_DISPATCHQUEUE_CPP_
// EasyContact Header Files
#include <EasyContact/DispatchQueue.hpp>
#include <EasyContact/SingleUser.hpp>
DispatchQueue::DispatchQueue(const size_t& NumThreads)
: JobID(0), Threads(NumThreads) {
: inServices(true), JobID(0), Threads(NumThreads) {
for (size_t i = 0; i < Threads.size(); ++i) {
Threads[i] = std::thread(&DispatchQueue::Dispatch_Hander, this);
}
Expand Down

0 comments on commit 5687bcf

Please sign in to comment.