From b3a20a96eb2b91a5b0b8a8fb506e20a2fb50ebe8 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Dec 2020 00:10:11 -0500 Subject: libthread: add threadmaybackground Programs that want to background themselves now need to define threadmaybackground returning 1. This avoids a confusing (to people and debuggers) extra parent process for all the threaded programs that will never want to background themselves. --- include/thread.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/thread.h b/include/thread.h index c01cd516..8c800829 100644 --- a/include/thread.h +++ b/include/thread.h @@ -1,7 +1,7 @@ #ifndef _THREAD_H_ #define _THREAD_H_ 1 #if defined(__cplusplus) -extern "C" { +extern "C" { #endif AUTOLIB(thread) @@ -15,6 +15,7 @@ void threadexits(char *); void threadexitsall(char *); void threadsetname(char*, ...); void threadsetstate(char*, ...); +void threadneedbackground(void); char *threadgetname(void); int threadyield(void); int threadidle(void); @@ -60,6 +61,8 @@ void **threaddata(void); void threadmain(int argc, char *argv[]); extern int mainstacksize; +int threadmaybackground(void); + /* * channel communication */ @@ -180,7 +183,7 @@ int threadspawnl(int[3], char*, ...); Channel* threadwaitchan(void); /* - * alternate interface to threadwaitchan - don't use both! + * alternate interface to threadwaitchan - don't use both! */ Waitmsg* procwait(int pid); -- cgit v1.2.3 From 18571208068d5fe2f0bf7b4e980525a7f577c503 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Dec 2020 07:18:30 -0500 Subject: libthread: simplify Now that everything uses pthreads and pthreadperthread, can delete various conditionals, all the custom context code, and so on. Also update documents. Fixes #355. --- include/libc.h | 2 -- include/u.h | 7 +------ 2 files changed, 1 insertion(+), 8 deletions(-) (limited to 'include') diff --git a/include/libc.h b/include/libc.h index 4bb537d6..1e24f0bb 100644 --- a/include/libc.h +++ b/include/libc.h @@ -473,10 +473,8 @@ extern _Thread *(*threadnow)(void); typedef struct Lock Lock; struct Lock { -#ifdef PLAN9PORT_USING_PTHREADS int init; pthread_mutex_t mutex; -#endif int held; }; diff --git a/include/u.h b/include/u.h index f84e348a..856e10f4 100644 --- a/include/u.h +++ b/include/u.h @@ -67,7 +67,6 @@ typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)]; #if defined(__linux__) # include # include -# define PLAN9PORT_USING_PTHREADS 1 # if defined(__USE_MISC) # undef _NEEDUSHORT # undef _NEEDUINT @@ -76,7 +75,6 @@ typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)]; #elif defined(__sun__) # include # include -# define PLAN9PORT_USING_PTHREADS 1 # undef _NEEDUSHORT # undef _NEEDUINT # undef _NEEDULONG @@ -84,7 +82,6 @@ typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)]; #elif defined(__FreeBSD__) # include # include -# define PLAN9PORT_USING_PTHREADS 1 # include # if !defined(_POSIX_SOURCE) # undef _NEEDUSHORT @@ -93,7 +90,6 @@ typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)]; #elif defined(__APPLE__) # include # include -# define PLAN9PORT_USING_PTHREADS 1 # if __GNUC__ < 4 # undef _NEEDUSHORT # undef _NEEDUINT @@ -108,20 +104,19 @@ typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)]; #elif defined(__NetBSD__) # include # include +# include # undef _NEEDUSHORT # undef _NEEDUINT # undef _NEEDULONG #elif defined(__OpenBSD__) # include # include -# define PLAN9PORT_USING_PTHREADS 1 # undef _NEEDUSHORT # undef _NEEDUINT # undef _NEEDULONG #else /* No idea what system this is -- try some defaults */ # include -# define PLAN9PORT_USING_PTHREADS 1 #endif #ifndef O_DIRECT -- cgit v1.2.3