-static uint8_t
-queue_getc (struct queue *q)
-{
- uint8_t byte;
-
- ASSERT (owned_by_current_thread (q));
- while (queue_empty (q))
- wait (q, &q->not_empty);
-
- byte = q->buf[q->tail];
- q->tail = next (q->tail);
- signal (q, &q->not_full);
- return byte;
-}
-
-static void
-queue_putc (struct queue *q, uint8_t byte)
-{
- ASSERT (owned_by_current_thread (q));
- while (queue_full (q))
- wait (q, &q->not_full);
-
- q->buf[q->head] = byte;
- q->head = next (q->head);
- signal (q, &q->not_empty);
-}
-
-static int
-next (int pos)
-{
- return (pos + 1) % QUEUE_BUFSIZE;
-}
-
-static bool
-owned_by_current_thread (const struct queue *q)
-{
- return (intr_context ()
- || (lock_held_by_current_thread (&q->lock)
- && intr_get_level () == INTR_OFF));