Created
June 30, 2022 13:20
-
-
Save stoffu/ca6dacaff7dd45f95b29e507ddc81fa4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- threadpool.cpp 2022-05-23 00:11:29.000000000 +0900 | |
+++ threadpool.new.cpp 2022-06-30 22:19:49.000000000 +0900 | |
@@ -41,6 +41,7 @@ | |
namespace tools | |
{ | |
threadpool::threadpool(unsigned int max_threads) : running(true), active(0) { | |
+#if 0 | |
boost::thread::attributes attrs; | |
attrs.set_stack_size(THREAD_STACK_SIZE); | |
max = max_threads ? max_threads : tools::get_max_concurrency(); | |
@@ -48,9 +49,11 @@ | |
while(i--) { | |
threads.push_back(boost::thread(attrs, boost::bind(&threadpool::run, this, false))); | |
} | |
+#endif | |
} | |
threadpool::~threadpool() { | |
+#if 0 | |
try | |
{ | |
const boost::unique_lock<boost::mutex> lock(mutex); | |
@@ -68,9 +71,11 @@ | |
try { threads[i].join(); } | |
catch (...) { /* ignore */ } | |
} | |
+#endif | |
} | |
void threadpool::submit(waiter *obj, std::function<void()> f, bool leaf) { | |
+#if 0 | |
CHECK_AND_ASSERT_THROW_MES(!is_leaf, "A leaf routine is using a thread pool"); | |
boost::unique_lock<boost::mutex> lock(mutex); | |
if (!leaf && ((active == max && !queue.empty()) || depth > 0)) { | |
@@ -91,6 +96,7 @@ | |
queue.push_back({obj, f, leaf}); | |
has_work.notify_one(); | |
} | |
+#endif | |
} | |
unsigned int threadpool::get_max_concurrency() const { | |
@@ -99,6 +105,7 @@ | |
threadpool::waiter::~waiter() | |
{ | |
+#if 0 | |
try | |
{ | |
boost::unique_lock<boost::mutex> lock(mt); | |
@@ -114,29 +121,37 @@ | |
{ | |
/* ignored */ | |
} | |
+#endif | |
} | |
void threadpool::waiter::wait(threadpool *tpool) { | |
+#if 0 | |
if (tpool) | |
tpool->run(true); | |
boost::unique_lock<boost::mutex> lock(mt); | |
while(num) | |
cv.wait(lock); | |
+#endif | |
} | |
void threadpool::waiter::inc() { | |
+#if 0 | |
const boost::unique_lock<boost::mutex> lock(mt); | |
num++; | |
+#endif | |
} | |
void threadpool::waiter::dec() { | |
+#if 0 | |
const boost::unique_lock<boost::mutex> lock(mt); | |
num--; | |
if (!num) | |
cv.notify_all(); | |
+#endif | |
} | |
void threadpool::run(bool flush) { | |
+#if 0 | |
boost::unique_lock<boost::mutex> lock(mutex); | |
while (running) { | |
entry e; | |
@@ -163,5 +178,6 @@ | |
lock.lock(); | |
active--; | |
} | |
+#endif | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment