-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduler.cpp
29 lines (24 loc) · 948 Bytes
/
scheduler.cpp
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
#include <iostream>
#include <thread>
#include <chrono>
#include <vector>
#include <algorithm>
#include <structs.h>
#include <functions.h>
#include <sync.h>
auto http_request_scheduler() -> void {
std::this_thread::sleep_for (std::chrono::seconds(options.time));
//Signal worker thread to process a request from the queue
//if(options.debug_flag) std::cout << "(Scheduler Thread): Starting scheduler\n";
while(true){
std::this_thread::sleep_for (std::chrono::seconds(1));
if(!http_request_queue.empty()){
std::unique_lock<std::mutex> data_lock (data_mutex);
//if(options.debug_flag) std::cout << "(Scheduler Thread): Sending job to worker thread\n";
//Reschedule (sort) all the requests in the queue using custom Comparator
sort(http_request_queue.begin(), http_request_queue.end(), Comparator(options.sched));
//Signal worker thread
work_cv.notify_one();
}
}
}