1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2 /*
3 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
4 * University Research and Technology
5 * Corporation. All rights reserved.
6 * Copyright (c) 2004-2006 The University of Tennessee and The University
7 * of Tennessee Research Foundation. All rights
8 * reserved.
9 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
10 * University of Stuttgart. All rights reserved.
11 * Copyright (c) 2004-2005 The Regents of the University of California.
12 * All rights reserved.
13 * Copyright (c) 2015 Los Alamos National Security, LLC. All rights
14 * reserved.
15 * $COPYRIGHT$
16 *
17 * Additional copyrights may follow
18 *
19 * $HEADER$
20 */
21 /**
22 * @file
23 * The public definition of the MCA Allocator framework.
24 */
25 #ifndef MCA_ALLOCATOR_H
26 #define MCA_ALLOCATOR_H
27
28 #include "opal_config.h"
29 #include "opal/mca/mca.h"
30
31 BEGIN_C_DECLS
32
33 /* Here so that we can use mca_allocator_base_module_t in the function typedefs */
34 struct mca_allocator_base_module_t;
35
36 /**
37 * The allocate function typedef for the function to be provided by the component.
38 */
39 typedef void* (*mca_allocator_base_module_alloc_fn_t)(
40 struct mca_allocator_base_module_t*,
41 size_t size,
42 size_t align);
43
44 /**
45 * The realloc function typedef
46 */
47 typedef void* (*mca_allocator_base_module_realloc_fn_t)(
48 struct mca_allocator_base_module_t*,
49 void*, size_t);
50
51 /**
52 * Free function typedef
53 */
54 typedef void(*mca_allocator_base_module_free_fn_t)(
55 struct mca_allocator_base_module_t*, void *);
56
57
58 /**
59 * compact/return memory to higher level allocator
60 */
61
62 typedef int (*mca_allocator_base_module_compact_fn_t)(
63 struct mca_allocator_base_module_t* allocator
64 );
65
66
67 /**
68 * cleanup (free) any resources held by allocator
69 */
70
71 typedef int (*mca_allocator_base_module_finalize_fn_t)(
72 struct mca_allocator_base_module_t* allocator
73 );
74
75 /**
76 * The data structure for each component.
77 */
78 struct mca_allocator_base_module_t {
79 mca_allocator_base_module_alloc_fn_t alc_alloc;
80 /**< Allocate memory */
81 mca_allocator_base_module_realloc_fn_t alc_realloc;
82 /**< Reallocate memory */
83 mca_allocator_base_module_free_fn_t alc_free;
84 /**< Free memory */
85 mca_allocator_base_module_compact_fn_t alc_compact;
86 /**< Return memory */
87 mca_allocator_base_module_finalize_fn_t alc_finalize;
88 /**< Finalize and free everything */
89 /* memory pool and resources */
90 void *alc_context;
91 };
92 /**
93 * Convenience typedef.
94 */
95 typedef struct mca_allocator_base_module_t mca_allocator_base_module_t;
96
97
98 /**
99 * A function to get more memory from the system. This function is to be
100 * provided by the module to the allocator framework.
101 */
102
103 typedef void* (*mca_allocator_base_component_segment_alloc_fn_t)(void *ctx,
104 size_t *size);
105
106 /**
107 * A function to free memory from the control of the allocator framework
108 * back to the system. This function is to be provided by the module to the
109 * allocator framework.
110 */
111 typedef void (*mca_allocator_base_component_segment_free_fn_t)(void *ctx,
112 void *segment);
113
114
115 /**
116 * The function used to initialize the component.
117 */
118 typedef struct mca_allocator_base_module_t*
119 (*mca_allocator_base_component_init_fn_t)(
120 bool enable_mpi_threads,
121 mca_allocator_base_component_segment_alloc_fn_t segment_alloc,
122 mca_allocator_base_component_segment_free_fn_t segment_free,
123 void *context
124 );
125
126 /**
127 * The data structure provided by each component to the framework which
128 * describes the component.
129 */
130 struct mca_allocator_base_component_2_0_0_t {
131 mca_base_component_t allocator_version;
132 /**< The version of the component */
133 mca_base_component_data_t allocator_data;
134 /**< The component metadata */
135 mca_allocator_base_component_init_fn_t allocator_init;
136 /**< The component initialization function. */
137 };
138
139 /**
140 * Convenience typedef.
141 */
142 typedef struct mca_allocator_base_component_2_0_0_t mca_allocator_base_component_t;
143
144 /**
145 * Macro for use in components that are of type allocator
146 */
147 #define MCA_ALLOCATOR_BASE_VERSION_2_0_0 \
148 OPAL_MCA_BASE_VERSION_2_1_0("allocator", 2, 0, 0)
149
150 END_C_DECLS
151
152 #endif /* MCA_ALLOCATOR_H */
153