2 * Copyright 2013-2014, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Ingo Weinhold <ingo_weinhold@gmx.de>
12 #include <PthreadMutexLocker.h>
15 // #pragma mark - JobQueue
20 fMutexInitialized(false),
21 fNewJobConditionInitialized(false),
30 if (fMutexInitialized
) {
31 PthreadMutexLocker
mutexLocker(fMutex
);
32 while (Job
* job
= fJobs
.RemoveHead())
33 job
->ReleaseReference();
36 if (fNewJobConditionInitialized
)
37 pthread_cond_destroy(&fNewJobCondition
);
39 if (fMutexInitialized
)
40 pthread_mutex_destroy(&fMutex
);
47 status_t error
= pthread_mutex_init(&fMutex
, NULL
);
50 fMutexInitialized
= true;
52 error
= pthread_cond_init(&fNewJobCondition
, NULL
);
55 fNewJobConditionInitialized
= true;
64 if (fMutexInitialized
&& fNewJobConditionInitialized
) {
65 PthreadMutexLocker
mutexLocker(fMutex
);
67 pthread_cond_broadcast(&fNewJobCondition
);
73 JobQueue::QueueJob(Job
* job
)
75 PthreadMutexLocker
mutexLocker(fMutex
);
80 job
->AcquireReference();
82 pthread_cond_signal(&fNewJobCondition
);
88 JobQueue::DequeueJob()
90 PthreadMutexLocker
mutexLocker(fMutex
);
93 Job
* job
= fJobs
.RemoveHead();
98 pthread_cond_wait(&fNewJobCondition
, &fMutex
);
106 JobQueue::DeleteJobs(Filter
* filter
)
108 PthreadMutexLocker
mutexLocker(fMutex
);
110 for (JobList::Iterator it
= fJobs
.GetIterator(); Job
* job
= it
.Next();) {
111 if (filter
->FilterJob(job
)) {
119 // #pragma mark - Filter
122 JobQueue::Filter::~Filter()