-
Notifications
You must be signed in to change notification settings - Fork 5
/
RoundRobinDistributor.h
42 lines (34 loc) · 1.02 KB
/
RoundRobinDistributor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef ROUND_ROBIN_DISTRIBUTOR_H_
#define ROUND_ROBIN_DISTRIBUTOR_H_
#include <iostream>
#include <atomic>
#include <memory>
#include <limits>
#include <thread>
#include <mutex>
#include <chrono>
#include <condition_variable>
#include <queue>
#include "AbstractDistributor.h"
class RoundRobinDistributor: public AbstractDistributor {
public:
RoundRobinDistributor(std::vector<struct Host*> *hosts);
~RoundRobinDistributor();
virtual void sendToMaster(struct HttpRequest *request, int sock);
virtual void distribute(struct HttpRequest *request, int sock);
void execute();
private:
std::atomic<unsigned int> read_counter;
const unsigned int m_boundary = std::numeric_limits<unsigned int>::max() / 2;
std::vector<std::thread> thread_pool;
std::mutex m_queue_mtx;
std::condition_variable m_queue_cv;
struct RequestTuple {
struct HttpRequest *request;
int host;
int socket;
bool is_write;
};
std::queue<struct RequestTuple*> m_parsedRequests;
};
#endif