1 /* 2 * Copyright 2013, 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 JobQueue(); 20 ~JobQueue(); 21 22 status_t Init(); 23 void Close(); 24 25 bool QueueJob(Job* job); 26 // acquires a reference, if successful 27 Job* DequeueJob(); 28 // returns a reference 29 30 private: 31 typedef DoublyLinkedList<Job> JobList; 32 33 private: 34 pthread_mutex_t fMutex; 35 pthread_cond_t fNewJobCondition; 36 bool fMutexInitialized; 37 bool fNewJobConditionInitialized; 38 JobList fJobs; 39 bool fClosed; 40 }; 41 42 43 #endif // JOB_QUEUE_H 44