]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | /* |
2 | * Copyright(c) 2012-2018 Intel Corporation | |
3 | * SPDX-License-Identifier: BSD-3-Clause-Clear | |
4 | */ | |
5 | ||
f67539c2 TL |
6 | #ifndef UTILS_REALLOC_H_ |
7 | #define UTILS_REALLOC_H_ | |
9f95a23c TL |
8 | |
9 | /** | |
f67539c2 TL |
10 | * @file utils_realloc.h |
11 | * @brief OCF realloc | |
9f95a23c TL |
12 | */ |
13 | ||
14 | void ocf_realloc_init(void **mem, size_t *limit); | |
15 | ||
16 | int ocf_realloc(void **mem, size_t size, size_t count, size_t *limit); | |
17 | ||
18 | int ocf_realloc_cp(void **mem, size_t size, size_t count, size_t *limit); | |
19 | ||
20 | /** | |
21 | * @brief Initialize memory pointer and limit before reallocator usage | |
22 | * | |
23 | * @param[inout] mem - Pointer to the memory | |
24 | * @param[inout] limit - Variable used internally by reallocator and indicates | |
25 | * last allocation size | |
26 | */ | |
27 | #define OCF_REALLOC_INIT(mem, limit) \ | |
28 | ocf_realloc_init((void **)mem, limit) | |
29 | ||
30 | /** | |
31 | * @brief De-Initialize memory pointer and limit, free memory | |
32 | * | |
33 | * @param[inout] mem - Pointer to the memory | |
34 | * @param[inout] limit - Variable used internally by reallocator and indicates | |
35 | * last allocation size | |
36 | */ | |
37 | #define OCF_REALLOC_DEINIT(mem, limit) \ | |
38 | ocf_realloc((void **)mem, 0, 0, limit) | |
39 | ||
40 | /** | |
41 | * @brief Reallocate referenced memory if it is required. | |
42 | * | |
43 | * @param[inout] mem - Pointer to the memory | |
44 | * @param[in] size - Size of particular element | |
45 | * @param[in] count - Counts of element | |
46 | * @param[inout] limit - Variable used internally by reallocator and indicates | |
47 | * last allocation size | |
48 | * | |
49 | * @return 0 - Reallocation successful, Non zero - Realocation ERROR | |
50 | */ | |
51 | #define OCF_REALLOC(mem, size, count, limit) \ | |
52 | ocf_realloc((void **)mem, size, count, limit) | |
53 | ||
54 | /** | |
55 | * @brief Reallocate referenced memory if it is required and copy old content | |
56 | * into new memory space, new memory space is set to '0' | |
57 | * | |
58 | * @param[inout] mem - Pointer to the memory | |
59 | * @param[in] size - Size of particular element | |
60 | * @param[in] count - Counts of element | |
61 | * @param[inout] limit - Variable used internally by reallocator and indicates | |
62 | * last allocation size | |
63 | * | |
64 | * @return 0 - Reallocation successful, Non zero - Realocation ERROR | |
65 | */ | |
66 | #define OCF_REALLOC_CP(mem, size, count, limit) \ | |
67 | ocf_realloc_cp((void **)mem, size, count, limit) | |
68 | ||
f67539c2 | 69 | #endif /* UTILS_REALLOC_H_ */ |