kernel: add cleanup to data types
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
0f7a2e46cc
commit
69d2fed697
4 changed files with 13 additions and 2 deletions
|
|
@ -3,10 +3,14 @@
|
||||||
#define _SPINLOCK_H_
|
#define _SPINLOCK_H_
|
||||||
|
|
||||||
#include <kernel/types.h>
|
#include <kernel/types.h>
|
||||||
|
#include <kernel/common.h>
|
||||||
|
|
||||||
|
#define CLEANUP_SLOCK CLEANUP(cleanup_spinlock)
|
||||||
|
|
||||||
typedef u32 spinlock_t;
|
typedef u32 spinlock_t;
|
||||||
|
|
||||||
void spinlock_acquire(spinlock_t *lock);
|
void spinlock_acquire(spinlock_t *lock);
|
||||||
void spinlock_release(spinlock_t *lock);
|
void spinlock_release(spinlock_t *lock);
|
||||||
|
void cleanup_spinlock(spinlock_t **lock_ptr);
|
||||||
|
|
||||||
#endif /* _SPINLOCK_H_ */
|
#endif /* _SPINLOCK_H_ */
|
||||||
|
|
|
||||||
|
|
@ -18,3 +18,9 @@ void spinlock_release(spinlock_t *lock)
|
||||||
{
|
{
|
||||||
atomic_cmpxchg(lock, 1, 0);
|
atomic_cmpxchg(lock, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cleanup_spinlock(spinlock_t **lock_ptr)
|
||||||
|
{
|
||||||
|
if (lock_ptr && *lock_ptr)
|
||||||
|
spinlock_release(*lock_ptr);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
#define ALLOC_KERN 0x1
|
#define ALLOC_KERN 0x1
|
||||||
#define ALLOC_USER 0x2
|
#define ALLOC_USER 0x2
|
||||||
|
|
||||||
#define CLEANUP_KFREE __attribute__((cleanup(_cleanup_kfree)))
|
#define CLEANUP_KFREE CLEANUP(cleanup_kfree)
|
||||||
|
|
||||||
typedef struct _mem_cache_t {
|
typedef struct _mem_cache_t {
|
||||||
char *name;
|
char *name;
|
||||||
|
|
@ -31,6 +31,7 @@ void *kalloc(size_t size, u64 flags);
|
||||||
void *kzalloc(size_t size, u64 flags);
|
void *kzalloc(size_t size, u64 flags);
|
||||||
void *krealloc(void *old, size_t size, u64 flags);
|
void *krealloc(void *old, size_t size, u64 flags);
|
||||||
void kfree(void *ptr);
|
void kfree(void *ptr);
|
||||||
|
void cleanup_kfree(void **ptr);
|
||||||
|
|
||||||
void kalloc_init();
|
void kalloc_init();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ void slab_free(mem_cache_t *cache, void *ptr)
|
||||||
spinlock_release(&cache->lock);
|
spinlock_release(&cache->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _cleanup_kfree(void **ptr)
|
void cleanup_kfree(void **ptr)
|
||||||
{
|
{
|
||||||
if (ptr && *ptr)
|
if (ptr && *ptr)
|
||||||
kfree(ptr);
|
kfree(ptr);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue