You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Justin Erenkrantz <je...@ebuilt.com> on 2001/07/27 00:21:23 UTC

[PATCH] Allow use of pthread related code without threads.

This patch would allow the use of pthread-related code (think mutex and
rwlocks, etc.) without having threads.  Not everything in pthread is
related to threads...

Would applying this break anything?  Could having the pthread library
linked (assuming it has it, of course) cause a problem (even though
we aren't using threads)?

This allows us to use pthread_mutex_t in cross-process mode even if we 
aren't threaded.  (Think of the accept mutex in httpd.)  -- justin

Index: configure.in
===================================================================
RCS file: /home/cvs/apr/configure.in,v
retrieving revision 1.345
diff -u -r1.345 configure.in
--- configure.in	2001/07/26 00:08:40	1.345
+++ configure.in	2001/07/26 22:13:54
@@ -257,15 +257,18 @@
 if test -z "$enable_threads"; then
 	AC_ARG_ENABLE(threads,
 	[  --enable-threads        Enable threading support in APR.],
-	[ enable_threads=$enableval] ,
+	[ enable_threads=$enableval ],
 	[ APR_CHECK_PTHREADS_H([ enable_threads="pthread" ] ,
 	                       [ enable_threads="no" ] ) ] )
 fi
 
 if test "$enable_threads" = "no"; then
     threads="0"
-    pthreadh="0"
     pthreadser="0"
+    APR_PTHREADS_CHECK_SAVE
+    APR_PTHREADS_CHECK
+    APR_CHECK_PTHREADS_H([ pthreadh="1" ], 
+                         [ pthreadh="0" APR_PTHREADS_CHECK_RESTORE ] )
 else
     if test "$enable_threads" = "pthread"; then
 # We have specified pthreads for our threading library, just make sure
@@ -304,29 +307,33 @@
     if test "$pthreadh" = "1"; then
         APR_CHECK_PTHREAD_GETSPECIFIC_TWO_ARGS
         APR_CHECK_PTHREAD_ATTR_GETDETACHSTATE_ONE_ARG
-        AC_CHECK_FUNCS(pthread_key_delete pthread_rwlock_init)
+        AC_CHECK_FUNCS(pthread_key_delete)
+    fi
+fi
+
+if test "$pthreadh" = "1"; then
+    AC_CHECK_FUNCS(pthread_rwlock_init)
 
-        if test "$ac_cv_func_pthread_rwlock_init" = "yes"; then
-            dnl #----------------------------- Checking for pthread_rwlock_t
-            dnl # Linux is silly as it has pthread_rwlock_init defined
-            dnl # but keeps the pthread_rwlock_t structure hidden unless 
-            dnl # special things are defined.
-            AC_TRY_COMPILE([#include <sys/types.h>
-                            #include <pthread.h>], 
+    if test "$ac_cv_func_pthread_rwlock_init" = "yes"; then
+        dnl #----------------------------- Checking for pthread_rwlock_t
+        dnl # Linux is silly as it has pthread_rwlock_init defined
+        dnl # but keeps the pthread_rwlock_t structure hidden unless 
+        dnl # special things are defined.
+        AC_TRY_COMPILE([#include <sys/types.h>
+                        #include <pthread.h>], 
+            [pthread_rwlock_t rwlock=PTHREAD_RWLOCK_INITIALIZER;],
+             ac_cv_struct_pthread_rw=yes, ac_cv_struct_pthread_rw=no)
+        if test "$ac_cv_struct_pthread_rw" = "no"; then
+            AC_TRY_COMPILE([#define _XOPEN_SOURCE 500
+                #define _BSD_SOURCE
+                #define _SVID_SOURCE
+                #include <sys/types.h>
+                #include <pthread.h>], 
                 [pthread_rwlock_t rwlock=PTHREAD_RWLOCK_INITIALIZER;],
-                 ac_cv_struct_pthread_rw=yes, ac_cv_struct_pthread_rw=no)
-            if test "$ac_cv_struct_pthread_rw" = "no"; then
-                AC_TRY_COMPILE([#define _XOPEN_SOURCE 500
-                    #define _BSD_SOURCE
-                    #define _SVID_SOURCE
-                    #include <sys/types.h>
-                    #include <pthread.h>], 
-                    [pthread_rwlock_t rwlock=PTHREAD_RWLOCK_INITIALIZER;],
-                    ac_cv_struct_pthread_rw=yes, ac_cv_struct_pthread_rw=no)
-                if test "$ac_cv_struct_pthread_rw" = "yes"; then
-                    APR_ADDTO(CPPFLAGS, [-D_XOPEN_SOURCE=500 -D_BSD_SOURCE])
-                    APR_ADDTO(CPPFLAGS, [-D_SVID_SOURCE])
-                fi
+                ac_cv_struct_pthread_rw=yes, ac_cv_struct_pthread_rw=no)
+            if test "$ac_cv_struct_pthread_rw" = "yes"; then
+                APR_ADDTO(CPPFLAGS, [-D_XOPEN_SOURCE=500 -D_BSD_SOURCE])
+                APR_ADDTO(CPPFLAGS, [-D_SVID_SOURCE])
             fi
         fi
     fi
@@ -971,7 +978,7 @@
 # any POLL definitions.
 APR_CHECK_DEFINE_FILES(POLLIN, poll.h sys/poll.h)
 
-if test "$threads" = "1"; then
+if test "$pthreadh" = "1"; then
     APR_CHECK_DEFINE(PTHREAD_PROCESS_SHARED, pthread.h)
     AC_CHECK_FUNCS(pthread_mutexattr_setpshared)
     dnl Some systems have setpshared and define PROCESS_SHARED, but don't 
Index: include/arch/unix/locks.h
===================================================================
RCS file: /home/cvs/apr/include/arch/unix/locks.h,v
retrieving revision 1.36
diff -u -r1.36 locks.h
--- include/arch/unix/locks.h	2001/07/19 00:11:56	1.36
+++ include/arch/unix/locks.h	2001/07/26 22:13:54
@@ -92,11 +92,8 @@
 #ifdef HAVE_SYS_MMAN_H
 #include <sys/mman.h>
 #endif
-
-#if APR_HAS_THREADS
 #if APR_HAVE_PTHREAD_H
 #include <pthread.h>
-#endif
 #endif
 /* End System Headers */
 


Re: [PATCH] Allow use of pthread related code without threads.

Posted by "Roy T. Fielding" <fi...@ebuilt.com>.
On Thu, Jul 26, 2001 at 04:31:53PM -0700, Aaron Bannert wrote:
> Does having threads mean we require _REENTRANT to be defined
> (on Solaris)? My followup to that question is: does having _REENTRANT
> defined change the way anything operates in a way that we aren't
> expecting?

It must be defined regardless of threads, since no library that is
compiled with _REENTRANT can be used by code that is not compiled with
_REENTRANT, and vice versa.  The symbol modifies the definition of errno.
We always need to define it because things like PHP will always define it.

....Roy


Re: [PATCH] Allow use of pthread related code without threads.

Posted by Aaron Bannert <aa...@ebuilt.com>.
Does having threads mean we require _REENTRANT to be defined
(on Solaris)? My followup to that question is: does having _REENTRANT
defined change the way anything operates in a way that we aren't
expecting?

-aaron


On Thu, Jul 26, 2001 at 03:21:23PM -0700, Justin Erenkrantz wrote:
> This patch would allow the use of pthread-related code (think mutex and
> rwlocks, etc.) without having threads.  Not everything in pthread is
> related to threads...
> 
> Would applying this break anything?  Could having the pthread library
> linked (assuming it has it, of course) cause a problem (even though
> we aren't using threads)?
> 
> This allows us to use pthread_mutex_t in cross-process mode even if we 
> aren't threaded.  (Think of the accept mutex in httpd.)  -- justin
> 
> Index: configure.in
> ===================================================================
> RCS file: /home/cvs/apr/configure.in,v
> retrieving revision 1.345
> diff -u -r1.345 configure.in
> --- configure.in	2001/07/26 00:08:40	1.345
> +++ configure.in	2001/07/26 22:13:54
> @@ -257,15 +257,18 @@
>  if test -z "$enable_threads"; then
>  	AC_ARG_ENABLE(threads,
>  	[  --enable-threads        Enable threading support in APR.],
> -	[ enable_threads=$enableval] ,
> +	[ enable_threads=$enableval ],
>  	[ APR_CHECK_PTHREADS_H([ enable_threads="pthread" ] ,
>  	                       [ enable_threads="no" ] ) ] )
>  fi
>  
>  if test "$enable_threads" = "no"; then
>      threads="0"
> -    pthreadh="0"
>      pthreadser="0"
> +    APR_PTHREADS_CHECK_SAVE
> +    APR_PTHREADS_CHECK
> +    APR_CHECK_PTHREADS_H([ pthreadh="1" ], 
> +                         [ pthreadh="0" APR_PTHREADS_CHECK_RESTORE ] )
>  else
>      if test "$enable_threads" = "pthread"; then
>  # We have specified pthreads for our threading library, just make sure
> @@ -304,29 +307,33 @@
>      if test "$pthreadh" = "1"; then
>          APR_CHECK_PTHREAD_GETSPECIFIC_TWO_ARGS
>          APR_CHECK_PTHREAD_ATTR_GETDETACHSTATE_ONE_ARG
> -        AC_CHECK_FUNCS(pthread_key_delete pthread_rwlock_init)
> +        AC_CHECK_FUNCS(pthread_key_delete)
> +    fi
> +fi
> +
> +if test "$pthreadh" = "1"; then
> +    AC_CHECK_FUNCS(pthread_rwlock_init)
>  
> -        if test "$ac_cv_func_pthread_rwlock_init" = "yes"; then
> -            dnl #----------------------------- Checking for pthread_rwlock_t
> -            dnl # Linux is silly as it has pthread_rwlock_init defined
> -            dnl # but keeps the pthread_rwlock_t structure hidden unless 
> -            dnl # special things are defined.
> -            AC_TRY_COMPILE([#include <sys/types.h>
> -                            #include <pthread.h>], 
> +    if test "$ac_cv_func_pthread_rwlock_init" = "yes"; then
> +        dnl #----------------------------- Checking for pthread_rwlock_t
> +        dnl # Linux is silly as it has pthread_rwlock_init defined
> +        dnl # but keeps the pthread_rwlock_t structure hidden unless 
> +        dnl # special things are defined.
> +        AC_TRY_COMPILE([#include <sys/types.h>
> +                        #include <pthread.h>], 
> +            [pthread_rwlock_t rwlock=PTHREAD_RWLOCK_INITIALIZER;],
> +             ac_cv_struct_pthread_rw=yes, ac_cv_struct_pthread_rw=no)
> +        if test "$ac_cv_struct_pthread_rw" = "no"; then
> +            AC_TRY_COMPILE([#define _XOPEN_SOURCE 500
> +                #define _BSD_SOURCE
> +                #define _SVID_SOURCE
> +                #include <sys/types.h>
> +                #include <pthread.h>], 
>                  [pthread_rwlock_t rwlock=PTHREAD_RWLOCK_INITIALIZER;],
> -                 ac_cv_struct_pthread_rw=yes, ac_cv_struct_pthread_rw=no)
> -            if test "$ac_cv_struct_pthread_rw" = "no"; then
> -                AC_TRY_COMPILE([#define _XOPEN_SOURCE 500
> -                    #define _BSD_SOURCE
> -                    #define _SVID_SOURCE
> -                    #include <sys/types.h>
> -                    #include <pthread.h>], 
> -                    [pthread_rwlock_t rwlock=PTHREAD_RWLOCK_INITIALIZER;],
> -                    ac_cv_struct_pthread_rw=yes, ac_cv_struct_pthread_rw=no)
> -                if test "$ac_cv_struct_pthread_rw" = "yes"; then
> -                    APR_ADDTO(CPPFLAGS, [-D_XOPEN_SOURCE=500 -D_BSD_SOURCE])
> -                    APR_ADDTO(CPPFLAGS, [-D_SVID_SOURCE])
> -                fi
> +                ac_cv_struct_pthread_rw=yes, ac_cv_struct_pthread_rw=no)
> +            if test "$ac_cv_struct_pthread_rw" = "yes"; then
> +                APR_ADDTO(CPPFLAGS, [-D_XOPEN_SOURCE=500 -D_BSD_SOURCE])
> +                APR_ADDTO(CPPFLAGS, [-D_SVID_SOURCE])
>              fi
>          fi
>      fi
> @@ -971,7 +978,7 @@
>  # any POLL definitions.
>  APR_CHECK_DEFINE_FILES(POLLIN, poll.h sys/poll.h)
>  
> -if test "$threads" = "1"; then
> +if test "$pthreadh" = "1"; then
>      APR_CHECK_DEFINE(PTHREAD_PROCESS_SHARED, pthread.h)
>      AC_CHECK_FUNCS(pthread_mutexattr_setpshared)
>      dnl Some systems have setpshared and define PROCESS_SHARED, but don't 
> Index: include/arch/unix/locks.h
> ===================================================================
> RCS file: /home/cvs/apr/include/arch/unix/locks.h,v
> retrieving revision 1.36
> diff -u -r1.36 locks.h
> --- include/arch/unix/locks.h	2001/07/19 00:11:56	1.36
> +++ include/arch/unix/locks.h	2001/07/26 22:13:54
> @@ -92,11 +92,8 @@
>  #ifdef HAVE_SYS_MMAN_H
>  #include <sys/mman.h>
>  #endif
> -
> -#if APR_HAS_THREADS
>  #if APR_HAVE_PTHREAD_H
>  #include <pthread.h>
> -#endif
>  #endif
>  /* End System Headers */
>