Changeset d0a0f12 in mainline for generic/include/adt/fifo.h
- Timestamp:
- 2006-02-10T14:12:57Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0882a9a
- Parents:
- a3eeceb6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
generic/include/adt/fifo.h
ra3eeceb6 rd0a0f12 28 28 29 29 /* 30 * This implementation of FIFO stores values in a statically31 * allocated array created on each FIFO's initialization.32 * As such, these FIFOs have upper bound on number of values33 * they can store. Push and pop operations are done via accessing34 * the array through head and tail indices. Because of better35 * operation ordering in fifo_pop(), the access policy for these36 * two indices is to 'increment (mod size of FIFO)and use'.30 * This implementation of FIFO stores values in an array 31 * (static or dynamic). As such, these FIFOs have upper bound 32 * on number of values they can store. Push and pop operations 33 * are done via accessing the array through head and tail indices. 34 * Because of better operation ordering in fifo_pop(), the access 35 * policy for these two indices is to 'increment (mod size of FIFO) 36 * and use'. 37 37 */ 38 38 … … 41 41 42 42 #include <typedefs.h> 43 #include <mm/slab.h> 43 44 44 /** Create and initialize FIFO. 45 /** Create and initialize static FIFO. 46 * 47 * FIFO is allocated statically. 48 * This macro is suitable for creating smaller FIFOs. 45 49 * 46 50 * @param name Name of FIFO. … … 48 52 * @param itms Number of items that can be stored in FIFO. 49 53 */ 50 #define FIFO_INITIALIZE (name, t, itms)\54 #define FIFO_INITIALIZE_STATIC(name, t, itms) \ 51 55 struct { \ 52 56 t fifo[(itms)]; \ … … 55 59 index_t tail; \ 56 60 } name = { \ 61 .items = (itms), \ 62 .head = 0, \ 63 .tail = 0 \ 64 } 65 66 /** Create and prepare dynamic FIFO. 67 * 68 * FIFO is allocated dynamically. 69 * This macro is suitable for creating larger FIFOs. 70 * 71 * @param name Name of FIFO. 72 * @param t Type of values stored in FIFO. 73 * @param itms Number of items that can be stored in FIFO. 74 */ 75 #define FIFO_INITIALIZE_DYNAMIC(name, t, itms) \ 76 struct { \ 77 t *fifo; \ 78 count_t items; \ 79 index_t head; \ 80 index_t tail; \ 81 } name = { \ 82 .fifo = NULL, \ 57 83 .items = (itms), \ 58 84 .head = 0, \ … … 78 104 name.fifo[name.tail = (name.tail + 1) < name.items ? (name.tail + 1) : 0] = (value) 79 105 106 /** Allocate memory for dynamic FIFO. 107 * 108 * @param name FIFO name. 109 */ 110 #define fifo_create(name) \ 111 name.fifo = malloc(sizeof(*name.fifo) * name.items, 0) 112 80 113 #endif
Note:
See TracChangeset
for help on using the changeset viewer.