Rename some stuff - cleanup

This commit is contained in:
Thomas Lovén 2018-01-27 20:27:34 +01:00
parent 13946b1758
commit fd0ca6f617
4 changed files with 9 additions and 13 deletions

View File

@ -10,7 +10,7 @@
void thread_function() void thread_function()
{ {
int thread_id = get_tid(); int thread_id = current_thread()->tid;
while(1) while(1)
{ {

View File

@ -32,6 +32,6 @@ struct thread_stack
struct thread *new_thread(void (*function)(void)); struct thread *new_thread(void (*function)(void));
void yield(); void yield();
int get_tid(); struct thread *current_thread();
void swtch(void *, void *); void switch_stack(void *old_ptr, void *new_ptr);

View File

@ -1,8 +1,8 @@
.intel_syntax noprefix .intel_syntax noprefix
.global swtch .global switch_stack
swtch: switch_stack:
push rbp push rbp
mov rbp, rsp mov rbp, rsp
push r15 push r15

View File

@ -1,7 +1,7 @@
#include <thread.h> #include <thread.h>
#include <scheduler.h> #include <scheduler.h>
struct thread dummy; struct thread boot_thread;
struct thread *_current_thread = 0; struct thread *_current_thread = 0;
uint64_t next_tid = 1; uint64_t next_tid = 1;
@ -11,6 +11,7 @@ struct thread *new_thread(void (*function)(void))
struct thread *th = &stk->tcb; struct thread *th = &stk->tcb;
th->tid = next_tid++; th->tid = next_tid++;
stk->RBP = (uint64_t)&stk->RBP2; stk->RBP = (uint64_t)&stk->RBP2;
stk->ret = (uint64_t)function; stk->ret = (uint64_t)function;
th->stack_ptr = (uint64_t)&stk->RBP; th->stack_ptr = (uint64_t)&stk->RBP;
@ -31,7 +32,7 @@ void set_current_thread(struct thread *th)
void switch_thread(struct thread *old, struct thread *new) void switch_thread(struct thread *old, struct thread *new)
{ {
set_current_thread(new); set_current_thread(new);
swtch(&old->stack_ptr, &new->stack_ptr); switch_stack(&old->stack_ptr, &new->stack_ptr);
} }
void yield() void yield()
@ -42,13 +43,8 @@ void yield()
if(old) if(old)
ready(old); ready(old);
else else
old = &dummy; old = &boot_thread;
while(!(new = scheduler_next())); while(!(new = scheduler_next()));
switch_thread(old, new); switch_thread(old, new);
} }
int get_tid()
{
return current_thread()->tid;
}