plan9port/include/thread.h

194 lines
4 KiB
C
Raw Permalink Normal View History

#ifndef _THREAD_H_
#define _THREAD_H_ 1
#if defined(__cplusplus)
extern "C" {
#endif
2003-09-30 17:47:41 +00:00
2005-01-04 21:18:08 +00:00
AUTOLIB(thread)
2004-12-25 22:00:11 +00:00
/*
* basic procs and threads
2003-09-30 17:47:41 +00:00
*/
2004-12-25 22:00:11 +00:00
int proccreate(void (*f)(void *arg), void *arg, unsigned int stacksize);
int threadcreate(void (*f)(void *arg), void *arg, unsigned int stacksize);
void threadexits(char *);
void threadexitsall(char *);
void threadsetname(char*, ...);
void threadsetstate(char*, ...);
void threadneedbackground(void);
2005-02-11 16:52:29 +00:00
char *threadgetname(void);
int threadyield(void);
2006-02-07 17:02:05 +00:00
int threadidle(void);
2004-12-25 22:00:11 +00:00
void _threadready(_Thread*);
void _threadswitch(void);
void _threadsetsysproc(void);
void _threadsleep(Rendez*);
_Thread *_threadwakeup(Rendez*);
2004-12-27 00:14:43 +00:00
#define yield threadyield
2006-02-05 17:50:09 +00:00
int threadid(void);
2006-06-26 05:47:59 +00:00
void _threadpin(void);
void _threadunpin(void);
2004-12-25 22:00:11 +00:00
2005-01-17 21:29:00 +00:00
/*
* I am tired of making this mistake.
*/
#define exits do_not_call_exits_in_threaded_programs
#define _exits do_not_call__exits_in_threaded_programs
2005-01-04 22:07:31 +00:00
/*
* signals
*/
void threadnotify(int(*f)(void*,char*), int);
2004-12-28 01:35:38 +00:00
/*
* daemonize
2005-01-04 21:18:08 +00:00
*
2004-12-28 01:35:38 +00:00
void threaddaemonize(void);
2005-01-04 21:18:08 +00:00
*/
2004-12-28 01:35:38 +00:00
2004-12-25 22:00:11 +00:00
/*
* per proc and thread data
*/
void **procdata(void);
2005-03-18 18:53:51 +00:00
void **threaddata(void);
2003-09-30 17:47:41 +00:00
2004-12-25 22:00:11 +00:00
/*
* supplied by user instead of main.
* mainstacksize is size of stack allocated to run threadmain
*/
void threadmain(int argc, char *argv[]);
extern int mainstacksize;
2003-09-30 17:47:41 +00:00
int threadmaybackground(void);
2004-12-25 22:00:11 +00:00
/*
* channel communication
*/
typedef struct Alt Alt;
typedef struct _Altarray _Altarray;
typedef struct Channel Channel;
2003-09-30 17:47:41 +00:00
2004-12-25 22:00:11 +00:00
enum
{
2003-09-30 17:47:41 +00:00
CHANEND,
CHANSND,
CHANRCV,
CHANNOP,
CHANNOBLK
2003-09-30 17:47:41 +00:00
};
2004-12-25 22:00:11 +00:00
struct Alt
{
Channel *c;
2005-03-18 18:53:51 +00:00
void *v;
2004-12-25 22:00:11 +00:00
uint op;
_Thread *thread;
2003-09-30 17:47:41 +00:00
};
2004-12-25 22:00:11 +00:00
struct _Altarray
{
Alt **a;
uint n;
uint m;
};
2003-09-30 17:47:41 +00:00
2004-12-25 22:00:11 +00:00
struct Channel
{
uint bufsize;
uint elemsize;
uchar *buf;
uint nbuf;
uint off;
_Altarray asend;
_Altarray arecv;
char *name;
};
2003-09-30 17:47:41 +00:00
2004-12-25 22:00:11 +00:00
/* [Edit .+1,./^$/ |cfn -h $PLAN9/src/libthread/channel.c] */
int chanalt(Alt *alts);
Channel* chancreate(int elemsize, int elemcnt);
void chanfree(Channel *c);
int channbrecv(Channel *c, void *v);
void* channbrecvp(Channel *c);
ulong channbrecvul(Channel *c);
int channbsend(Channel *c, void *v);
int channbsendp(Channel *c, void *v);
int channbsendul(Channel *c, ulong v);
int chanrecv(Channel *c, void *v);
void* chanrecvp(Channel *c);
ulong chanrecvul(Channel *c);
int chansend(Channel *c, void *v);
int chansendp(Channel *c, void *v);
int chansendul(Channel *c, ulong v);
2004-12-27 03:36:37 +00:00
void chansetname(Channel *c, char *fmt, ...);
2004-12-25 22:00:11 +00:00
#define alt chanalt
#define nbrecv channbrecv
#define nbrecvp channbrecvp
2005-02-08 21:03:55 +00:00
#define nbrecvul channbrecvul
2004-12-25 22:00:11 +00:00
#define nbsend channbsend
#define nbsendp channbsendp
#define nbsendul channbsendul
#define recv chanrecv
#define recvp chanrecvp
#define recvul chanrecvul
#define send chansend
#define sendp chansendp
#define sendul chansendul
/*
* reference counts
*/
typedef struct Ref Ref;
2003-09-30 17:47:41 +00:00
2004-12-25 22:00:11 +00:00
struct Ref {
Lock lock;
long ref;
};
2003-09-30 17:47:41 +00:00
2004-12-25 22:00:11 +00:00
long decref(Ref *r);
long incref(Ref *r);
2003-09-30 17:47:41 +00:00
2004-12-25 22:00:11 +00:00
/*
* slave i/o processes
*/
typedef struct Ioproc Ioproc;
2003-09-30 17:47:41 +00:00
2004-12-25 22:00:11 +00:00
/* [Edit .+1,/^$/ |cfn -h $PLAN9/src/libthread/io*.c] */
void closeioproc(Ioproc *io);
long iocall(Ioproc *io, long (*op)(va_list*), ...);
int ioclose(Ioproc *io, int fd);
int iodial(Ioproc *io, char *addr, char *local, char *dir, int *cdfp);
void iointerrupt(Ioproc *io);
int ioopen(Ioproc *io, char *path, int mode);
Ioproc* ioproc(void);
long ioread(Ioproc *io, int fd, void *a, long n);
int ioread9pmsg(Ioproc*, int, void*, int);
long ioreadn(Ioproc *io, int fd, void *a, long n);
int iorecvfd(Ioproc *, int);
int iosendfd(Ioproc*, int, int);
int iosleep(Ioproc *io, long n);
long iowrite(Ioproc *io, int fd, void *a, long n);
/*
* exec external programs
*/
void threadexec(Channel*, int[3], char*, char *[]);
void threadexecl(Channel*, int[3], char*, ...);
int threadspawn(int[3], char*, char*[]);
int threadspawnd(int[3], char*, char*[], char*);
2005-01-18 18:26:43 +00:00
int threadspawnl(int[3], char*, ...);
2004-12-25 22:00:11 +00:00
Channel* threadwaitchan(void);
2003-09-30 17:47:41 +00:00
2006-02-12 16:48:11 +00:00
/*
* alternate interface to threadwaitchan - don't use both!
2006-02-12 16:48:11 +00:00
*/
Waitmsg* procwait(int pid);
#if defined(__cplusplus)
}
#endif
2003-09-30 17:47:41 +00:00
#endif /* _THREADH_ */