Esempio n. 1
0
Uint32 SyncJobQueue::RunJobs(Uint32 count)
{
	Uint32 executed = 0;
	assert(count >= 1);
	for (Uint32 i = 0; i < count; ++i) {
		if (m_queue.empty())
			break;

		Job* job = m_queue.front();
		m_queue.pop_front();
		job->OnRun();
		executed++;
		m_finished.push_back(job);
	}
	return executed;
}
Esempio n. 2
0
void AsyncJobQueue::JobRunner::Main()
{
	Job *job;

	// Lock to prevent destruction of the queue while calling GetJob.
	SDL_LockMutex(m_queueDestroyingLock);
	if (m_queueDestroyed) {
		SDL_UnlockMutex(m_queueDestroyingLock);
		return;
	}
	job = m_jobQueue->GetJob();
	SDL_UnlockMutex(m_queueDestroyingLock);

	while (job) {
		// record the job so we can cancel it in case of premature shutdown
		SDL_LockMutex(m_jobLock);
		m_job = job;
		SDL_UnlockMutex(m_jobLock);

		// run the thing
		job->OnRun();

		// Lock to prevent destruction of the queue while calling Finish
		SDL_LockMutex(m_queueDestroyingLock);
		if (m_queueDestroyed) {
			SDL_UnlockMutex(m_queueDestroyingLock);
			return;
		}
		m_jobQueue->Finish(job, m_threadIdx);
		SDL_UnlockMutex(m_queueDestroyingLock);

		SDL_LockMutex(m_jobLock);
		m_job = 0;
		SDL_UnlockMutex(m_jobLock);

		// get a new job. this will block normally, or return null during
		// shutdown (Lock to protect against the queue being destroyed
		// during GetJob)
		SDL_LockMutex(m_queueDestroyingLock);
		if (m_queueDestroyed) {
			SDL_UnlockMutex(m_queueDestroyingLock);
			return;
		}
		job = m_jobQueue->GetJob();
		SDL_UnlockMutex(m_queueDestroyingLock);
	}
}
Esempio n. 3
0
void JobRunner::Main()
{
	Job *job = m_jobQueue->GetJob();
	while (job) {
		// record the job so we can cancel it in case of premature shutdown
		SDL_LockMutex(m_jobLock);
		m_job = job;
		SDL_UnlockMutex(m_jobLock);

		// run the thing
		job->OnRun();
		m_jobQueue->Finish(job, m_threadIdx);

		SDL_LockMutex(m_jobLock);
		m_job = 0;
		SDL_UnlockMutex(m_jobLock);

		// get a new job. this will block normally, or return null during
		// shutdown
		job = m_jobQueue->GetJob();
	}
}