CS318 - Pintos
Pintos source browser for JHU CS318 course
intq.h
Go to the documentation of this file.
1 #ifndef DEVICES_INTQ_H
2 #define DEVICES_INTQ_H
3 
4 #include "threads/interrupt.h"
5 #include "threads/synch.h"
6 
7 /** An "interrupt queue", a circular buffer shared between
8  kernel threads and external interrupt handlers.
9 
10  Interrupt queue functions can be called from kernel threads or
11  from external interrupt handlers. Except for intq_init(),
12  interrupts must be off in either case.
13 
14  The interrupt queue has the structure of a "monitor". Locks
15  and condition variables from threads/synch.h cannot be used in
16  this case, as they normally would, because they can only
17  protect kernel threads from one another, not from interrupt
18  handlers. */
19 
20 /** Queue buffer size, in bytes. */
21 #define INTQ_BUFSIZE 64
22 
23 /** A circular queue of bytes. */
24 struct intq
25  {
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. */
30 
31  /* Queue. */
32  uint8_t buf[INTQ_BUFSIZE]; /**< Buffer. */
33  int head; /**< New data is written here. */
34  int tail; /**< Old data is read here. */
35  };
36 
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);
42 
43 #endif /**< devices/intq.h */
intq_empty
bool intq_empty(const struct intq *)
Returns true if Q is empty, false otherwise.
Definition: intq.c:20
uint8_t
unsigned char uint8_t
Definition: stdint.h:20
thread
A kernel thread or user process.
Definition: thread.h:83
intq::buf
uint8_t buf[INTQ_BUFSIZE]
Buffer.
Definition: intq.h:32
intq_full
bool intq_full(const struct intq *)
Returns true if Q is full, false otherwise.
Definition: intq.c:28
interrupt.h
intq_getc
uint8_t intq_getc(struct intq *)
Removes a byte from Q and returns it.
Definition: intq.c:38
INTQ_BUFSIZE
#define INTQ_BUFSIZE
An "interrupt queue", a circular buffer shared between kernel threads and external interrupt handlers...
Definition: intq.h:21
intq::head
int head
New data is written here.
Definition: intq.h:33
intq::not_empty
struct thread * not_empty
Thread waiting for not-empty condition.
Definition: intq.h:29
intq::tail
int tail
Old data is read here.
Definition: intq.h:34
intq
A circular queue of bytes.
Definition: intq.h:24
intq_init
void intq_init(struct intq *)
Initializes interrupt queue Q.
Definition: intq.c:11
intq::not_full
struct thread * not_full
Thread waiting for not-full condition.
Definition: intq.h:28
synch.h
lock
Lock.
Definition: synch.h:21
intq_putc
void intq_putc(struct intq *, uint8_t)
devices/intq.h
Definition: intq.c:61