1 // Licensed GNU LGPL v3 or later: http://www.gnu.org/licenses/lgpl.html 2 3 #ifndef SPECTMORPH_BUILDER_THREAD_HH 4 #define SPECTMORPH_BUILDER_THREAD_HH 5 6 #include <thread> 7 #include <mutex> 8 #include <functional> 9 #include <vector> 10 #include <condition_variable> 11 12 namespace SpectMorph 13 { 14 15 class WavSet; 16 class WavSetBuilder; 17 18 class BuilderThread 19 { 20 std::mutex mutex; 21 std::thread thread; 22 std::condition_variable cond; 23 bool thread_quit = false; 24 25 struct Job; 26 27 std::vector<std::unique_ptr<Job>> todo; 28 29 bool check_quit(); 30 Job *first_job(); 31 void pop_job(); 32 void run_job (Job *job); 33 void run(); 34 35 public: 36 BuilderThread(); 37 ~BuilderThread(); 38 39 void add_job (WavSetBuilder *builder, int object_id, const std::function<void(WavSet *wav_set)>& done_func); 40 size_t job_count(); 41 bool search_job (int object_id); 42 void kill_all_jobs(); 43 void kill_jobs_by_id (int object_id); 44 }; 45 46 } 47 48 #endif 49