2011-01-22 01:18:58 +03:00
|
|
|
/*
|
2015-05-18 19:21:58 +03:00
|
|
|
* Copyright 2011-2015, Haiku, Inc.
|
2011-01-22 01:18:58 +03:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2015-05-18 19:21:58 +03:00
|
|
|
#ifndef _SUPPORT_PRIVATE_JOB_QUEUE_H_
|
|
|
|
#define _SUPPORT_PRIVATE_JOB_QUEUE_H_
|
2011-01-22 01:18:58 +03:00
|
|
|
|
|
|
|
|
|
|
|
#include <Locker.h>
|
|
|
|
#include <SupportDefs.h>
|
|
|
|
|
2015-05-18 19:21:58 +03:00
|
|
|
#include <Job.h>
|
2011-01-22 01:18:58 +03:00
|
|
|
|
|
|
|
|
2015-05-18 19:21:58 +03:00
|
|
|
namespace BSupportKit {
|
2011-01-22 01:18:58 +03:00
|
|
|
|
2011-01-25 20:07:27 +03:00
|
|
|
namespace BPrivate {
|
2011-01-22 01:18:58 +03:00
|
|
|
|
2011-01-24 23:48:03 +03:00
|
|
|
|
2011-01-25 20:07:27 +03:00
|
|
|
class JobQueue : private BJobStateListener {
|
2011-01-22 01:18:58 +03:00
|
|
|
public:
|
|
|
|
JobQueue();
|
2011-01-25 20:07:27 +03:00
|
|
|
virtual ~JobQueue();
|
|
|
|
|
|
|
|
status_t InitCheck() const;
|
2011-01-22 01:18:58 +03:00
|
|
|
|
2011-01-25 20:07:27 +03:00
|
|
|
status_t AddJob(BJob* job);
|
|
|
|
// takes ownership
|
|
|
|
status_t RemoveJob(BJob* job);
|
|
|
|
// gives up ownership
|
2011-01-22 01:18:58 +03:00
|
|
|
|
2011-01-25 20:07:27 +03:00
|
|
|
BJob* Pop();
|
2015-05-31 20:03:34 +03:00
|
|
|
status_t Pop(bigtime_t timeout, bool returnWhenEmpty,
|
|
|
|
BJob** _job);
|
2011-01-25 20:07:27 +03:00
|
|
|
// caller owns job
|
2011-01-22 01:18:58 +03:00
|
|
|
|
2015-05-31 20:03:34 +03:00
|
|
|
size_t CountJobs() const;
|
|
|
|
|
2011-01-25 20:07:27 +03:00
|
|
|
void Close();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// BJobStateListener
|
|
|
|
virtual void JobSucceeded(BJob* job);
|
|
|
|
virtual void JobFailed(BJob* job);
|
2011-01-22 01:18:58 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct JobPriorityLess;
|
|
|
|
class JobPriorityQueue;
|
|
|
|
|
|
|
|
private:
|
2011-01-25 20:07:27 +03:00
|
|
|
status_t _Init();
|
|
|
|
|
|
|
|
void _RequeueDependantJobsOf(BJob* job);
|
|
|
|
void _RemoveDependantJobsOf(BJob* job);
|
2011-01-22 01:18:58 +03:00
|
|
|
|
2015-05-31 20:03:34 +03:00
|
|
|
mutable BLocker fLock;
|
2011-01-25 20:07:27 +03:00
|
|
|
uint32 fNextTicketNumber;
|
2011-01-22 01:18:58 +03:00
|
|
|
JobPriorityQueue* fQueuedJobs;
|
2011-01-25 20:07:27 +03:00
|
|
|
sem_id fHaveRunnableJobSem;
|
2011-01-22 01:18:58 +03:00
|
|
|
|
2011-01-25 20:07:27 +03:00
|
|
|
status_t fInitStatus;
|
|
|
|
};
|
2011-01-22 01:18:58 +03:00
|
|
|
|
2011-01-24 23:48:03 +03:00
|
|
|
|
2011-01-25 20:07:27 +03:00
|
|
|
} // namespace BPrivate
|
2011-01-22 01:18:58 +03:00
|
|
|
|
2015-05-18 19:21:58 +03:00
|
|
|
} // namespace BSupportKit
|
2011-01-22 01:18:58 +03:00
|
|
|
|
|
|
|
|
2015-05-18 19:21:58 +03:00
|
|
|
#endif // _SUPPORT_PRIVATE_JOB_QUEUE_H_
|