kthread: formatting
This commit is contained in:
parent
c7feb31c22
commit
6cfc8e1c2f
@ -23,8 +23,9 @@ void kthreadExit()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int kthreadSetup(vaddr_t mainStack, size_t mainStackSize){
|
int kthreadSetup(vaddr_t mainStack, size_t mainStackSize)
|
||||||
struct kthread * current = (struct kthread *)malloc(sizeof(struct kthread));
|
{
|
||||||
|
struct kthread *current = (struct kthread *)malloc(sizeof(struct kthread));
|
||||||
strzcpy(current->name, "[KINIT]", KTHREAD_NAME_MAX_LENGTH);
|
strzcpy(current->name, "[KINIT]", KTHREAD_NAME_MAX_LENGTH);
|
||||||
current->stackAddr = mainStack;
|
current->stackAddr = mainStack;
|
||||||
current->stackSize = mainStackSize;
|
current->stackSize = mainStackSize;
|
||||||
@ -34,26 +35,26 @@ int kthreadSetup(vaddr_t mainStack, size_t mainStackSize){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct kthread *kthreadCreate(const char *name, cpu_kstate_function_arg1_t func,
|
struct kthread *kthreadCreate(const char *name, cpu_kstate_function_arg1_t func, void *args)
|
||||||
void *args)
|
|
||||||
{
|
{
|
||||||
struct kthread *thread = (struct kthread *)malloc(sizeof(struct kthread));
|
struct kthread *thread = (struct kthread *)malloc(sizeof(struct kthread));
|
||||||
if (!thread)
|
if (!thread)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
thread->stackAddr = (vaddr_t) malloc(KTHREAD_DEFAULT_STACK_SIZE);
|
thread->stackAddr = (vaddr_t)malloc(KTHREAD_DEFAULT_STACK_SIZE);
|
||||||
|
printf("Alloc stask at 0x%x strcut at 0x%x\n", thread->stackAddr, thread);
|
||||||
thread->stackSize = KTHREAD_DEFAULT_STACK_SIZE;
|
thread->stackSize = KTHREAD_DEFAULT_STACK_SIZE;
|
||||||
|
|
||||||
if(!thread->stackAddr)
|
if (!thread->stackAddr)
|
||||||
goto free_mem;
|
goto free_mem;
|
||||||
|
|
||||||
if(name)
|
if (name)
|
||||||
strzcpy(thread->name, name, KTHREAD_NAME_MAX_LENGTH);
|
strzcpy(thread->name, name, KTHREAD_NAME_MAX_LENGTH);
|
||||||
else
|
else
|
||||||
strzcpy(thread->name, "[UNKNOW]", KTHREAD_NAME_MAX_LENGTH);
|
strzcpy(thread->name, "[UNKNOW]", KTHREAD_NAME_MAX_LENGTH);
|
||||||
|
|
||||||
if(cpu_kstate_init(&thread->cpuState, (cpu_kstate_function_arg1_t *)func, (vaddr_t)args,
|
if (cpu_kstate_init(&thread->cpuState, (cpu_kstate_function_arg1_t *)func,
|
||||||
thread->stackAddr, thread->stackSize,
|
(vaddr_t)args, thread->stackAddr, thread->stackSize,
|
||||||
(cpu_kstate_function_arg1_t *)kthreadExit, 0))
|
(cpu_kstate_function_arg1_t *)kthreadExit, 0))
|
||||||
goto free_mem;
|
goto free_mem;
|
||||||
|
|
||||||
@ -65,14 +66,16 @@ free_mem:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void kthreadDelete(struct kthread *thread){
|
void kthreadDelete(struct kthread *thread)
|
||||||
|
{
|
||||||
list_delete(currentThread, thread);
|
list_delete(currentThread, thread);
|
||||||
|
|
||||||
free((void *)thread->stackAddr);
|
free((void *)thread->stackAddr);
|
||||||
free((void *)thread);
|
free((void *)thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct kthread *kthreadSelectNext(){
|
struct kthread *kthreadSelectNext()
|
||||||
|
{
|
||||||
struct kthread *nextThread = currentThread->next;
|
struct kthread *nextThread = currentThread->next;
|
||||||
return nextThread;
|
return nextThread;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user