Browse Source

Added NoThread task queue

yhirose 6 years ago
parent
commit
d45676b064
1 changed files with 17 additions and 2 deletions
  1. 17 2
      httplib.h

+ 17 - 2
httplib.h

@@ -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
   };
 }