Added NoThread task queue

This commit is contained in:
yhirose 2019-11-25 13:00:37 -05:00
parent 94d13e88a5
commit d45676b064

View file

@ -435,7 +435,7 @@ private:
std::condition_variable cond_;
std::mutex mutex_;
};
#else
#elif CPPHTTPLIB_THREAD_POOL_COUNT == 0
class Threads : public TaskQueue {
public:
Threads() : running_threads_(0) {}
@ -469,6 +469,19 @@ private:
std::mutex running_threads_mutex_;
int running_threads_;
};
#else
class NoThread : public TaskQueue {
public:
NoThread() {}
virtual ~NoThread() {}
virtual void enqueue(std::function<void()> fn) override {
fn();
}
virtual void shutdown() override {
}
};
#endif
class Server {
@ -2335,8 +2348,10 @@ inline Server::Server()
new_task_queue = [] {
#if CPPHTTPLIB_THREAD_POOL_COUNT > 0
return new ThreadPool(CPPHTTPLIB_THREAD_POOL_COUNT);
#else
#elif CPPHTTPLIB_THREAD_POOL_COUNT == 0
return new Threads();
#else
return new NoThread();
#endif
};
}