Skip to content

Commit c8aee7b

Browse files
Andrew Boienashif
authored andcommitted
sys_mem_pool: use sys_mutex
Permission management no longer necessary, the former parameter for the mutex is now simply ignored. Signed-off-by: Andrew Boie <[email protected]>
1 parent 0ccaa5d commit c8aee7b

File tree

5 files changed

+13
-25
lines changed

5 files changed

+13
-25
lines changed

include/misc/mempool.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99

1010
#include <kernel.h>
1111
#include <misc/mempool_base.h>
12+
#include <misc/mutex.h>
1213

1314
struct sys_mem_pool {
1415
struct sys_mem_pool_base base;
15-
struct k_mutex *mutex;
16+
struct sys_mutex mutex;
1617
};
1718

1819
struct sys_mem_pool_block {
@@ -38,16 +39,15 @@ struct sys_mem_pool_block {
3839
* run sys_mem_pool_init() on it before using any other APIs.
3940
*
4041
* @param name Name of the memory pool.
41-
* @param kmutex Pointer to an initialized k_mutex object, used for
42-
* synchronization, declared with K_MUTEX_DEFINE().
42+
* @param ignored ignored, any value
4343
* @param minsz Size of the smallest blocks in the pool (in bytes).
4444
* @param maxsz Size of the largest blocks in the pool (in bytes).
4545
* @param nmax Number of maximum sized blocks in the pool.
4646
* @param align Alignment of the pool's buffer (power of 2).
4747
* @param section Destination binary section for pool data
4848
*/
49-
#define SYS_MEM_POOL_DEFINE(name, kmutex, minsz, maxsz, nmax, align, section) \
50-
char __aligned(align) Z_GENERIC_SECTION(section) \
49+
#define SYS_MEM_POOL_DEFINE(name, ignored, minsz, maxsz, nmax, align, section) \
50+
char __aligned(align) Z_GENERIC_SECTION(section) \
5151
_mpool_buf_##name[_ALIGN4(maxsz * nmax) \
5252
+ _MPOOL_BITS_SIZE(maxsz, minsz, nmax)]; \
5353
struct sys_mem_pool_lvl Z_GENERIC_SECTION(section) \
@@ -60,8 +60,7 @@ struct sys_mem_pool_block {
6060
.n_levels = Z_MPOOL_LVLS(maxsz, minsz), \
6161
.levels = _mpool_lvls_##name, \
6262
.flags = SYS_MEM_POOL_USER \
63-
}, \
64-
.mutex = kmutex, \
63+
} \
6564
}
6665

6766
/**

lib/gui/lvgl/lvgl_mem_user.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
#include <init.h>
1010
#include <misc/mempool.h>
1111

12-
K_MUTEX_DEFINE(lvgl_mem_pool_mutex);
13-
SYS_MEM_POOL_DEFINE(lvgl_mem_pool, &lvgl_mem_pool_mutex,
12+
SYS_MEM_POOL_DEFINE(lvgl_mem_pool, NULL,
1413
CONFIG_LVGL_MEM_POOL_MIN_SIZE,
1514
CONFIG_LVGL_MEM_POOL_MAX_SIZE,
1615
CONFIG_LVGL_MEM_POOL_NUMBER_BLOCKS, 4, .data);
@@ -27,9 +26,6 @@ void lvgl_free(void *ptr)
2726

2827
static int lvgl_mem_pool_init(struct device *unused)
2928
{
30-
#ifdef CONFIG_USERSPACE
31-
k_object_access_all_grant(&lvgl_mem_pool_mutex);
32-
#endif
3329
sys_mem_pool_init(&lvgl_mem_pool);
3430
return 0;
3531
}

lib/libc/minimal/source/stdlib/malloc.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ K_APPMEM_PARTITION_DEFINE(z_malloc_partition);
2424
#define POOL_SECTION .data
2525
#endif /* CONFIG_USERSPACE */
2626

27-
K_MUTEX_DEFINE(malloc_mutex);
28-
SYS_MEM_POOL_DEFINE(z_malloc_mem_pool, &malloc_mutex, 16,
27+
SYS_MEM_POOL_DEFINE(z_malloc_mem_pool, NULL, 16,
2928
CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE, 1, 4, POOL_SECTION);
3029

3130
void *malloc(size_t size)
@@ -44,9 +43,6 @@ static int malloc_prepare(struct device *unused)
4443
{
4544
ARG_UNUSED(unused);
4645

47-
#ifdef CONFIG_USERSPACE
48-
k_object_access_all_grant(&malloc_mutex);
49-
#endif
5046
sys_mem_pool_init(&z_malloc_mem_pool);
5147

5248
return 0;

lib/os/mempool.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ void *sys_mem_pool_alloc(struct sys_mem_pool *p, size_t size)
333333
u32_t level, block;
334334
char *ret;
335335

336-
k_mutex_lock(p->mutex, K_FOREVER);
336+
sys_mutex_lock(&p->mutex, K_FOREVER);
337337

338338
size += sizeof(struct sys_mem_pool_block);
339339
if (z_sys_mem_pool_block_alloc(&p->base, size, &level, &block,
@@ -348,7 +348,7 @@ void *sys_mem_pool_alloc(struct sys_mem_pool *p, size_t size)
348348
blk->pool = p;
349349
ret += sizeof(*blk);
350350
out:
351-
k_mutex_unlock(p->mutex);
351+
sys_mutex_unlock(&p->mutex);
352352
return ret;
353353
}
354354

@@ -364,8 +364,8 @@ void sys_mem_pool_free(void *ptr)
364364
blk = (struct sys_mem_pool_block *)((char *)ptr - sizeof(*blk));
365365
p = blk->pool;
366366

367-
k_mutex_lock(p->mutex, K_FOREVER);
367+
sys_mutex_lock(&p->mutex, K_FOREVER);
368368
z_sys_mem_pool_block_free(&p->base, blk->level, blk->block);
369-
k_mutex_unlock(p->mutex);
369+
sys_mutex_unlock(&p->mutex);
370370
}
371371

tests/kernel/mem_pool/sys_mem_pool/src/main.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
#define BLK_SIZE_EXCLUDE_DESC (BLK_SIZE_MIN - 16)
2020
#define BLK_ALIGN BLK_SIZE_MIN
2121

22-
K_MUTEX_DEFINE(pool_mutex);
23-
24-
SYS_MEM_POOL_DEFINE(pool, &pool_mutex, BLK_SIZE_MIN, BLK_SIZE_MAX,
22+
SYS_MEM_POOL_DEFINE(pool, NULL, BLK_SIZE_MIN, BLK_SIZE_MAX,
2523
BLK_NUM_MAX, BLK_ALIGN, ZTEST_SECTION);
2624

2725
/**
@@ -126,7 +124,6 @@ void test_sys_mem_pool_min_block_size(void)
126124
/*test case main entry*/
127125
void test_main(void)
128126
{
129-
k_thread_access_grant(k_current_get(), &pool_mutex);
130127
sys_mem_pool_init(&pool);
131128

132129
ztest_test_suite(test_sys_mem_pool_api,

0 commit comments

Comments
 (0)