diff --git a/src/qsched.c b/src/qsched.c index d0bfa76b67fe8023f5f6c322f234e6e6fa7cb214..e95cfdae39dee8adf37afd8ae702a82220e1ae1f 100644 --- a/src/qsched.c +++ b/src/qsched.c @@ -719,7 +719,7 @@ struct task *qsched_gettask ( struct qsched *s , int qid ) { /* Try to get a task from my own queue. */ { TIMER_TIC - tid = queue_get( &s->queues[qid] , s ); + tid = queue_get( &s->queues[qid] , s , 1 ); TIMER_TOC( s , qsched_timer_queue ) if ( tid < 0 ) { @@ -730,7 +730,7 @@ struct task *qsched_gettask ( struct qsched *s , int qid ) { while ( naq > 0 ) { k = rand() % naq; TIMER_TIC2 - tid = queue_get( &s->queues[ qids[k] ] , s ); + tid = queue_get( &s->queues[ qids[k] ] , s , 0 ); TIMER_TOC( s , qsched_timer_queue ) if ( tid < 0 ) qids[k] = qids[ --naq ]; diff --git a/src/queue.c b/src/queue.c index 8d5022d48362af743d49d9a6c47cd166021689c0..30d120d1c3e7deb4103568f149524a3fcffa792b 100644 --- a/src/queue.c +++ b/src/queue.c @@ -40,11 +40,12 @@ * * @param q The #queue. * @param s The #sched in which this queue's tasks lives. + * @param insists If set, wait at the queue's lock, otherwise fail. * * @return The task ID or -1 if no available task could be found. */ -int queue_get ( struct queue *q , struct qsched *s ) { +int queue_get ( struct queue *q , struct qsched *s , int insist ) { int k, j, temp, tid, *inds, w, count; struct task *tasks = s->tasks; @@ -55,8 +56,12 @@ int queue_get ( struct queue *q , struct qsched *s ) { /* Lock this queue. */ TIMER_TIC - if ( lock_lock( &q->lock ) != 0 ) - error( "Failed to lock queue." ); + if ( insist ) { + if ( lock_lock( &q->lock ) != 0 ) + error( "Failed to lock queue." ); + } + else if ( lock_trylock( &q->lock ) != 0 ) + return qsched_task_none; TIMER_TOC( s , qsched_timer_qlock ); /* Get a pointer to the indices. */ @@ -103,7 +108,7 @@ int queue_get ( struct queue *q , struct qsched *s ) { /* Otherwise, clear the task ID. */ else - tid = -1; + tid = qsched_task_none; /* Unlock the queue. */ lock_unlock_blind( &q->lock ); diff --git a/src/queue.h b/src/queue.h index 16895ca2665baa620b46322950e15ed2667639db..10d268e5da18173d7d09ba21d9a12af1f97a3820 100644 --- a/src/queue.h +++ b/src/queue.h @@ -36,11 +36,11 @@ struct queue { /* Maximum number of tasks in queue. */ int size; - }; + } __attribute__((aligned (128))); /* Function prototypes. */ -int queue_get ( struct queue *q , struct qsched *s ); +int queue_get ( struct queue *q , struct qsched *s , int insist ); void queue_put ( struct queue *q , struct qsched *s , int tid ); void queue_init ( struct queue *q , int size ); void queue_free ( struct queue *q );