2011-01-22 01:18:58 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2011, Haiku, Inc.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2011-01-25 20:07:27 +03:00
|
|
|
#ifndef _PACKAGE__PRIVATE__JOB_QUEUE_H_
|
|
|
|
#define _PACKAGE__PRIVATE__JOB_QUEUE_H_
|
2011-01-22 01:18:58 +03:00
|
|
|
|
|
|
|
|
|
|
|
#include <Locker.h>
|
|
|
|
#include <SupportDefs.h>
|
|
|
|
|
|
|
|
#include <package/Job.h>
|
|
|
|
|
|
|
|
|
2011-01-25 20:07:27 +03:00
|
|
|
namespace BPackageKit {
|
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();
|
|
|
|
// caller owns job
|
2011-01-22 01:18:58 +03:00
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
2011-01-25 20:07:27 +03:00
|
|
|
} // namespace BPackageKit
|
2011-01-22 01:18:58 +03:00
|
|
|
|
|
|
|
|
2011-01-25 20:07:27 +03:00
|
|
|
#endif // _PACKAGE__PRIVATE__JOB_QUEUE_H_
|