Debian Codegraph @

i386/i386at/kd_queue.c

raw
1 /*
2 * Mach Operating System
3 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
11 *
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15 *
16 * Carnegie Mellon requests users of this software to return to
17 *
18 * Software Distribution Coordinator or [email protected]
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
22 *
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
25 */
26 /* **********************************************************************
27 File: kd_queue.c
28 Description: Event queue code for keyboard/display (and mouse) driver.
29
30 $ Header: $
31
32 Copyright Ing. C. Olivetti & C. S.p.A. 1989.
33 All rights reserved.
34 ********************************************************************** */
35 /*
36 Copyright 1988, 1989 by Olivetti Advanced Technology Center, Inc.,
37 Cupertino, California.
38
39 All Rights Reserved
40
41 Permission to use, copy, modify, and distribute this software and
42 its documentation for any purpose and without fee is hereby
43 granted, provided that the above copyright notice appears in all
44 copies and that both the copyright notice and this permission notice
45 appear in supporting documentation, and that the name of Olivetti
46 not be used in advertising or publicity pertaining to distribution
47 of the software without specific, written prior permission.
48
49 OLIVETTI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
50 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
51 IN NO EVENT SHALL OLIVETTI BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
52 CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
53 LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
54 NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUR OF OR IN CONNECTION
55 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
56 */
57
58
59 #include <i386at/kd_queue.h>
60
61 /*
62 * Notice that when adding an entry to the queue, the caller provides
63 * its own storage, which is copied into the queue. However, when
64 * removing an entry from the queue, the caller is given a pointer to a
65 * queue element. This means that the caller must either process the
66 * element or copy it into its own storage before unlocking the queue.
67 *
68 * These routines should be called only at a protected SPL.
69 */
70
71 #define q_next(index) (((index)+1) % KDQSIZE)
72
73 boolean_t
74 kdq_empty(const kd_event_queue *q)
75 {
76 return(q->firstfree == q->firstout);
77 }
78
79 boolean_t
80 kdq_full(const kd_event_queue *q)
81 {
82 return(q_next(q->firstfree) == q->firstout);
83 }
84
85 void
86 kdq_put(kd_event_queue *q, kd_event *ev)
87 {
88 kd_event *qp = q->events + q->firstfree;
89
90 qp->type = ev->type;
91 qp->unused_time = ev->unused_time;
92 qp->value = ev->value;
93 q->firstfree = q_next(q->firstfree);
94 }
95
96 kd_event *
97 kdq_get(kd_event_queue *q)
98 {
99 kd_event *result = q->events + q->firstout;
100
101 q->firstout = q_next(q->firstout);
102 return(result);
103 }
104
105 void
106 kdq_reset(kd_event_queue *q)
107 {
108 q->firstout = q->firstfree = 0;
109 }