btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / headers / private / support / JobQueue.h
blob468877a0e4a1b7c0e9e72a74593c001210a0fe0e
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_
9 #include <Locker.h>
10 #include <SupportDefs.h>
12 #include <Job.h>
15 namespace BSupportKit {
17 namespace BPrivate {
20 class JobQueue : private BJobStateListener {
21 public:
22 JobQueue();
23 virtual ~JobQueue();
25 status_t InitCheck() const;
27 status_t AddJob(BJob* job);
28 // takes ownership
29 status_t RemoveJob(BJob* job);
30 // gives up ownership
32 BJob* Pop();
33 status_t Pop(bigtime_t timeout, bool returnWhenEmpty,
34 BJob** _job);
35 // caller owns job
37 size_t CountJobs() const;
39 void Close();
41 private:
42 // BJobStateListener
43 virtual void JobSucceeded(BJob* job);
44 virtual void JobFailed(BJob* job);
46 private:
47 struct JobPriorityLess;
48 class JobPriorityQueue;
50 private:
51 status_t _Init();
53 void _RequeueDependantJobsOf(BJob* job);
54 void _RemoveDependantJobsOf(BJob* job);
56 mutable BLocker fLock;
57 uint32 fNextTicketNumber;
58 JobPriorityQueue* fQueuedJobs;
59 sem_id fHaveRunnableJobSem;
61 status_t fInitStatus;
65 } // namespace BPrivate
67 } // namespace BSupportKit
70 #endif // _SUPPORT_PRIVATE_JOB_QUEUE_H_