Get first job from queue(removes it from queue) * * Notice: Caller MUST hold a mutex */
| 516 | * Notice: Caller MUST hold a mutex |
| 517 | */ |
| 518 | static struct job *jobqueue_pull(jobqueue *jobqueue_p) { |
| 519 | |
| 520 | pthread_mutex_lock(&jobqueue_p->rwmutex); |
| 521 | job *job_p = jobqueue_p->front; |
| 522 | |
| 523 | switch(jobqueue_p->len) { |
| 524 | |
| 525 | case 0: /* if no jobs in queue */ |
| 526 | break; |
| 527 | |
| 528 | case 1: /* if one job in queue */ |
| 529 | jobqueue_p->front = NULL; |
| 530 | jobqueue_p->rear = NULL; |
| 531 | jobqueue_p->len = 0; |
| 532 | break; |
| 533 | |
| 534 | default: /* if >1 jobs in queue */ |
| 535 | jobqueue_p->front = job_p->prev; |
| 536 | jobqueue_p->len--; |
| 537 | /* more than one job in queue -> post it */ |
| 538 | bsem_post(jobqueue_p->has_jobs); |
| 539 | } |
| 540 | |
| 541 | pthread_mutex_unlock(&jobqueue_p->rwmutex); |
| 542 | return job_p; |
| 543 | } |
| 544 | |
| 545 | /* Free all queue resources back to the system */ |
| 546 | static void jobqueue_destroy(jobqueue *jobqueue_p) { |
no test coverage detected