1 /* 2 * Copyright 2013-2014, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Ingo Weinhold <ingo_weinhold@gmx.de> 7 */ 8 #ifndef JOB_QUEUE_H 9 #define JOB_QUEUE_H 10 11 12 #include <pthread.h> 13 14 #include "Job.h" 15 16 17 class JobQueue { 18 public: 19 class Filter; 20 21 public: 22 JobQueue(); 23 ~JobQueue(); 24 25 status_t Init(); 26 void Close(); 27 28 bool QueueJob(Job* job); 29 // acquires a reference, if successful 30 Job* DequeueJob(); 31 // returns a reference 32 33 void DeleteJobs(Filter* filter); 34 35 private: 36 typedef DoublyLinkedList<Job> JobList; 37 38 private: 39 pthread_mutex_t fMutex; 40 pthread_cond_t fNewJobCondition; 41 bool fMutexInitialized; 42 bool fNewJobConditionInitialized; 43 JobList fJobs; 44 bool fClosed; 45 }; 46 47 48 class JobQueue::Filter { 49 public: 50 virtual ~Filter(); 51 52 virtual bool FilterJob(Job* job) = 0; 53 }; 54 55 56 #endif // JOB_QUEUE_H 57