1 // Copyright 2017 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #pragma once
6 
7 #include <stdbool.h>
8 #include <stdint.h>
9 #include <stdlib.h>
10 
11 #include <zircon/compiler.h>
12 
13 __BEGIN_CDECLS;
14 
15 #define PTY_FIFO_SIZE (4096)
16 
17 typedef struct pty_fifo {
18     uint32_t head;
19     uint32_t tail;
20     uint8_t data[PTY_FIFO_SIZE];
21 } pty_fifo_t;
22 
23 size_t pty_fifo_read(pty_fifo_t* fifo, void* data, size_t len);
24 size_t pty_fifo_write(pty_fifo_t* fifo, const void* data, size_t len, bool atomic);
25 
pty_fifo_is_empty(pty_fifo_t * fifo)26 static inline bool pty_fifo_is_empty(pty_fifo_t* fifo) {
27     return fifo->head == fifo->tail;
28 }
29 
pty_fifo_is_full(pty_fifo_t * fifo)30 static inline bool pty_fifo_is_full(pty_fifo_t* fifo) {
31     return (fifo->head - fifo->tail) == PTY_FIFO_SIZE;
32 }
33 
34 __END_CDECLS;
35