From cfa54797c81c302a42619fa108cae2db8d461d79 Mon Sep 17 00:00:00 2001
From: Pedro Gonnet <pedro.gonnet@durham.ac.uk>
Date: Fri, 5 Jul 2013 12:42:19 +0000
Subject: [PATCH] re-define queue blocking param.

Former-commit-id: 3d8bc9a2652a01e3587a4d2439758dd758774ff8
---
 src/queue.c     | 12 +++++++++---
 src/scheduler.c |  2 +-
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/queue.c b/src/queue.c
index 2126783da4..dc601abfd1 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 a285caa308..3b08ad9d5a 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. */
-- 
GitLab