1 /*
2 * Copyright (C) 2015-2017 Alibaba Group Holding Limited
3 */
4
5 #include "k_api.h"
6
7 #if (RHINO_CONFIG_KOBJ_DYN_ALLOC > 0)
8
9 #if (RHINO_CONFIG_USER_SPACE > 0)
10 void krhino_utask_free_res(ktask_t *task);
11 #endif
12
dyn_mem_proc_task(void * arg)13 void dyn_mem_proc_task(void *arg)
14 {
15 CPSR_ALLOC();
16 size_t i;
17 kstat_t ret;
18 res_free_t *res_free;
19 res_free_t tmp;
20
21 (void)arg;
22
23 while (1) {
24 ret = krhino_sem_take(&g_res_sem, RHINO_WAIT_FOREVER);
25 if (ret != RHINO_SUCCESS) {
26 k_err_proc(RHINO_DYN_MEM_PROC_ERR);
27 }
28
29 while (1) {
30 RHINO_CRITICAL_ENTER();
31 if (!is_klist_empty(&g_res_list)) {
32 res_free = krhino_list_entry(g_res_list.next, res_free_t, res_list);
33 klist_rm(&res_free->res_list);
34 RHINO_CRITICAL_EXIT();
35 #if (RHINO_CONFIG_USER_SPACE > 0)
36 krhino_utask_free_res((ktask_t *)(res_free->res[1]));
37 #endif
38 memcpy(&tmp, res_free, sizeof(res_free_t));
39 for (i = 0; i < tmp.cnt; i++) {
40 krhino_mm_free(tmp.res[i]);
41 }
42 } else {
43 RHINO_CRITICAL_EXIT();
44 break;
45 }
46 }
47 }
48 }
49
dyn_mem_proc_task_start(void)50 __attribute__((weak)) void dyn_mem_proc_task_start(void)
51 {
52 krhino_task_create(&g_dyn_task, "dyn_mem_proc_task", 0, RHINO_CONFIG_K_DYN_MEM_TASK_PRI,
53 0, g_dyn_task_stack, RHINO_CONFIG_K_DYN_TASK_STACK, dyn_mem_proc_task, 1);
54 }
55
56 #endif
57
58