From 1fca5af522dd331bb231796c2f26625fe2dd2ae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Fri, 26 Jan 2018 14:55:59 +0100 Subject: [PATCH] Change interface for getting and setting current thread --- src/kernel/include/thread.h | 4 ---- src/kernel/proc/thread.c | 18 ++++++++++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/kernel/include/thread.h b/src/kernel/include/thread.h index 46723df..6b11d24 100644 --- a/src/kernel/include/thread.h +++ b/src/kernel/include/thread.h @@ -28,10 +28,6 @@ struct thread struct tcb tcb; }__attribute__((packed)); -struct thread *current_thread; -#define GET_CURRENT_THREAD() (current_thread) -#define SET_CURRENT_THREAD(thread) current_thread = (thread) - struct thread *new_thread(void (*function)(void)); void yield(); int get_tid(); diff --git a/src/kernel/proc/thread.c b/src/kernel/proc/thread.c index 2f541dd..4759b08 100644 --- a/src/kernel/proc/thread.c +++ b/src/kernel/proc/thread.c @@ -2,7 +2,7 @@ #include struct thread dummy; -struct thread *current_thread = 0; +struct thread *_current_thread = 0; uint64_t next_tid = 1; struct thread *new_thread(void (*function)(void)) @@ -17,9 +17,19 @@ struct thread *new_thread(void (*function)(void)) return th; } +struct thread *current_thread() +{ + return _current_thread; +} + +void set_current_thread(struct thread *th) +{ + _current_thread = th; +} + void switch_thread(struct thread *old, struct thread *new) { - SET_CURRENT_THREAD(new); + set_current_thread(new); swtch(&old->tcb.stack_ptr, &new->tcb.stack_ptr); } @@ -27,7 +37,7 @@ void yield() { struct thread *old, *new; - old = GET_CURRENT_THREAD(); + old = current_thread(); if(old) ready(old); else @@ -39,5 +49,5 @@ void yield() int get_tid() { - return GET_CURRENT_THREAD()->tcb.tid; + return current_thread()->tcb.tid; }