4 #include "threads/interrupt.h"
5 #include "threads/synch.h"
7 /* An "interrupt queue", a circular buffer shared between
8 kernel threads and external interrupt handlers.
10 These functions can be called from kernel threads or from
11 external interrupt handlers. Except for intq_init(),
12 interrupts must be off in either case.
14 Incidentally, this has the structure of a "monitor". Normally
15 we'd use locks and condition variables from threads/synch.h to
16 implement a monitor, but those are intended only to protect
17 kernel threads from one another, not from interrupt
20 /* Queue buffer size, in bytes. */
21 #define INTQ_BUFSIZE 64
23 /* A circular queue of bytes. */
26 /* Waiting threads. */
27 struct lock lock; /* Only one thread may wait at once. */
28 struct thread *not_full; /* Thread waiting for not-full condition. */
29 struct thread *not_empty; /* Thread waiting for not-empty condition. */
32 uint8_t buf[INTQ_BUFSIZE]; /* Buffer. */
33 int head; /* New data is written here. */
34 int tail; /* Old data is read here. */
37 void intq_init (struct intq *);
38 bool intq_empty (const struct intq *);
39 bool intq_full (const struct intq *);
40 uint8_t intq_getc (struct intq *);
41 void intq_putc (struct intq *, uint8_t);
43 #endif /* devices/intq.h */