source: rtems/cpukit/score/include/rtems/score/freechain.h @ fdb45d6

4.115
Last change on this file since fdb45d6 was fdb45d6, checked in by Sebastian Huber <sebastian.huber@…>, on 06/24/15 at 12:00:08

score: Freechain handler API changes

Replace the extend function with an allocator since this fits better
to the current use case.

  • Property mode set to 100644
File size: 2.5 KB
Line 
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
23extern "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 */
41typedef void *( *Freechain_Allocator )( size_t size );
42
43/**
44 * @brief The freechain control.
45 */
46typedef 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 */
65void _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 */
85void *_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.
97 */
98void _Freechain_Put(
99  Freechain_Control *freechain,
100  void              *node
101);
102
103/**@}*/
104
105#ifdef __cplusplus
106}
107#endif
108
109#endif
110/* end of include file */
Note: See TracBrowser for help on using the repository browser.