-
Notifications
You must be signed in to change notification settings - Fork 0
/
ThreadUtils.h
42 lines (36 loc) · 907 Bytes
/
ThreadUtils.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
/*
* ThreadUtils.h
*
* Created on: Aug 7, 2016
* Author: helospark
*/
#ifndef THREADUTILS_H_
#define THREADUTILS_H_
#include <map>
#include <string>
#include <thread>
#include "math.h"
namespace ThreadUtils {
inline int getNumberOfCores() {
int numberOfCores = std::thread::hardware_concurrency();
if (numberOfCores <= 0) {
numberOfCores = 1;
}
return numberOfCores;
}
inline int getThreadCountFromArgument(const std::map<std::string, std::string>& map) {
int threads = 0;
auto it = map.find("threads");
int numberOfCores = getNumberOfCores();
if (it != map.end()) {
std::string threadCount = (*it).second;
threads = Math::parseIntOrGet(threadCount, numberOfCores);
}
if (threads <= 0) {
threads = numberOfCores;
}
std::cout << "T=" << threads << std::endl;
return threads;
}
}
#endif /* THREADUTILS_H_ */