Debian Codegraph @

listings/chapter-4/job-queue1.c

raw
1 /***********************************************************************
2 * Code listing from "Advanced Linux Programming," by CodeSourcery LLC *
3 * Copyright (C) 2001 by New Riders Publishing *
4 * See COPYRIGHT for license information. *
5 ***********************************************************************/
6
7 #include <malloc.h>
8
9 struct job {
10 /* Link field for linked list. */
11 struct job* next;
12
13 /* Other fields describing work to be done... */
14 };
15
16 /* A linked list of pending jobs. */
17 struct job* job_queue;
18
19 extern void process_job (struct job*);
20
21 /* Process queued jobs until the queue is empty. */
22
23 void* thread_function (void* arg)
24 {
25 while (job_queue != NULL) {
26 /* Get the next available job. */
27 struct job* next_job = job_queue;
28 /* Remove this job from the list. */
29 job_queue = job_queue->next;
30 /* Carry out the work. */
31 process_job (next_job);
32 /* Clean up. */
33 free (next_job);
34 }
35 return NULL;
36 }