1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup ScoreFreechain |
---|
5 | * |
---|
6 | * @brief Freechain Handler API |
---|
7 | */ |
---|
8 | /* |
---|
9 | * Copyright (c) 2013 Gedare Bloom. |
---|
10 | * |
---|
11 | * The license and distribution terms for this file may be |
---|
12 | * found in the file LICENSE in this distribution or at |
---|
13 | * http://www.rtems.org/license/LICENSE. |
---|
14 | */ |
---|
15 | |
---|
16 | #ifndef _RTEMS_SCORE_FREECHAIN_H |
---|
17 | #define _RTEMS_SCORE_FREECHAIN_H |
---|
18 | |
---|
19 | #include <rtems/score/basedefs.h> |
---|
20 | #include <rtems/score/chain.h> |
---|
21 | |
---|
22 | #ifdef __cplusplus |
---|
23 | extern "C" { |
---|
24 | #endif |
---|
25 | |
---|
26 | /** |
---|
27 | * @defgroup ScoreFreechain Freechain Handler |
---|
28 | * |
---|
29 | * @ingroup Score |
---|
30 | * |
---|
31 | * The Freechain Handler is used to manage a chain of nodes, of which size can |
---|
32 | * automatically increase when there is no free node left. This handler |
---|
33 | * provides one data structure: Freechain_Control. |
---|
34 | * |
---|
35 | * @{ |
---|
36 | */ |
---|
37 | |
---|
38 | /** |
---|
39 | * @brief Allocator function. |
---|
40 | */ |
---|
41 | typedef void *( *Freechain_Allocator )( size_t size ); |
---|
42 | |
---|
43 | /** |
---|
44 | * @brief The freechain control. |
---|
45 | */ |
---|
46 | typedef struct { |
---|
47 | /** |
---|
48 | * @brief Chain of free nodes. |
---|
49 | */ |
---|
50 | Chain_Control Free; |
---|
51 | } Freechain_Control; |
---|
52 | |
---|
53 | /** |
---|
54 | * @brief Initializes a freechain. |
---|
55 | * |
---|
56 | * This routine initializes the freechain control structure to manage a chain |
---|
57 | * of nodes. In case the freechain is empty the extend handler is called to |
---|
58 | * get more nodes. |
---|
59 | * |
---|
60 | * @param[in] freechain The freechain control to initialize. |
---|
61 | * @param[in] allocator The allocator function. |
---|
62 | * @param[in] number_nodes The initial number of nodes. |
---|
63 | * @param[in] node_size The node size. |
---|
64 | */ |
---|
65 | void _Freechain_Initialize( |
---|
66 | Freechain_Control *freechain, |
---|
67 | Freechain_Allocator allocator, |
---|
68 | size_t number_nodes, |
---|
69 | size_t node_size |
---|
70 | ); |
---|
71 | |
---|
72 | /** |
---|
73 | * @brief Gets a node from the freechain. |
---|
74 | * |
---|
75 | * @param[in] freechain The freechain control. |
---|
76 | * @param[in] allocator The allocator function. |
---|
77 | * @param[in] number_nodes_to_extend The number of nodes in case an extend is |
---|
78 | * necessary due to an empty freechain. |
---|
79 | * @param[in] node_size The node size. |
---|
80 | * |
---|
81 | * @retval NULL The freechain is empty and the extend operation failed. |
---|
82 | * @retval otherwise Pointer to a node. The node ownership passes to the |
---|
83 | * caller. |
---|
84 | */ |
---|
85 | void *_Freechain_Get( |
---|
86 | Freechain_Control *freechain, |
---|
87 | Freechain_Allocator allocator, |
---|
88 | size_t number_nodes_to_extend, |
---|
89 | size_t node_size |
---|
90 | ); |
---|
91 | |
---|
92 | /** |
---|
93 | * @brief Puts a node back onto the freechain. |
---|
94 | * |
---|
95 | * @param[in] freechain The freechain control. |
---|
96 | * @param[in] node The node to put back. The node may be @c NULL, in this case |
---|
97 | * the function does nothing. |
---|
98 | */ |
---|
99 | void _Freechain_Put( |
---|
100 | Freechain_Control *freechain, |
---|
101 | void *node |
---|
102 | ); |
---|
103 | |
---|
104 | /**@}*/ |
---|
105 | |
---|
106 | #ifdef __cplusplus |
---|
107 | } |
---|
108 | #endif |
---|
109 | |
---|
110 | #endif |
---|
111 | /* end of include file */ |
---|