Define curthread as an inline function that loads the thread pointer

directly from g7, the pcpu pointer. This guarantees correct behavior
when the thread migrates to a different CPU.
Commit message stolen from r205431. Additional testing by Peter Jeremy.

MFC after:	3 days
This commit is contained in:
Marius Strobl 2011-11-15 20:17:18 +00:00
parent 5a880d34e1
commit 1249ba5fc6

View File

@ -74,6 +74,16 @@ register struct pcpu *pcpup __asm__(__XSTRING(PCPU_REG));
#define PCPU_GET(member) (pcpup->pc_ ## member)
static __inline __pure2 struct thread *
__curthread(void)
{
struct thread *td;
__asm("ldx [%" __XSTRING(PCPU_REG) "], %0" : "=r" (td));
return (td);
}
#define curthread (__curthread())
/*
* XXX The implementation of this operation should be made atomic
* with respect to preemption.