Use different processing order depending if we have OWF or not

This commit is contained in:
Laurent Fasnacht 2014-06-16 07:24:31 +02:00
parent c32943f78b
commit 3be3fa8d6e
3 changed files with 17 additions and 8 deletions

View file

@ -52,8 +52,11 @@ int encoder_control_init(encoder_control * const encoder, const config * const c
encoder->threadqueue = MALLOC(threadqueue_queue, 1);
//FIXME use cfg
encoder->owf = 1;
//Init threadqueue
if (!encoder->threadqueue || !threadqueue_init(encoder->threadqueue, cfg->threads)) {
if (!encoder->threadqueue || !threadqueue_init(encoder->threadqueue, cfg->threads, encoder->owf > 0)) {
fprintf(stderr, "Could not initialize threadqueue");
return 0;
}
@ -254,8 +257,6 @@ int encoder_control_init(encoder_control * const encoder, const config * const c
encoder->wpp = encoder->cfg->wpp;
encoder->owf = 1;
#ifdef _DEBUG
printf("Tiles columns width:");
for (i=0; i < encoder->tiles_num_tile_columns; ++i) {

View file

@ -88,9 +88,14 @@ static void* threadqueue_worker(void* threadqueue_worker_spec_opaque) {
PTHREAD_LOCK(&next_job->lock);
assert(next_job->ndepends == 0);
job = next_job;
} else {
for (i = threadqueue->queue_count - 1; i >= threadqueue->queue_start; --i) {
} else {
//FIXME: if not using OWF, the first is better than the second, otherwise we should use the second order
//for (i = threadqueue->queue_count - 1; i >= threadqueue->queue_start; --i) {
//for (i = threadqueue->queue_start; i < threadqueue->queue_count; ++i) {
for (i = (threadqueue->fifo ? threadqueue->queue_start : threadqueue->queue_count - 1);
(threadqueue->fifo ? i < threadqueue->queue_count : i >= threadqueue->queue_start);
(threadqueue->fifo ? ++i : --i)) {
threadqueue_job * const i_job = threadqueue->queue[i];
if (i_job->state == THREADQUEUE_JOB_STATE_QUEUED && i_job->ndepends == 0) {
@ -206,7 +211,7 @@ static void* threadqueue_worker(void* threadqueue_worker_spec_opaque) {
return NULL;
}
int threadqueue_init(threadqueue_queue * const threadqueue, int thread_count) {
int threadqueue_init(threadqueue_queue * const threadqueue, int thread_count, int fifo) {
int i;
if (pthread_mutex_init(&threadqueue->lock, NULL) != 0) {
fprintf(stderr, "pthread_mutex_init failed!\n");
@ -226,6 +231,7 @@ int threadqueue_init(threadqueue_queue * const threadqueue, int thread_count) {
}
threadqueue->stop = 0;
threadqueue->fifo = !!fifo;
threadqueue->threads_running = 0;
threadqueue->threads_count = thread_count;

View file

@ -71,6 +71,8 @@ typedef struct {
int stop; //=>1: threads should stop asap
int fifo;
threadqueue_job **queue;
unsigned int queue_start;
unsigned int queue_count;
@ -93,8 +95,8 @@ typedef struct {
#endif
} threadqueue_queue;
//Init a threadqueue
int threadqueue_init(threadqueue_queue * threadqueue, int thread_count);
//Init a threadqueue (if fifo, then behave as a FIFO with dependencies, otherwise as a LIFO with dependencies)
int threadqueue_init(threadqueue_queue * threadqueue, int thread_count, int fifo);
//Add a job to the queue, and returs a threadqueue_job handle. If wait == 1, one has to run threadqueue_job_unwait_job in order to have it run
threadqueue_job * threadqueue_submit(threadqueue_queue * threadqueue, void (*fptr)(void *arg), void *arg, int wait, const char* debug_description);