| 1 |
|
|---|
| 2 | #ifndef SH_FIFO_H
|
|---|
| 3 | #define SH_FIFO_H
|
|---|
| 4 |
|
|---|
| 5 | /*****************************************************
|
|---|
| 6 | *
|
|---|
| 7 | * the maximum number of entries the fifo will hold
|
|---|
| 8 | * - additional entries are simply not accepted -
|
|---|
| 9 | *
|
|---|
| 10 | *****************************************************/
|
|---|
| 11 |
|
|---|
| 12 | #define SH_FIFO_MAX 16384
|
|---|
| 13 |
|
|---|
| 14 | /*****************************************************
|
|---|
| 15 | *
|
|---|
| 16 | * the type definitions for the fifo
|
|---|
| 17 | *
|
|---|
| 18 | *****************************************************/
|
|---|
| 19 |
|
|---|
| 20 | struct dlist {
|
|---|
| 21 | struct dlist * next;
|
|---|
| 22 | char * data;
|
|---|
| 23 | char * s_xtra;
|
|---|
| 24 | int i_xtra;
|
|---|
| 25 | int transact;
|
|---|
| 26 | struct dlist * prev;
|
|---|
| 27 | };
|
|---|
| 28 |
|
|---|
| 29 | typedef struct fifo_str {
|
|---|
| 30 | struct dlist * head_ptr;
|
|---|
| 31 | struct dlist * tail_ptr;
|
|---|
| 32 | int fifo_cts;
|
|---|
| 33 | } SH_FIFO;
|
|---|
| 34 |
|
|---|
| 35 | /*****************************************************
|
|---|
| 36 | *
|
|---|
| 37 | * fifo functions
|
|---|
| 38 | *
|
|---|
| 39 | *****************************************************/
|
|---|
| 40 |
|
|---|
| 41 | /* Initialize the list.
|
|---|
| 42 | *
|
|---|
| 43 | */
|
|---|
| 44 | #define fifo_init(fifo_p) { fifo_p->fifo_cts = 0; fifo_p->head_ptr = NULL; \
|
|---|
| 45 | fifo_p->tail_ptr = NULL; }
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 | /* Push an item on the head of the list.
|
|---|
| 49 | *
|
|---|
| 50 | * Returns: -1 if the list is full, 0 on success
|
|---|
| 51 | */
|
|---|
| 52 | int push_list (SH_FIFO * fifo, char * indat, int in_i, const char * in_str);
|
|---|
| 53 |
|
|---|
| 54 | /* Push an item on the tail of the list.
|
|---|
| 55 | *
|
|---|
| 56 | * Returns: -1 if the list is full, 0 on success
|
|---|
| 57 | */
|
|---|
| 58 | int push_tail_list (SH_FIFO * fifo, char * indat, int in_i, const char * in_str);
|
|---|
| 59 |
|
|---|
| 60 | /* pop an item from the tail of the list
|
|---|
| 61 | *
|
|---|
| 62 | * Returns: NULL if the list is empty,
|
|---|
| 63 | * freshly allocated memory on success (should be free'd by caller)
|
|---|
| 64 | */
|
|---|
| 65 | char * pop_list (SH_FIFO * fifo);
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 | sh_string * tag_list (SH_FIFO * fifo, char * tag,
|
|---|
| 69 | int(*check)(int, const char*, const char*, const void*),
|
|---|
| 70 | const void * info, int okNull);
|
|---|
| 71 | void rollback_list (SH_FIFO * fifo);
|
|---|
| 72 | void mark_list (SH_FIFO * fifo);
|
|---|
| 73 | void reset_list (SH_FIFO * fifo);
|
|---|
| 74 | int commit_list (SH_FIFO * fifo);
|
|---|
| 75 |
|
|---|
| 76 | #endif
|
|---|