1 /* $Id: dqueue.c,v 1.5 2003/04/12 21:40:49 schindler Exp $
3 * Driver for Eicon DIVA Server ISDN cards.
4 * User Mode IDI Interface
6 * Copyright 2000-2003 by Armin Schindler (mac@melware.de)
7 * Copyright 2000-2003 Cytronics & Melware (info@melware.de)
9 * This software may be used and distributed according to the terms
10 * of the GNU General Public License, incorporated herein by reference.
17 diva_data_q_init(diva_um_idi_data_queue_t *q,
18 int max_length, int max_segments)
22 q->max_length = max_length;
23 q->segments = max_segments;
25 for (i = 0; i < q->segments; i++) {
29 q->read = q->write = q->count = q->segment_pending = 0;
31 for (i = 0; i < q->segments; i++) {
32 if (!(q->data[i] = diva_os_malloc(0, q->max_length))) {
41 int diva_data_q_finit(diva_um_idi_data_queue_t *q)
45 for (i = 0; i < q->segments; i++) {
47 diva_os_free(0, q->data[i]);
52 q->read = q->write = q->count = q->segment_pending = 0;
57 int diva_data_q_get_max_length(const diva_um_idi_data_queue_t *q)
59 return (q->max_length);
62 void *diva_data_q_get_segment4write(diva_um_idi_data_queue_t *q)
64 if ((!q->segment_pending) && (q->count < q->segments)) {
65 q->segment_pending = 1;
66 return (q->data[q->write]);
73 diva_data_q_ack_segment4write(diva_um_idi_data_queue_t *q, int length)
75 if (q->segment_pending) {
76 q->length[q->write] = length;
79 if (q->write >= q->segments) {
82 q->segment_pending = 0;
86 const void *diva_data_q_get_segment4read(const diva_um_idi_data_queue_t *
90 return (q->data[q->read]);
95 int diva_data_q_get_segment_length(const diva_um_idi_data_queue_t *q)
97 return (q->length[q->read]);
100 void diva_data_q_ack_segment4read(diva_um_idi_data_queue_t *q)
103 q->length[q->read] = 0;
106 if (q->read >= q->segments) {