mirror of
https://github.com/drasko/codezero.git
synced 2026-02-26 08:43:13 +01:00
Added mutex locking to kmalloc/kfree.
This commit is contained in:
@@ -42,7 +42,7 @@ void init_kmalloc()
|
|||||||
* Allocates memory from mem_caches that it generates on-the-fly,
|
* Allocates memory from mem_caches that it generates on-the-fly,
|
||||||
* for up to KMALLOC_POOLS_MAX different sizes.
|
* for up to KMALLOC_POOLS_MAX different sizes.
|
||||||
*/
|
*/
|
||||||
void *kmalloc(int size)
|
void *__kmalloc(int size)
|
||||||
{
|
{
|
||||||
struct mem_cache *cache;
|
struct mem_cache *cache;
|
||||||
int right_sized_pool_idx = -1;
|
int right_sized_pool_idx = -1;
|
||||||
@@ -96,11 +96,21 @@ void *kmalloc(int size)
|
|||||||
return mem_cache_alloc(cache);
|
return mem_cache_alloc(cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *kmalloc(int size)
|
||||||
|
{
|
||||||
|
void *p;
|
||||||
|
|
||||||
|
mutex_lock(&km_pool.kmalloc_mutex);
|
||||||
|
p = __kmalloc(size);
|
||||||
|
mutex_unlock(&km_pool.kmalloc_mutex);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
/* FIXME:
|
/* FIXME:
|
||||||
* Horrible complexity O(n^2) because we don't know which cache
|
* Horrible complexity O(n^2) because we don't know which cache
|
||||||
* we're freeing from!!! But its simple. ;-)
|
* we're freeing from!!! But its simple. ;-)
|
||||||
*/
|
*/
|
||||||
int kfree(void *p)
|
int __kfree(void *p)
|
||||||
{
|
{
|
||||||
struct mem_cache *cache, *tmp;
|
struct mem_cache *cache, *tmp;
|
||||||
|
|
||||||
@@ -124,6 +134,15 @@ int kfree(void *p)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int kfree(void *p)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
mutex_lock(&km_pool.kmalloc_mutex);
|
||||||
|
ret = __kfree(p);
|
||||||
|
mutex_unlock(&km_pool.kmalloc_mutex);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
void *kzalloc(int size)
|
void *kzalloc(int size)
|
||||||
{
|
{
|
||||||
void *p = kmalloc(size);
|
void *p = kmalloc(size);
|
||||||
|
|||||||
Reference in New Issue
Block a user