Removed duplicate variable for turbo marcxml (using_turbo_format). Now works in zooms...
[yaz-moved-to-github.git] / src / requestq.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2010 Index Data
3  * See the file LICENSE for details.
4  */
5 /**
6  * \file requestq.c
7  * \brief Implements Simple queue management for GFS.
8  *
9  * We also use the request-freelist to store encoding buffers, rather than
10  * freeing and xmalloc'ing them on each cycle.
11  */
12
13 #include <stdlib.h>
14
15 #include <yaz/xmalloc.h>
16 #include "session.h"
17
18 void request_enq(request_q *q, request *r)
19 {
20     if (q->tail)
21         q->tail->next = r;
22     else
23         q->head = r;
24     q->tail = r;
25     q->num++;
26 }
27
28 request *request_head(request_q *q)
29 {
30     return q->head;
31 }
32
33 request *request_deq(request_q *q)
34 {
35     request *r = q->head;
36
37     if (!r)
38         return 0;
39     q->head = q->head->next;
40     if (!q->head)
41         q->tail = 0;
42     q->num--;
43     return r;
44 }
45
46 void request_initq(request_q *q)
47 {
48     q->head = q->tail = q->list = 0;
49     q->num = 0;
50 }
51
52 void request_delq(request_q *q)
53 {
54     request *r1, *r = q->list;
55     while (r)
56     {
57         xfree (r->response);
58         r1 = r;
59         r = r->next;
60         xfree (r1);
61     }
62 }
63
64 request *request_get(request_q *q)
65 {
66     request *r = q->list;
67
68     if (r)
69         q->list = r->next;
70     else
71     {
72         if (!(r = (request *)xmalloc(sizeof(*r))))
73             abort();
74         r->response = 0;
75         r->size_response = 0;
76     }
77     r->q = q;
78     r->gdu_request = 0;
79     r->apdu_request = 0;
80     r->request_mem = 0;
81     r->len_response = 0;
82     r->clientData = 0;
83     r->state = REQUEST_IDLE;
84     r->next = 0;
85     return r;
86 }
87
88 void request_release(request *r)
89 {
90     request_q *q = r->q;
91     r->next = q->list;
92     q->list = r;
93 }
94
95 /*
96  * Local variables:
97  * c-basic-offset: 4
98  * c-file-style: "Stroustrup"
99  * indent-tabs-mode: nil
100  * End:
101  * vim: shiftwidth=4 tabstop=8 expandtab
102  */
103