Change interface for getting and setting current thread
This commit is contained in:
parent
c26434f814
commit
1fca5af522
@ -28,10 +28,6 @@ struct thread
|
|||||||
struct tcb tcb;
|
struct tcb tcb;
|
||||||
}__attribute__((packed));
|
}__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));
|
struct thread *new_thread(void (*function)(void));
|
||||||
void yield();
|
void yield();
|
||||||
int get_tid();
|
int get_tid();
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include <scheduler.h>
|
#include <scheduler.h>
|
||||||
|
|
||||||
struct thread dummy;
|
struct thread dummy;
|
||||||
struct thread *current_thread = 0;
|
struct thread *_current_thread = 0;
|
||||||
|
|
||||||
uint64_t next_tid = 1;
|
uint64_t next_tid = 1;
|
||||||
struct thread *new_thread(void (*function)(void))
|
struct thread *new_thread(void (*function)(void))
|
||||||
@ -17,9 +17,19 @@ struct thread *new_thread(void (*function)(void))
|
|||||||
return th;
|
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)
|
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);
|
swtch(&old->tcb.stack_ptr, &new->tcb.stack_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,7 +37,7 @@ void yield()
|
|||||||
{
|
{
|
||||||
struct thread *old, *new;
|
struct thread *old, *new;
|
||||||
|
|
||||||
old = GET_CURRENT_THREAD();
|
old = current_thread();
|
||||||
if(old)
|
if(old)
|
||||||
ready(old);
|
ready(old);
|
||||||
else
|
else
|
||||||
@ -39,5 +49,5 @@ void yield()
|
|||||||
|
|
||||||
int get_tid()
|
int get_tid()
|
||||||
{
|
{
|
||||||
return GET_CURRENT_THREAD()->tcb.tid;
|
return current_thread()->tcb.tid;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user