Skip to content

Commit d45676b

Browse files
committed
Added NoThread task queue
1 parent 94d13e8 commit d45676b

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

httplib.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ class ThreadPool : public TaskQueue {
435435
std::condition_variable cond_;
436436
std::mutex mutex_;
437437
};
438-
#else
438+
#elif CPPHTTPLIB_THREAD_POOL_COUNT == 0
439439
class Threads : public TaskQueue {
440440
public:
441441
Threads() : running_threads_(0) {}
@@ -469,6 +469,19 @@ class Threads : public TaskQueue {
469469
std::mutex running_threads_mutex_;
470470
int running_threads_;
471471
};
472+
#else
473+
class NoThread : public TaskQueue {
474+
public:
475+
NoThread() {}
476+
virtual ~NoThread() {}
477+
478+
virtual void enqueue(std::function<void()> fn) override {
479+
fn();
480+
}
481+
482+
virtual void shutdown() override {
483+
}
484+
};
472485
#endif
473486

474487
class Server {
@@ -2335,8 +2348,10 @@ inline Server::Server()
23352348
new_task_queue = [] {
23362349
#if CPPHTTPLIB_THREAD_POOL_COUNT > 0
23372350
return new ThreadPool(CPPHTTPLIB_THREAD_POOL_COUNT);
2338-
#else
2351+
#elif CPPHTTPLIB_THREAD_POOL_COUNT == 0
23392352
return new Threads();
2353+
#else
2354+
return new NoThread();
23402355
#endif
23412356
};
23422357
}

0 commit comments

Comments
 (0)