Skip to content

Commit 66890f6

Browse files
committed
Clamping thread count
1 parent 37979bb commit 66890f6

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

cpr/threadpool.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "cpr/threadpool.h"
2+
#include <algorithm>
23
#include <chrono>
34
#include <cstddef>
45
#include <ctime>
@@ -20,12 +21,7 @@ int ThreadPool::Start(size_t start_threads) {
2021
return -1;
2122
}
2223
status = RUNNING;
23-
if (start_threads < min_thread_num) {
24-
start_threads = min_thread_num;
25-
}
26-
if (start_threads > max_thread_num) {
27-
start_threads = max_thread_num;
28-
}
24+
start_threads = std::clamp(start_threads, min_thread_num, max_thread_num);
2925
for (size_t i = 0; i < start_threads; ++i) {
3026
CreateThread();
3127
}

0 commit comments

Comments
 (0)