comparison packages/fs/jffs2/current/src/malloc-ecos.c @ 1373:00a9f2cb1081

* cdl/jffs2.cdl: * src/malloc-ecos.c: * src/fs-ecos.c: Allocate jffs2_raw_node_ref structs from pool or malloc depending on a CDL configuration.
author asl
date Thu, 20 Nov 2003 21:06:25 +0000
parents a7947d436e85
children cd7d2afbc7dd
comparison
equal deleted inserted replaced
1372:121121d3d18f 1373:00a9f2cb1081
10 * $Id: malloc-ecos.c,v 1.2 2003/01/09 13:53:44 dwmw2 Exp $ 10 * $Id: malloc-ecos.c,v 1.2 2003/01/09 13:53:44 dwmw2 Exp $
11 * 11 *
12 */ 12 */
13 13
14 #include <linux/kernel.h> 14 #include <linux/kernel.h>
15 #include <cyg/hal/drv_api.h>
15 #include "nodelist.h" 16 #include "nodelist.h"
17
18 #if !defined(CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE)
19 # define CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE 0
20 #endif
16 21
17 struct jffs2_full_dirent *jffs2_alloc_full_dirent(int namesize) 22 struct jffs2_full_dirent *jffs2_alloc_full_dirent(int namesize)
18 { 23 {
19 return malloc(sizeof(struct jffs2_full_dirent) + namesize); 24 return malloc(sizeof(struct jffs2_full_dirent) + namesize);
20 } 25 }
62 void jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info *x) 67 void jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info *x)
63 { 68 {
64 free(x); 69 free(x);
65 } 70 }
66 71
72 struct jffs2_node_frag *jffs2_alloc_node_frag(void)
73 {
74 return malloc(sizeof(struct jffs2_node_frag));
75 }
76
77 void jffs2_free_node_frag(struct jffs2_node_frag *x)
78 {
79 free(x);
80 }
81
82 #if CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE == 0
83
84 int jffs2_create_slab_caches(void)
85 {
86 return 0;
87 }
88
89 void jffs2_destroy_slab_caches(void)
90 {
91 }
92
67 struct jffs2_raw_node_ref *jffs2_alloc_raw_node_ref(void) 93 struct jffs2_raw_node_ref *jffs2_alloc_raw_node_ref(void)
68 { 94 {
69 return malloc(sizeof(struct jffs2_raw_node_ref)); 95 return malloc(sizeof(struct jffs2_raw_node_ref));
70 } 96 }
71 97
72 void jffs2_free_raw_node_ref(struct jffs2_raw_node_ref *x) 98 void jffs2_free_raw_node_ref(struct jffs2_raw_node_ref *x)
73 { 99 {
74 free(x); 100 free(x);
75 } 101 }
76 102
77 struct jffs2_node_frag *jffs2_alloc_node_frag(void) 103 #else // CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE == 0
104
105 static struct jffs2_raw_node_ref
106 rnr_pool[CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE] __attribute__ ((aligned (4))),
107 * first = NULL;
108 static cyg_drv_mutex_t mutex;
109
110 int jffs2_create_slab_caches(void)
78 { 111 {
79 return malloc(sizeof(struct jffs2_node_frag)); 112 struct jffs2_raw_node_ref * p;
113 cyg_drv_mutex_init(&mutex);
114 for (
115 p = rnr_pool;
116 p < rnr_pool + CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE - 1;
117 p++
118 )
119 p->next_phys = p + 1;
120 rnr_pool[CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE - 1].next_phys = NULL;
121 first = &rnr_pool[0];
122 return 0;
80 } 123 }
81 124
82 void jffs2_free_node_frag(struct jffs2_node_frag *x) 125 void jffs2_destroy_slab_caches(void)
83 { 126 {
84 free(x);
85 } 127 }
128
129 struct jffs2_raw_node_ref *jffs2_alloc_raw_node_ref(void)
130 {
131 struct jffs2_raw_node_ref * p;
132
133 cyg_drv_mutex_lock(&mutex);
134 p = first;
135 if (p != NULL)
136 first = p->next_phys;
137 cyg_drv_mutex_unlock(&mutex);
138 return p;
139 }
140
141 void jffs2_free_raw_node_ref(struct jffs2_raw_node_ref *x)
142 {
143 cyg_drv_mutex_lock(&mutex);
144 x->next_phys = first;
145 first = x;
146 cyg_drv_mutex_unlock(&mutex);
147 }
148
149 #endif // CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE == 0
86 150
87 struct jffs2_inode_cache *jffs2_alloc_inode_cache(void) 151 struct jffs2_inode_cache *jffs2_alloc_inode_cache(void)
88 { 152 {
89 struct jffs2_inode_cache *ret = malloc(sizeof(struct jffs2_inode_cache)); 153 struct jffs2_inode_cache *ret = malloc(sizeof(struct jffs2_inode_cache));
90 D1(printk(KERN_DEBUG "Allocated inocache at %p\n", ret)); 154 D1(printk(KERN_DEBUG "Allocated inocache at %p\n", ret));