Skip to content
Snippets Groups Projects
Commit 7b7eaca9 authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

added flag to wait for queue lock or not.

parent d547fdaf
Branches
No related tags found
No related merge requests found
......@@ -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 ];
......
......@@ -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 );
......
......@@ -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 );
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment