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
13struct 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 */
24struct packet_buffer {
25	struct ring_buffer*	buffer;
26	spinlock			lock;
27};
28
29
30struct packet_buffer* create_packet_buffer(size_t size);
31void delete_packet_buffer(struct packet_buffer* buffer);
32
33void packet_buffer_clear(struct packet_buffer* buffer);
34size_t packet_buffer_readable(struct packet_buffer* buffer);
35size_t packet_buffer_writable(struct packet_buffer *buffer);
36void packet_buffer_flush(struct packet_buffer* buffer, size_t bytes);
37size_t packet_buffer_read(struct packet_buffer* buffer, uint8* data, size_t
38	length);
39size_t packet_buffer_write(struct packet_buffer* buffer, const uint8* data,
40	size_t length);
41
42#endif	/* PACKET_BUFFER_H */
43