mirror of
https://github.com/drasko/codezero.git
synced 2026-02-03 21:53:13 +01:00
Mutex implementation almost working.
- Fixed a wrong instruction in mutex.S user library - Added support for blocking lock/unlock - Divided waiting into wait_on_prepare and wait_on_prepared_wait so that mutex_control lock is released after getting in the waitqueue. - Declaring waitqueue on the stack should be done outside wait_on_prepare Issues: - Tests can be simplified for atomic data access instead of producer/consumer. - kmalloc variable sized memory caches are not freed properly. Currently only the last slot can be freed, occupied correctly. it should be done in any slot, i.e. 1, 2, 3, 4 instead of just 5. - Need to add a mutex to kmalloc.
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
struct kmalloc_mempool {
|
||||
int total;
|
||||
struct list_head pool_head[KMALLOC_POOLS_MAX];
|
||||
struct mutex kmalloc_mutex;
|
||||
};
|
||||
struct kmalloc_mempool km_pool;
|
||||
|
||||
@@ -21,6 +22,7 @@ void init_kmalloc()
|
||||
{
|
||||
for (int i = 0; i < KMALLOC_POOLS_MAX; i++)
|
||||
INIT_LIST_HEAD(&km_pool.pool_head[i]);
|
||||
mutex_init(&km_pool.kmalloc_mutex);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -69,6 +71,7 @@ void *kmalloc(int size)
|
||||
BUG_ON(size >= PAGE_SIZE);
|
||||
BUG_ON(!(cache = mem_cache_init(alloc_page(), PAGE_SIZE,
|
||||
size, 0)));
|
||||
printk("%s: Created new cache for size %d\n", __FUNCTION__, size);
|
||||
list_add(&cache->list, &km_pool.pool_head[index]);
|
||||
return mem_cache_alloc(cache);
|
||||
}
|
||||
@@ -87,7 +90,12 @@ int kfree(void *p)
|
||||
if (mem_cache_is_empty(cache)) {
|
||||
list_del(&cache->list);
|
||||
free_page(cache);
|
||||
/* Total remains the same. */
|
||||
/*
|
||||
* Total remains the same unless all
|
||||
* caches are freed on that pool
|
||||
*/
|
||||
if (list_empty(&km_pool.pool_head[i]))
|
||||
km_pool.total--;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user