new:kzalloc

This commit is contained in:
fslongjin
2022-08-15 17:57:05 +08:00
parent cec44c1fd7
commit f513286f53
11 changed files with 73 additions and 29 deletions

View File

@ -1,5 +1,7 @@
#pragma once
#define __force __attribute__((force))
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)

8
kernel/common/gfp.h Normal file
View File

@ -0,0 +1,8 @@
#pragma once
#include <common/sys/types.h>
#include <common/compiler.h>
/**
* __GFP_ZERO: 获取内存的同时,将获取到的这块内存清空
*
*/
#define __GFP_ZERO ((gfp_t)(1UL << 0))

View File

@ -37,14 +37,14 @@ void mutex_lock(mutex_t *lock)
spin_lock(&lock->wait_lock);
if (likely(mutex_is_locked(lock)))
{
struct mutex_waiter_t *waiter = (struct mutex_waiter_t *)kmalloc(sizeof(struct mutex_waiter_t), 0);
struct mutex_waiter_t *waiter = (struct mutex_waiter_t *)kzalloc(sizeof(struct mutex_waiter_t), 0);
if (waiter == NULL)
{
kerror("In mutex_lock: no memory to alloc waiter. Program's behaviour might be indetermined!");
spin_unlock(&lock->wait_lock);
return;
}
memset(waiter, 0, sizeof(struct mutex_waiter_t));
// memset(waiter, 0, sizeof(struct mutex_waiter_t));
waiter->pcb = current_pcb;
list_init(&waiter->list);
list_append(&lock->wait_list, &waiter->list);

View File

@ -83,4 +83,6 @@ typedef struct __pthread_spinlock_t
typedef struct __pthread_condattr_t
{
int clockid; // clockid_t
} pthread_condattr_t;
} pthread_condattr_t;
typedef uint64_t gfp_t;