aboutsummaryrefslogtreecommitdiff
path: root/src/libthread/threadimpl.h
blob: 9f70b0e06a56c10cc72502a4812a1800c7330e61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <ucontext.h>

typedef struct Context Context;
typedef struct Proc Proc;
typedef struct _Procrendez _Procrendez;

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;
};

extern Proc *xxx;
#define proc() _threadproc()
#define setproc(p) _threadsetproc(p)

extern void _procstart(Proc*, void (*fn)(void*));
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);