Esempio n. 1
0
            std::future<typename std::result_of<TFunction()>::type> submit(TFunction&& func) {

                typedef typename std::result_of<TFunction()>::type result_type;

                std::packaged_task<result_type()> task(std::forward<TFunction>(func));
                std::future<result_type> future_result(task.get_future());
                m_work_queue.push(std::move(task));

                return future_result;
            }
Esempio n. 2
0
 void worker_thread() {
     while (!m_done) {
         std::function<void()> task;
         if (m_work_queue.try_pop(task)) {
             task();
         } else {
             std::this_thread::yield();
         }
     }
 }
Esempio n. 3
0
 void worker_thread() {
     osmium::thread::set_thread_name("_osmium_worker");
     while (true) {
         function_wrapper task;
         m_work_queue.wait_and_pop_with_timeout(task);
         if (task) {
             if (task()) {
                 // The called tasks returns true only when the
                 // worker thread should shut down.
                 return;
             }
         }
     }
 }
Esempio n. 4
0
 bool queue_empty() const {
     return m_work_queue.empty();
 }
Esempio n. 5
0
 size_t queue_size() const {
     return m_work_queue.size();
 }
Esempio n. 6
0
 ~Pool() {
     shutdown_all_workers();
     m_work_queue.shutdown();
 }
Esempio n. 7
0
 void shutdown_all_workers() {
     for (int i = 0; i < m_num_threads; ++i) {
         // The special function wrapper makes a worker shut down.
         m_work_queue.push(function_wrapper{0});
     }
 }
Esempio n. 8
0
 inline void add_to_queue(osmium::thread::Queue<std::future<T>>& queue, std::exception_ptr&& exception) {
     std::promise<T> promise;
     queue.push(promise.get_future());
     promise.set_exception(std::move(exception));
 }
Esempio n. 9
0
 inline void add_to_queue(osmium::thread::Queue<std::future<T>>& queue, T&& data) {
     std::promise<T> promise;
     queue.push(promise.get_future());
     promise.set_value(std::forward<T>(data));
 }
Esempio n. 10
0
 size_t submit(TFunction f) {
     return m_work_queue.push_and_get_size(std::function<void()>(f));
 }