Skip to content

Commit 81197c3

Browse files
author
Jyri Sarha
committed
modules: Add safeguard to mod_alloc() and friends
Add safeguard to mod_alloc() and friends that checks that they are always called from the same thread (e.g. no locking needed). Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent 04bca06 commit 81197c3

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/audio/module_adapter/module/generic.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ int module_init(struct processing_module *mod)
9999
list_init(&md->resources.cont_chunk_list);
100100
md->resources.heap_usage = 0;
101101
md->resources.heap_high_water_mark = 0;
102-
102+
#if DEBUG
103+
md->resources.rsrc_mngr = k_current_get();
104+
#endif
103105
/* Now we can proceed with module specific initialization */
104106
ret = interface->init(mod);
105107
if (ret) {
@@ -167,6 +169,9 @@ void *mod_alloc_align(struct processing_module *mod, uint32_t size, uint32_t ali
167169
struct module_resources *res = &mod->priv.resources;
168170
void *ptr;
169171

172+
#if DEBUG
173+
assert(res->rsrc_mngr == k_current_get());
174+
#endif
170175
if (!container)
171176
return NULL;
172177

@@ -251,6 +256,9 @@ mod_data_blob_handler_new(struct processing_module *mod)
251256
struct module_memory *container = container_get(mod);
252257
struct comp_data_blob_handler *dbh;
253258

259+
#if DEBUG
260+
assert(res->rsrc_mngr == k_current_get());
261+
#endif
254262
if (!container)
255263
return NULL;
256264

@@ -284,6 +292,9 @@ const void *mod_fast_get(struct processing_module *mod, const void * const dram_
284292
struct module_memory *container = container_get(mod);
285293
const void *ptr;
286294

295+
#if DEBUG
296+
assert(res->rsrc_mngr == k_current_get());
297+
#endif
287298
if (!container)
288299
return NULL;
289300

@@ -315,6 +326,9 @@ int mod_free(struct processing_module *mod, void *ptr)
315326
struct list_item *mem_list;
316327
struct list_item *_mem_list;
317328

329+
#if DEBUG
330+
assert(res->rsrc_mngr == k_current_get());
331+
#endif
318332
if (!ptr)
319333
return 0;
320334

@@ -539,6 +553,9 @@ void mod_free_all(struct processing_module *mod)
539553
struct list_item *list;
540554
struct list_item *_list;
541555

556+
#if DEBUG
557+
assert(res->rsrc_mngr == k_current_get());
558+
#endif
542559
/* Find which container keeps this memory */
543560
list_for_item_safe(list, _list, &res->mem_list) {
544561
struct module_memory *mem = container_of(list, struct module_memory, mem_list);

src/include/sof/audio/module_adapter/module/generic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ struct module_resources {
125125
struct list_item cont_chunk_list;
126126
size_t heap_usage;
127127
size_t heap_high_water_mark;
128+
#if DEBUG
129+
k_tid_t rsrc_mngr;
130+
#endif
128131
};
129132

130133
/**

0 commit comments

Comments
 (0)