diff options
| author | Sam Varshavchik | 2020-10-28 21:25:13 -0400 |
|---|---|---|
| committer | Sam Varshavchik | 2020-10-28 21:25:13 -0400 |
| commit | 0d4feee51d2c360c8f061c823b441afefddd07df (patch) | |
| tree | 57ee4374955a641250b523292363404f920b185a /waitlib | |
| parent | 6441fb0adc939f73f75fc1b03ee7f42bd57a1b2b (diff) | |
| download | courier-libs-0d4feee51d2c360c8f061c823b441afefddd07df.tar.bz2 | |
Fix LTO problem on Fedora
Diffstat (limited to 'waitlib')
| -rw-r--r-- | waitlib/Makefile.am | 3 | ||||
| -rw-r--r-- | waitlib/configure.ac | 20 | ||||
| -rw-r--r-- | waitlib/testwait.c | 29 |
3 files changed, 17 insertions, 35 deletions
diff --git a/waitlib/Makefile.am b/waitlib/Makefile.am index a743c58..5ce852d 100644 --- a/waitlib/Makefile.am +++ b/waitlib/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 1998 - 1999 Double Precision, Inc. See COPYING for +# Copyright 1998 - 2020 Double Precision, Inc. See COPYING for # distribution information. @@ -13,7 +13,6 @@ libwaitlib_la_SOURCES=waitlib.c waitlib.h waitlib2.c testwait_SOURCES=testwait.c testwait_DEPENDENCIES=libwaitlib.la testwait_LDADD=libwaitlib.la -testwait_CFLAGS=@PTHREAD@ check-am: ./testwait diff --git a/waitlib/configure.ac b/waitlib/configure.ac index c40846d..d475dee 100644 --- a/waitlib/configure.ac +++ b/waitlib/configure.ac @@ -106,24 +106,4 @@ then CFLAGS="-Wall $CFLAGS" fi -save_CFLAGS="$CFLAGS" - -AC_CACHE_CHECK([for -pthread flag],waitlib_cv_PTHREAD, - CFLAGS="$CFLAGS -pthread" - AC_TRY_COMPILE([],[], - [ - waitlib_cv_PTHREAD='yes' - ], - [ - waitlib_cv_PTHREAD='no' - ])) -CFLAGS="$save_CFLAGS" - -PTHREAD='' -if test "$waitlib_cv_PTHREAD" = "yes" -then - PTHREAD="$CFLAGS -pthread" -fi -AC_SUBST(PTHREAD) - AC_OUTPUT(Makefile) diff --git a/waitlib/testwait.c b/waitlib/testwait.c index 6020c36..a720e49 100644 --- a/waitlib/testwait.c +++ b/waitlib/testwait.c @@ -17,17 +17,13 @@ #define NUMCHILDREN 100 /* Start 100 child processes */ #define INITCHILDREN 10 /* Start with these many child procs */ -pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t cond = PTHREAD_COND_INITIALIZER; - -static unsigned started, finished; +static unsigned started; +static int reap_pipefd[2]; static void reap_child(pid_t p, int dummy) { - pthread_mutex_lock(&mutex); - ++finished; - pthread_cond_signal(&cond); - pthread_mutex_unlock(&mutex); + if (write(reap_pipefd[1], "", 1) < 0) + ; /* shut up gcc */ } static RETSIGTYPE sighandler(int sig) @@ -65,8 +61,9 @@ int main() int pipefd[2]; int pipefd2[2]; char c; +unsigned finished=0; - if (pipe(pipefd) || pipe(pipefd2)) + if (pipe(reap_pipefd) || pipe(pipefd) || pipe(pipefd2)) { perror("pipe"); exit(1); @@ -74,7 +71,7 @@ char c; signal(SIGCHLD, sighandler); - started=finished=0; + started=0; while (started < INITCHILDREN) { if (start_child() == 0) @@ -99,11 +96,17 @@ char c; _exit(0); alarm(30); - pthread_mutex_lock(&mutex); while (finished < started) { - pthread_cond_wait(&cond, &mutex); + char c; + int n=read(reap_pipefd[0], &c, 1); + + if (n <= 0) + { + fprintf(stderr, "pipe error\n"); + exit(1); + } + ++finished; } - pthread_mutex_unlock(&mutex); exit(0); } |
