xref: /haiku/headers/private/kernel/util/ring_buffer.h (revision e1c4049fed1047bdb957b0529e1921e97ef94770)
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
7 
8 
9 #include <OS.h>
10 
11 
12 struct iovec;
13 
14 
15 struct ring_buffer {
16 	int32		first;
17 	int32		in;
18 	int32		size;
19 	uint8		buffer[0];
20 };
21 
22 
23 // flags for create_ring_buffer_etc()
24 #define RING_BUFFER_INIT_FROM_BUFFER	0x01
25 
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
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);
35 
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);
47 size_t ring_buffer_move(struct ring_buffer *to, ssize_t length, struct ring_buffer *from);
48 
49 #ifdef __cplusplus
50 }
51 #endif
52 
53 
54 #endif	/* RING_BUFFER_H */
55