make use of st::future conditional, we do not really need it
This commit is contained in:
parent
cc858289e8
commit
ee58aabdbe
1 changed files with 13 additions and 1 deletions
|
@ -18,7 +18,9 @@
|
||||||
#define _WORKQUEUE_H_INCLUDED_
|
#define _WORKQUEUE_H_INCLUDED_
|
||||||
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#if HAVE_STD_FUTURE
|
||||||
#include <future>
|
#include <future>
|
||||||
|
#endif
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
@ -76,10 +78,14 @@ public:
|
||||||
bool start(int nworkers, void *(workproc)(void *), void *arg) {
|
bool start(int nworkers, void *(workproc)(void *), void *arg) {
|
||||||
std::unique_lock<std::mutex> lock(m_mutex);
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
for (int i = 0; i < nworkers; i++) {
|
for (int i = 0; i < nworkers; i++) {
|
||||||
std::packaged_task<void *(void *)> task(workproc);
|
|
||||||
Worker w;
|
Worker w;
|
||||||
|
#if HAVE_STD_FUTURE
|
||||||
|
std::packaged_task<void *(void *)> task(workproc);
|
||||||
w.res = task.get_future();
|
w.res = task.get_future();
|
||||||
w.thr = std::thread(std::move(task), arg);
|
w.thr = std::thread(std::move(task), arg);
|
||||||
|
#else
|
||||||
|
w.thr = std::thread(workproc, arg);
|
||||||
|
#endif
|
||||||
m_worker_threads.push_back(std::move(w));
|
m_worker_threads.push_back(std::move(w));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -189,7 +195,11 @@ public:
|
||||||
// Workers return (void*)1 if ok
|
// Workers return (void*)1 if ok
|
||||||
void *statusall = (void*)1;
|
void *statusall = (void*)1;
|
||||||
while (!m_worker_threads.empty()) {
|
while (!m_worker_threads.empty()) {
|
||||||
|
#if HAVE_STD_FUTURE
|
||||||
void *status = m_worker_threads.front().res.get();
|
void *status = m_worker_threads.front().res.get();
|
||||||
|
#else
|
||||||
|
void *status = (void*) 1;
|
||||||
|
#endif
|
||||||
m_worker_threads.front().thr.join();
|
m_worker_threads.front().thr.join();
|
||||||
if (status == (void *)0) {
|
if (status == (void *)0) {
|
||||||
statusall = status;
|
statusall = status;
|
||||||
|
@ -305,7 +315,9 @@ private:
|
||||||
|
|
||||||
struct Worker {
|
struct Worker {
|
||||||
std::thread thr;
|
std::thread thr;
|
||||||
|
#if HAVE_STD_FUTURE
|
||||||
std::future<void *> res;
|
std::future<void *> res;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
// Configuration
|
// Configuration
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue