Semi-decennial update. 50% code inflation.
[cbaos.git] / include / bip_buf.h
blobd04e9bf9b92125afbbc182647f89f6db73e98624
1 #ifndef BIP_BUF_H_
2 #define BIP_BUF_H_
3 /* Author: Domen Puncer Kugler <domen@cba.si>. License: WTFPL, see file LICENSE */
5 #include <types.h>
7 struct bip_buf {
8 u8 *data;
9 unsigned size;
10 volatile unsigned head; /* points to first free byte */
11 volatile unsigned tail; /* points to first used byte */
12 volatile unsigned tailwrap;
13 /* extreme case tail == head: all free;
14 * tail == head+1: all full (last byte can't be used)
15 * ____tailxxxxxxxxhead_____
16 * xxxxhead________tailxxxxx
20 void bip_buf_init(struct bip_buf *cb, void *buf, unsigned size);
22 void* bip_buf_alloc(struct bip_buf *cb, unsigned len);
23 /* len here must be exactly the same as for _alloc() */
24 void bip_buf_alloc_commit(struct bip_buf *cb, unsigned len);
26 void* bip_buf_getdata(struct bip_buf *cb);
27 void bip_buf_free(struct bip_buf *cb, unsigned len);
29 #endif