Rev 1787 | Rev 2052 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1787 | Rev 1950 | ||
---|---|---|---|
Line 135... | Line 135... | ||
135 | "malloc-64K","malloc-128K","malloc-256K" |
135 | "malloc-64K","malloc-128K","malloc-256K" |
136 | }; |
136 | }; |
137 | 137 | ||
138 | /** Slab descriptor */ |
138 | /** Slab descriptor */ |
139 | typedef struct { |
139 | typedef struct { |
140 | slab_cache_t *cache; /**< Pointer to parent cache */ |
140 | slab_cache_t *cache; /**< Pointer to parent cache. */ |
141 | link_t link; /* List of full/partial slabs */ |
141 | link_t link; /**< List of full/partial slabs. */ |
142 | void *start; /**< Start address of first available item */ |
142 | void *start; /**< Start address of first available item. */ |
143 | count_t available; /**< Count of available items in this slab */ |
143 | count_t available; /**< Count of available items in this slab. */ |
144 | index_t nextavail; /**< The index of next available item */ |
144 | index_t nextavail; /**< The index of next available item. */ |
145 | }slab_t; |
145 | }slab_t; |
146 | 146 | ||
147 | #ifdef CONFIG_DEBUG |
147 | #ifdef CONFIG_DEBUG |
148 | static int _slab_initialized = 0; |
148 | static int _slab_initialized = 0; |
149 | #endif |
149 | #endif |
Line 287... | Line 287... | ||
287 | slab = slab_space_alloc(cache, flags); |
287 | slab = slab_space_alloc(cache, flags); |
288 | if (!slab) |
288 | if (!slab) |
289 | return NULL; |
289 | return NULL; |
290 | spinlock_lock(&cache->slablock); |
290 | spinlock_lock(&cache->slablock); |
291 | } else { |
291 | } else { |
292 | slab = list_get_instance(cache->partial_slabs.next, |
292 | slab = list_get_instance(cache->partial_slabs.next, slab_t, link); |
293 | slab_t, |
- | |
294 | link); |
- | |
295 | list_remove(&slab->link); |
293 | list_remove(&slab->link); |
296 | } |
294 | } |
297 | obj = slab->start + slab->nextavail * cache->size; |
295 | obj = slab->start + slab->nextavail * cache->size; |
298 | slab->nextavail = *((int *)obj); |
296 | slab->nextavail = *((int *)obj); |
299 | slab->available--; |
297 | slab->available--; |
300 | 298 | ||
301 | if (! slab->available) |
299 | if (!slab->available) |
302 | list_prepend(&slab->link, &cache->full_slabs); |
300 | list_prepend(&slab->link, &cache->full_slabs); |
303 | else |
301 | else |
304 | list_prepend(&slab->link, &cache->partial_slabs); |
302 | list_prepend(&slab->link, &cache->partial_slabs); |
305 | 303 | ||
306 | spinlock_unlock(&cache->slablock); |
304 | spinlock_unlock(&cache->slablock); |
Line 897... | Line 895... | ||
897 | 895 | ||
898 | void free(void *obj) |
896 | void free(void *obj) |
899 | { |
897 | { |
900 | slab_t *slab; |
898 | slab_t *slab; |
901 | 899 | ||
902 | if (!obj) return; |
900 | if (!obj) |
- | 901 | return; |
|
903 | 902 | ||
904 | slab = obj2slab(obj); |
903 | slab = obj2slab(obj); |
905 | _slab_free(slab->cache, obj, slab); |
904 | _slab_free(slab->cache, obj, slab); |
906 | } |
905 | } |
907 | 906 |