2004-12-25 21:57:50 +00:00
|
|
|
#include <ucontext.h>
|
|
|
|
|
|
|
|
typedef struct Context Context;
|
|
|
|
typedef struct Proc Proc;
|
|
|
|
typedef struct _Procrendez _Procrendez;
|
|
|
|
|
2004-12-27 00:13:48 +00:00
|
|
|
typedef struct Jmp Jmp;
|
|
|
|
struct Jmp
|
|
|
|
{
|
|
|
|
p9jmp_buf b;
|
|
|
|
};
|
|
|
|
|
2004-12-25 21:57:50 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
STACK = 8192
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Context
|
|
|
|
{
|
|
|
|
ucontext_t uc;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _Thread
|
|
|
|
{
|
|
|
|
_Thread *next;
|
|
|
|
_Thread *prev;
|
|
|
|
_Thread *allnext;
|
|
|
|
_Thread *allprev;
|
|
|
|
Context context;
|
|
|
|
uint id;
|
|
|
|
uchar *stk;
|
|
|
|
uint stksize;
|
|
|
|
int exiting;
|
|
|
|
void (*startfn)(void*);
|
|
|
|
void *startarg;
|
|
|
|
Proc *proc;
|
|
|
|
char name[256];
|
|
|
|
char state[256];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _Procrendez
|
|
|
|
{
|
|
|
|
Lock *l;
|
|
|
|
int asleep;
|
|
|
|
pthread_cond_t cond;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern void _procsleep(_Procrendez*);
|
|
|
|
extern void _procwakeup(_Procrendez*);
|
|
|
|
|
|
|
|
struct Proc
|
|
|
|
{
|
|
|
|
pthread_t tid;
|
|
|
|
Lock lock;
|
|
|
|
_Thread *thread;
|
|
|
|
_Threadlist runqueue;
|
|
|
|
_Threadlist allthreads;
|
|
|
|
uint nthread;
|
|
|
|
uint sysproc;
|
|
|
|
_Procrendez runrend;
|
|
|
|
Context schedcontext;
|
|
|
|
void *udata;
|
2004-12-27 00:13:48 +00:00
|
|
|
Jmp sigjmp;
|
2004-12-25 21:57:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern Proc *xxx;
|
|
|
|
#define proc() _threadproc()
|
|
|
|
#define setproc(p) _threadsetproc(p)
|
|
|
|
|
2004-12-27 03:49:03 +00:00
|
|
|
extern void _procstart(Proc*, void (*fn)(Proc*));
|
2004-12-25 21:57:50 +00:00
|
|
|
extern _Thread *_threadcreate(Proc*, void(*fn)(void*), void*, uint);
|
|
|
|
extern void _threadexit(void);
|
|
|
|
extern Proc *_threadproc(void);
|
|
|
|
extern void _threadsetproc(Proc*);
|
|
|
|
extern int _threadlock(Lock*, int, ulong);
|
|
|
|
extern void _threadunlock(Lock*, ulong);
|
2004-12-27 00:13:48 +00:00
|
|
|
extern void _pthreadinit(void);
|