-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbitfifo.h
92 lines (66 loc) · 2.23 KB
/
bitfifo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* bitfifo.h -- fifo which stores bits */
/**
* \file bitfifo.h
*
* A fifo which stores bits.
*/
#ifndef DATASTRUCT_BITFIFO_H
#define DATASTRUCT_BITFIFO_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <stddef.h>
#include "base/result.h"
/* ----------------------------------------------------------------------- */
#define result_BITFIFO_EMPTY (result_BASE_BITFIFO + 0)
#define result_BITFIFO_FULL (result_BASE_BITFIFO + 1)
#define result_BITFIFO_INSUFFICIENT (result_BASE_BITFIFO + 2)
/* ----------------------------------------------------------------------- */
#define T bitfifo_t
/**
* A bit fifo's type.
*/
typedef struct bitfifo T;
/* ----------------------------------------------------------------------- */
/**
* Create a bitfifo.
*
* \param nbits Minimum number of bits that the bitfifo should store.
*
* \return New bitfifo or NULL if OOM.
*/
bitfifo_t *bitfifo_create(int nbits);
/**
* Destroy a bitfifo.
*
* \param doomed bitfifo to destroy.
*/
void bitfifo_destroy(T *doomed);
/* ----------------------------------------------------------------------- */
/* writes bits to 'head' onwards, wrapping around if required */
/* fifo will reject attempts to store more bits than there is space for */
result_t bitfifo_enqueue(T *fifo,
const unsigned int *newbits,
unsigned int newbitsoffset,
size_t nnewbits);
/* reads bits from 'tail' onwards, wrapping around if required */
result_t bitfifo_dequeue(T *fifo,
unsigned int *outbits,
size_t noutbits);
/* ----------------------------------------------------------------------- */
/* empty the specified fifo */
void bitfifo_clear(T *fifo);
/* returns number of used bits in the fifo */
size_t bitfifo_used(const T *fifo);
/* returns non-zero if the fifo is full */
int bitfifo_full(const T *fifo);
/* returns non-zero if the fifo is empty */
int bitfifo_empty(const T *fifo);
/* ----------------------------------------------------------------------- */
#undef T
/* ----------------------------------------------------------------------- */
#ifdef __cplusplus
}
#endif
#endif /* DATASTRUCT_BITFIFO_H */