19 #ifndef FF_COMMON_THREAD_H_
20 #define FF_COMMON_THREAD_H_
22 #include <gflags/gflags.h>
30 #define GOOGLE_ALLOW_RVALUE_REFERENCES_PUSH
31 #define GOOGLE_ALLOW_RVALUE_REFERENCES_POP
41 typedef std::tuple<std::function<void(
void)>, pthread_mutex_t*, pthread_cond_t*,
bool>
VarsTuple;
62 template <
typename Function,
typename... Args>
63 void AddTask(Function&& f, Args&&... args) {
67 var_bindings_.emplace_back(std::bind(f, args...),
72 threads_.push_back(pthread_t());
73 pthread_create(&threads_.back(), NULL,
HolderFunction, &var_bindings_.back());
79 void WaitTillJobOpening();
81 size_t max_concurrent_jobs_;
82 std::list<pthread_t> threads_;
83 std::list<VarsTuple> var_bindings_;
84 pthread_mutex_t cond_mutex_;
92 #endif // FF_COMMON_THREAD_H_