git.haldean.org qb / main task.cpp
main

Tree @main (Download .tar.gz)

task.cpp @mainraw · history · blame

#include "task.hpp"

namespace qb {
  taskpool& taskpool::get() {
    static taskpool tp;
    return tp;
  }

  void taskpool::submit_async(const task &t) {
    std::thread(t).detach();
  }

  void taskpool::submit_frame(const task &t) {
    std::lock_guard<std::mutex> guard(_locktasks);
    _frametasks.push_back(t);
  }

  void taskpool::frame() {
    std::lock_guard<std::mutex> guard(_locktasks);
    for (const task &t : _frametasks) {
      t();
    }
    _frametasks.clear();
  }
}