cleanup: include/: move misc/mempool_base.h to sys/mempool_base.h
move misc/mempool_base.h to sys/mempool_base.h and create a shim for backward-compatibility. No functional changes to the headers. A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES. Related to #16539 Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
parent
43d2b9c246
commit
1ed300b318
|
@ -25,7 +25,7 @@
|
|||
#include <misc/slist.h>
|
||||
#include <misc/sflist.h>
|
||||
#include <misc/util.h>
|
||||
#include <misc/mempool_base.h>
|
||||
#include <sys/mempool_base.h>
|
||||
#include <kernel_version.h>
|
||||
#include <random/rand32.h>
|
||||
#include <kernel_arch_thread.h>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#define ZEPHYR_INCLUDE_MISC_MEMPOOL_H_
|
||||
|
||||
#include <kernel.h>
|
||||
#include <misc/mempool_base.h>
|
||||
#include <sys/mempool_base.h>
|
||||
#include <misc/mutex.h>
|
||||
|
||||
struct sys_mem_pool {
|
||||
|
|
|
@ -1,112 +1,15 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Intel Corporation
|
||||
* Copyright (c) 2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_MISC_MEMPOOL_BASE_H_
|
||||
#define ZEPHYR_INCLUDE_MISC_MEMPOOL_BASE_H_
|
||||
|
||||
#include <zephyr/types.h>
|
||||
#include <stddef.h>
|
||||
#ifndef CONFIG_COMPAT_INCLUDES
|
||||
#warning "This header file has moved, include <sys/mempool_base.h> instead."
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Definitions and macros used by both the IRQ-safe k_mem_pool and user-mode
|
||||
* compatible sys_mem_pool implementations
|
||||
*/
|
||||
|
||||
struct sys_mem_pool_lvl {
|
||||
union {
|
||||
u32_t *bits_p;
|
||||
u32_t bits;
|
||||
};
|
||||
sys_dlist_t free_list;
|
||||
};
|
||||
|
||||
#define SYS_MEM_POOL_KERNEL BIT(0)
|
||||
#define SYS_MEM_POOL_USER BIT(1)
|
||||
|
||||
struct sys_mem_pool_base {
|
||||
void *buf;
|
||||
size_t max_sz;
|
||||
u16_t n_max;
|
||||
u8_t n_levels;
|
||||
s8_t max_inline_level;
|
||||
struct sys_mem_pool_lvl *levels;
|
||||
u8_t flags;
|
||||
};
|
||||
|
||||
#define _ALIGN4(n) ((((n)+3)/4)*4)
|
||||
|
||||
#define Z_MPOOL_HAVE_LVL(maxsz, minsz, l) (((maxsz) >> (2*(l))) \
|
||||
>= (minsz) ? 1 : 0)
|
||||
|
||||
#define __MPOOL_LVLS(maxsz, minsz) \
|
||||
(Z_MPOOL_HAVE_LVL((maxsz), (minsz), 0) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 1) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 2) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 3) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 4) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 5) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 6) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 7) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 8) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 9) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 10) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 11) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 12) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 13) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 14) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 15))
|
||||
|
||||
#define _MPOOL_MINBLK sizeof(sys_dnode_t)
|
||||
|
||||
#define Z_MPOOL_LVLS(maxsz, minsz) \
|
||||
__MPOOL_LVLS((maxsz), (minsz) >= _MPOOL_MINBLK ? (minsz) : \
|
||||
_MPOOL_MINBLK)
|
||||
|
||||
/* Rounds the needed bits up to integer multiples of u32_t */
|
||||
#define Z_MPOOL_LBIT_WORDS_UNCLAMPED(n_max, l) \
|
||||
((((n_max) << (2*(l))) + 31) / 32)
|
||||
|
||||
/* One word gets stored free unioned with the pointer, otherwise the
|
||||
* calculated unclamped value
|
||||
*/
|
||||
#define Z_MPOOL_LBIT_WORDS(n_max, l) \
|
||||
(Z_MPOOL_LBIT_WORDS_UNCLAMPED(n_max, l) < 2 ? 0 \
|
||||
: Z_MPOOL_LBIT_WORDS_UNCLAMPED(n_max, l))
|
||||
|
||||
/* How many bytes for the bitfields of a single level? */
|
||||
#define Z_MPOOL_LBIT_BYTES(maxsz, minsz, l, n_max) \
|
||||
(Z_MPOOL_LVLS((maxsz), (minsz)) > (l) ? \
|
||||
4 * Z_MPOOL_LBIT_WORDS((n_max), l) : 0)
|
||||
|
||||
/* Size of the bitmap array that follows the buffer in allocated memory */
|
||||
#define _MPOOL_BITS_SIZE(maxsz, minsz, n_max) \
|
||||
(Z_MPOOL_LBIT_BYTES(maxsz, minsz, 0, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 1, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 2, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 3, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 4, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 5, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 6, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 7, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 8, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 9, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 10, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 11, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 12, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 13, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 14, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 15, n_max))
|
||||
|
||||
|
||||
void z_sys_mem_pool_base_init(struct sys_mem_pool_base *p);
|
||||
|
||||
int z_sys_mem_pool_block_alloc(struct sys_mem_pool_base *p, size_t size,
|
||||
u32_t *level_p, u32_t *block_p, void **data_p);
|
||||
|
||||
void z_sys_mem_pool_block_free(struct sys_mem_pool_base *p, u32_t level,
|
||||
u32_t block);
|
||||
#include <sys/mempool_base.h>
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_MISC_MEMPOOL_BASE_H_ */
|
||||
|
|
112
include/sys/mempool_base.h
Normal file
112
include/sys/mempool_base.h
Normal file
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_SYS_MEMPOOL_BASE_H_
|
||||
#define ZEPHYR_INCLUDE_SYS_MEMPOOL_BASE_H_
|
||||
|
||||
#include <zephyr/types.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/*
|
||||
* Definitions and macros used by both the IRQ-safe k_mem_pool and user-mode
|
||||
* compatible sys_mem_pool implementations
|
||||
*/
|
||||
|
||||
struct sys_mem_pool_lvl {
|
||||
union {
|
||||
u32_t *bits_p;
|
||||
u32_t bits;
|
||||
};
|
||||
sys_dlist_t free_list;
|
||||
};
|
||||
|
||||
#define SYS_MEM_POOL_KERNEL BIT(0)
|
||||
#define SYS_MEM_POOL_USER BIT(1)
|
||||
|
||||
struct sys_mem_pool_base {
|
||||
void *buf;
|
||||
size_t max_sz;
|
||||
u16_t n_max;
|
||||
u8_t n_levels;
|
||||
s8_t max_inline_level;
|
||||
struct sys_mem_pool_lvl *levels;
|
||||
u8_t flags;
|
||||
};
|
||||
|
||||
#define _ALIGN4(n) ((((n)+3)/4)*4)
|
||||
|
||||
#define Z_MPOOL_HAVE_LVL(maxsz, minsz, l) (((maxsz) >> (2*(l))) \
|
||||
>= (minsz) ? 1 : 0)
|
||||
|
||||
#define __MPOOL_LVLS(maxsz, minsz) \
|
||||
(Z_MPOOL_HAVE_LVL((maxsz), (minsz), 0) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 1) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 2) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 3) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 4) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 5) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 6) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 7) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 8) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 9) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 10) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 11) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 12) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 13) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 14) + \
|
||||
Z_MPOOL_HAVE_LVL((maxsz), (minsz), 15))
|
||||
|
||||
#define _MPOOL_MINBLK sizeof(sys_dnode_t)
|
||||
|
||||
#define Z_MPOOL_LVLS(maxsz, minsz) \
|
||||
__MPOOL_LVLS((maxsz), (minsz) >= _MPOOL_MINBLK ? (minsz) : \
|
||||
_MPOOL_MINBLK)
|
||||
|
||||
/* Rounds the needed bits up to integer multiples of u32_t */
|
||||
#define Z_MPOOL_LBIT_WORDS_UNCLAMPED(n_max, l) \
|
||||
((((n_max) << (2*(l))) + 31) / 32)
|
||||
|
||||
/* One word gets stored free unioned with the pointer, otherwise the
|
||||
* calculated unclamped value
|
||||
*/
|
||||
#define Z_MPOOL_LBIT_WORDS(n_max, l) \
|
||||
(Z_MPOOL_LBIT_WORDS_UNCLAMPED(n_max, l) < 2 ? 0 \
|
||||
: Z_MPOOL_LBIT_WORDS_UNCLAMPED(n_max, l))
|
||||
|
||||
/* How many bytes for the bitfields of a single level? */
|
||||
#define Z_MPOOL_LBIT_BYTES(maxsz, minsz, l, n_max) \
|
||||
(Z_MPOOL_LVLS((maxsz), (minsz)) > (l) ? \
|
||||
4 * Z_MPOOL_LBIT_WORDS((n_max), l) : 0)
|
||||
|
||||
/* Size of the bitmap array that follows the buffer in allocated memory */
|
||||
#define _MPOOL_BITS_SIZE(maxsz, minsz, n_max) \
|
||||
(Z_MPOOL_LBIT_BYTES(maxsz, minsz, 0, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 1, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 2, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 3, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 4, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 5, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 6, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 7, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 8, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 9, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 10, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 11, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 12, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 13, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 14, n_max) + \
|
||||
Z_MPOOL_LBIT_BYTES(maxsz, minsz, 15, n_max))
|
||||
|
||||
|
||||
void z_sys_mem_pool_base_init(struct sys_mem_pool_base *p);
|
||||
|
||||
int z_sys_mem_pool_block_alloc(struct sys_mem_pool_base *p, size_t size,
|
||||
u32_t *level_p, u32_t *block_p, void **data_p);
|
||||
|
||||
void z_sys_mem_pool_block_free(struct sys_mem_pool_base *p, u32_t level,
|
||||
u32_t block);
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_SYS_MEMPOOL_BASE_H_ */
|
|
@ -7,7 +7,7 @@
|
|||
#include <kernel.h>
|
||||
#include <string.h>
|
||||
#include <sys/__assert.h>
|
||||
#include <misc/mempool_base.h>
|
||||
#include <sys/mempool_base.h>
|
||||
#include <misc/mempool.h>
|
||||
|
||||
#ifdef CONFIG_MISRA_SANE
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/dlist.h>
|
||||
#include <misc/mempool_base.h>
|
||||
#include <sys/mempool_base.h>
|
||||
|
||||
#include "hal/cntr.h"
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#include <sys/dlist.h>
|
||||
#include <misc/mempool_base.h>
|
||||
#include <sys/mempool_base.h>
|
||||
|
||||
#include "util/mem.h"
|
||||
#include "hal/ecb.h"
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/dlist.h>
|
||||
#include <misc/mempool_base.h>
|
||||
#include <sys/mempool_base.h>
|
||||
#include <toolchain.h>
|
||||
|
||||
#include "util/mem.h"
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include <stdbool.h>
|
||||
#include <sys/dlist.h>
|
||||
#include <misc/mempool_base.h>
|
||||
#include <sys/mempool_base.h>
|
||||
|
||||
#include "hal/cntr.h"
|
||||
|
||||
|
|
Loading…
Reference in a new issue