make log a bit verbose for some useful information
[lunaix-os.git] / lunaix-os / includes / lunaix / ds / flipbuf.h
1 #ifndef __LUNAIX_FLIPBUF_H
2 #define __LUNAIX_FLIPBUF_H
3
4 #include <lunaix/types.h>
5 #include <lunaix/spike.h>
6
7 struct flipbuf
8 {
9     void* buf;
10     void* top;
11     unsigned long half_size;
12 };
13
14 #define DEFINE_FLIPBUF(name, halfsz, buf_) \
15             struct flipbuf name = { .buf=buf_, .top=buf_, .half_size=halfsz }
16
17 static inline void*
18 flipbuf_under(struct flipbuf* fbuf)
19 {
20     ptr_t off;
21
22     off  = __ptr(fbuf->top);
23     off += fbuf->half_size;
24     off %= fbuf->half_size;
25     off += __ptr(fbuf->buf);
26     
27     return (void*)off;
28 }
29
30 static inline void*
31 flipbuf_top(struct flipbuf* fbuf)
32 {
33     return fbuf->top;
34 }
35
36 static inline void*
37 flipbuf_flip(struct flipbuf* fbuf)
38 {
39     fbuf->top = flipbuf_under(fbuf);
40     return fbuf->top;
41 }
42
43 #endif /* __LUNAIX_FLIPBUF_H */