diff --git a/src/queue.c b/src/queue.c index 2126783da4c581e8ffc550cfca04479746b3fbff..dc601abfd16011411349f65f9f1e6d00664d1cd6 100644 --- a/src/queue.c +++ b/src/queue.c @@ -144,8 +144,14 @@ struct task *queue_gettask ( struct queue *q , int qid , struct cell *super , in while ( q->count > 0 ) { /* Grab the task lock. */ - if ( lock_lock( qlock ) != 0 ) - error( "Locking the qlock failed.\n" ); + if ( blocking ) { + if ( lock_lock( qlock ) != 0 ) + error( "Locking the qlock failed.\n" ); + } + else { + if ( lock_trylock( qlock ) != 0 ) + return NULL; + } /* Set some pointers we will use often. */ qtid = q->tid; @@ -221,7 +227,7 @@ struct task *queue_gettask ( struct queue *q , int qid , struct cell *super , in error( "Unlocking the qlock failed.\n" ); /* Leave? */ - if ( res != NULL || !blocking ) + if ( res != NULL ) break; } /* while there are tasks. */ diff --git a/src/scheduler.c b/src/scheduler.c index a285caa3083b3db0931bb8a214f6d7f90ef67e9b..3b08ad9d5a372c53b0509c84c13b71453409cb61 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -850,7 +850,7 @@ struct task *scheduler_gettask ( struct scheduler *s , int qid , struct cell *su for ( int tries = 0 ; res == NULL && s->waiting && tries < scheduler_maxtries ; tries++ ) { /* Try to get a task from the suggested queue. */ - if ( ( res = queue_gettask( &s->queues[qid] , qid , super , 0 ) ) != NULL ) + if ( s->queues[qid].count > 0 && ( res = queue_gettask( &s->queues[qid] , qid , super , 1 ) ) != NULL ) break; /* If unsucessful, try stealing from the other queues. */