diff options
| author | rsc <devnull@localhost> | 2004-09-17 03:34:32 +0000 |
|---|---|---|
| committer | rsc <devnull@localhost> | 2004-09-17 03:34:32 +0000 |
| commit | bcf527a98e295548629620a7cb06ada951db7822 (patch) | |
| tree | 0c459268d6391745a7acc3fefb82ba1e62ed858e /src/lib9/rendez-Linux.c | |
| parent | 06bb4ed20d855b60e39c1125d8d715ba8892265b (diff) | |
| download | plan9port-bcf527a98e295548629620a7cb06ada951db7822.tar.gz plan9port-bcf527a98e295548629620a7cb06ada951db7822.zip | |
Continue switching library over to pthreads when possible.
Tprimes works on Linux 2.6. You can only have 128 procs
though.
Diffstat (limited to 'src/lib9/rendez-Linux.c')
| -rw-r--r-- | src/lib9/rendez-Linux.c | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/src/lib9/rendez-Linux.c b/src/lib9/rendez-Linux.c index 673818e0..6d479310 100644 --- a/src/lib9/rendez-Linux.c +++ b/src/lib9/rendez-Linux.c @@ -1,3 +1,60 @@ -/* Could use futex(2) here instead of signals? */ +/* + * On Linux 2.6 and later, we can use pthreads (in fact, we must), + * but on earlier Linux, pthreads are incompatible with using our + * own coroutines in libthread. In order to make binaries that work + * on either system, we detect the pthread library in use and call + * the appropriate functions. + */ +#include <u.h> +#include <signal.h> +#include <pthread.h> +#include <libc.h> + +#define _procsleep _procsleep_signal +#define _procwakeup _procwakeup_signal #include "rendez-signal.c" + +#undef _procsleep +#undef _procwakeup +#define _procsleep _procsleep_pthread +#define _procwakeup _procwakeup_pthread +#include "rendez-pthread.c" + +#undef _procsleep +#undef _procwakeup + +int +_islinuxnptl(void) +{ + static char buf[100]; + static int isnptl = -1; + + if(isnptl == -1){ + if(confstr(_CS_GNU_LIBPTHREAD_VERSION, buf, sizeof buf) > 0 + && strncmp(buf, "NPTL", 4) == 0) + isnptl = 1; + else + isnptl = 0; + } + return isnptl; +} + +void +_procsleep(_Procrend *r) +{ + if(_islinuxnptl()) + return _procsleep_pthread(r); + else + return _procsleep_signal(r); +} + +void +_procwakeup(_Procrend *r) +{ + if(_islinuxnptl()) + return _procwakeup_pthread(r); + else + return _procwakeup_signal(r); +} + |
