forked from pantyusha/nesca
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreader.cpp
More file actions
36 lines (30 loc) · 733 Bytes
/
Threader.cpp
File metadata and controls
36 lines (30 loc) · 733 Bytes
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
#include "Threader.h"
int Threader::gThreadDelay = 10;
int Threader::threadId = 0;
std::mutex Threader::m;
bool Threader::ready = false;
std::condition_variable Threader::cv;
std::queue<std::string> Threader::ipQueue;
void Threader::fireThread(std::string ip, void *func(void)) {
ipQueue.push(ip);
if(threadId < gThreads) {
++threadId;
std::thread workerThread(func);
workerThread.detach();
}
ready = true;
cv.notify_one();
Sleep(gThreadDelay);
}
void Threader::cleanUp() {
ready = true;
cv.notify_all();
std::unique_lock<std::mutex> lk(m);
lk.unlock();
lk.release();
Sleep(200);
threadId = 0;
std::queue<std::string> empty;
std::swap(ipQueue, empty);
ready = false;
}