btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / headers / private / kernel / util / ring_buffer.h
blobfd1b78000f933e64d3e46c4dc97225b152b596b0
1 /*
2 * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef RING_BUFFER_H
6 #define RING_BUFFER_H
9 #include <OS.h>
12 struct iovec;
15 struct ring_buffer {
16 int32 first;
17 int32 in;
18 int32 size;
19 uint8 buffer[0];
23 // flags for create_ring_buffer_etc()
24 #define RING_BUFFER_INIT_FROM_BUFFER 0x01
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
31 struct ring_buffer *create_ring_buffer(size_t size);
32 struct ring_buffer *create_ring_buffer_etc(void *memory, size_t size,
33 uint32 flags);
34 void delete_ring_buffer(struct ring_buffer *buffer);
36 void ring_buffer_clear(struct ring_buffer *buffer);
37 size_t ring_buffer_readable(struct ring_buffer *buffer);
38 size_t ring_buffer_writable(struct ring_buffer *buffer);
39 void ring_buffer_flush(struct ring_buffer *buffer, size_t bytes);
40 size_t ring_buffer_read(struct ring_buffer *buffer, uint8 *data, ssize_t length);
41 size_t ring_buffer_write(struct ring_buffer *buffer, const uint8 *data, ssize_t length);
42 ssize_t ring_buffer_user_read(struct ring_buffer *buffer, uint8 *data, ssize_t length);
43 ssize_t ring_buffer_user_write(struct ring_buffer *buffer, const uint8 *data, ssize_t length);
44 size_t ring_buffer_peek(struct ring_buffer *buffer, size_t offset, void *data,
45 size_t length);
46 int32 ring_buffer_get_vecs(struct ring_buffer *buffer, struct iovec *vecs);
48 #ifdef __cplusplus
50 #endif
53 #endif /* RING_BUFFER_H */