xref: /haiku/src/add-ons/kernel/bus_managers/ps2/packet_buffer.h (revision 1e60bdeab63fa7a57bc9a55b032052e95a18bd2c)
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 PACKET_BUFFER_H
6 #define PACKET_BUFFER_H
7 
8 
9 #include <KernelExport.h>
10 #include <OS.h>
11 
12 
13 struct ring_buffer;
14 
15 
16 /**	The idea behind this packet buffer is to have multi-threading safe
17  *	implementation that can be used in interrupts on top of the
18  *	ring_buffer implementation provided by the kernel.
19  *	It uses a spinlock for synchronization.
20  *
21  *	IOW if you don't have such high restrictions in your environment,
22  *	you better don't want to use it at all.
23  */
24 struct packet_buffer {
25 	struct ring_buffer*	buffer;
26 	spinlock			lock;
27 };
28 
29 
30 struct packet_buffer* create_packet_buffer(size_t size);
31 void delete_packet_buffer(struct packet_buffer* buffer);
32 
33 void packet_buffer_clear(struct packet_buffer* buffer);
34 size_t packet_buffer_readable(struct packet_buffer* buffer);
35 size_t packet_buffer_writable(struct packet_buffer *buffer);
36 void packet_buffer_flush(struct packet_buffer* buffer, size_t bytes);
37 size_t packet_buffer_read(struct packet_buffer* buffer, uint8* data, size_t
38 	length);
39 size_t packet_buffer_write(struct packet_buffer* buffer, const uint8* data,
40 	size_t length);
41 
42 #endif	/* PACKET_BUFFER_H */
43