00001 #ifndef DEVICES_INTQ_H 00002 //3111214044 00003 #define DEVICES_INTQ_H 00004 00005 #include "threads/interrupt.h" 00006 #include "threads/synch.h" 00007 00008 /* An "interrupt queue", a circular buffer shared between 00009 kernel threads and external interrupt handlers. 00010 00011 Interrupt queue functions can be called from kernel threads or 00012 from external interrupt handlers. Except for intq_init(), 00013 interrupts must be off in either case. 00014 00015 The interrupt queue has the structure of a "monitor". Locks 00016 and condition variables from threads/synch.h cannot be used in 00017 this case, as they normally would, because they can only 00018 protect kernel threads from one another, not from interrupt 00019 handlers. */ 00020 00021 /* Queue buffer size, in bytes. */ 00022 #define INTQ_BUFSIZE 64 00023 00024 /* A circular queue of bytes. */ 00025 struct intq 00026 { 00027 /* Waiting threads. */ 00028 struct lock lock; /* Only one thread may wait at once. */ 00029 struct thread *not_full; /* Thread waiting for not-full condition. */ 00030 struct thread *not_empty; /* Thread waiting for not-empty condition. */ 00031 00032 /* Queue. */ 00033 uint8_t buf[INTQ_BUFSIZE]; /* Buffer. */ 00034 int head; /* New data is written here. */ 00035 int tail; /* Old data is read here. */ 00036 }; 00037 00038 void intq_init (struct intq *); 00039 bool intq_empty (const struct intq *); 00040 bool intq_full (const struct intq *); 00041 uint8_t intq_getc (struct intq *); 00042 void intq_putc (struct intq *, uint8_t); 00043 00044 #endif /* devices/intq.h */