1/* 2 * Copyright 2011-2015, Haiku, Inc. 3 * Distributed under the terms of the MIT License. 4 */ 5#ifndef _SUPPORT_PRIVATE_JOB_QUEUE_H_ 6#define _SUPPORT_PRIVATE_JOB_QUEUE_H_ 7 8 9#include <Locker.h> 10#include <SupportDefs.h> 11 12#include <Job.h> 13 14 15namespace BSupportKit { 16 17namespace BPrivate { 18 19 20class JobQueue : private BJobStateListener { 21public: 22 JobQueue(); 23 virtual ~JobQueue(); 24 25 status_t InitCheck() const; 26 27 status_t AddJob(BJob* job); 28 // takes ownership 29 status_t RemoveJob(BJob* job); 30 // gives up ownership 31 32 BJob* Pop(); 33 status_t Pop(bigtime_t timeout, bool returnWhenEmpty, 34 BJob** _job); 35 // caller owns job 36 37 size_t CountJobs() const; 38 39 void Close(); 40 41private: 42 // BJobStateListener 43 virtual void JobSucceeded(BJob* job); 44 virtual void JobFailed(BJob* job); 45 46private: 47 struct JobPriorityLess; 48 class JobPriorityQueue; 49 50private: 51 status_t _Init(); 52 53 void _RequeueDependantJobsOf(BJob* job); 54 void _RemoveDependantJobsOf(BJob* job); 55 56 mutable BLocker fLock; 57 uint32 fNextTicketNumber; 58 JobPriorityQueue* fQueuedJobs; 59 sem_id fHaveRunnableJobSem; 60 61 status_t fInitStatus; 62}; 63 64 65} // namespace BPrivate 66 67} // namespace BSupportKit 68 69 70#endif // _SUPPORT_PRIVATE_JOB_QUEUE_H_ 71