rbb 99/10/19 12:21:24
Modified: src/lib/apr acconfig.h configure.in
src/lib/apr/file_io/unix dir.c
src/lib/apr/network_io/unix sockets.c sockopt.c
src/lib/apr/time/unix time.c
Removed: src/lib/apr/inc apr_macro.h
Log:
Remove all of the ugly SAFETY_LOCK code. APR determines if it has threading
support turned on. If so, it uses re-entrant functions that should be there.
If the functions aren't there, we use non-re-entrant functions. If this
causes problems in the future, we'll provide implementations of the
re-entrant functions. For now though, this should work, and it is definately
cleaner than what we had before.
Revision Changes Path
1.9 +2 -0 apache-2.0/src/lib/apr/acconfig.h
Index: acconfig.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/acconfig.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- acconfig.h 1999/10/18 09:44:07 1.8
+++ acconfig.h 1999/10/19 19:20:58 1.9
@@ -47,6 +47,8 @@
#undef NEED_RLIM_T
#undef USEBCOPY
+#undef APR_HAS_THREADS
+
@BOTTOM@
#define API_EXPORT(type) type
#define API_EXPORT_NONSTD(type) type
1.21 +22 -1 apache-2.0/src/lib/apr/configure.in
Index: configure.in
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/configure.in,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- configure.in 1999/10/14 03:00:33 1.20
+++ configure.in 1999/10/19 19:21:01 1.21
@@ -179,7 +179,6 @@
AC_CHECK_HEADERS(sys/types.h)
AC_CHECK_HEADERS(sys/wait.h)
-AC_CHECK_HEADERS(pthread.h)
AC_CHECK_HEADERS(kernel/OS.h)
dnl Checks for typedefs, structures, and compiler characteristics.
@@ -209,6 +208,28 @@
AC_CHECK_FUNC(_getch)
AC_CHECK_FUNCS(gmtime_r localtime_r)
+
+AC_MSG_CHECKING(whether to enable thread support)
+AC_ARG_ENABLE(threads,
+[ --enable-threads Enable threading support in APR.],
+[
+ if test "$enableval" = "no"; then
+ AC_DEFINE(APR_HAS_THREADS, 0)
+ AC_MSG_RESULT(no)
+ else
+ if test "$enableval" = "pthread"; then
+ AC_CHECK_HEADERS(pthread.h, [ AC_DEFINE(APR_HAS_THREADS, 1) ], [
AC_DEFINE(APR_HAS_THREADS, 0) ] )
+ AC_MSG_RESULT(yes)
+ else
+ AC_MSG_RESULT(no)
+ fi
+ fi
+],
+[
+ AC_CHECK_HEADERS(pthread.h, [ AC_DEFINE(APR_HAS_THREADS, 1) ], [
AC_DEFINE(APR_HAS_THREADS, 0) ] )
+
+])
+
dnl Start building stuff from our information
AC_SUBST(LDLIBS)
1.10 +13 -8 apache-2.0/src/lib/apr/file_io/unix/dir.c
Index: dir.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/dir.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- dir.c 1999/10/16 14:06:58 1.9
+++ dir.c 1999/10/19 19:21:13 1.10
@@ -58,15 +58,11 @@
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
-#include "apr_macro.h"
#include "fileio.h"
#include "apr_file_io.h"
#include "apr_lib.h"
-#include "apr_lock.h"
#include "apr_portable.h"
-static ap_lock_t *lock_readdir = NULL;
-
static ap_status_t dir_cleanup(void *thedir)
{
struct dir_t *dir = thedir;
@@ -128,11 +124,20 @@
*/
ap_status_t ap_readdir(struct dir_t *thedir)
{
+#if APR_HAS_THREADS && _POSIX_THREAD_SAFE_FUNCTIONS
+ return readdir_r(thedir->dirstruct, thedir->entry, &thedir->entry);
+#else
+ int save_errno;
ap_status_t status;
- SAFETY_LOCK(readdir, "readdir_file");
- READDIR(thedir->dirstruct, thedir->entry, status);
- SAFETY_UNLOCK(readdir);
- return status;
+
+ thedir->entry = readdir(thedir->dirstruct);
+ if (thedir->entry == NULL) {
+ if (errno == save_errno) {
+ return APR_SUCCESS;
+ }
+ return errno;
+ }
+#endif
}
/* ***APRDOC********************************************************
1.18 +5 -10 apache-2.0/src/lib/apr/network_io/unix/sockets.c
Index: sockets.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/unix/sockets.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- sockets.c 1999/10/16 14:07:00 1.17
+++ sockets.c 1999/10/19 19:21:18 1.18
@@ -58,7 +58,6 @@
#include "apr_general.h"
#include "apr_portable.h"
#include "apr_lib.h"
-#include "apr_macro.h"
#include <errno.h>
#include <string.h>
#include <sys/socket.h>
@@ -210,9 +209,8 @@
ap_status_t ap_getipaddr(char *addr, ap_ssize_t len,
const struct socket_t *sock)
{
- SAFETY_LOCK(inet, "inetfile");
- INET_NTOA(sock->addr->sin_addr, addr, len - 1);
- SAFETY_UNLOCK(inet);
+ char *temp = inet_ntoa(sock->addr->sin_addr);
+ ap_cpystrn(addr, temp, len - 1);
return APR_SUCCESS;
}
@@ -293,24 +291,21 @@
ap_status_t ap_connect(struct socket_t *sock, char *hostname)
{
struct hostent *hp;
- struct hostent *hp_safe;
if (hostname != NULL) {
- SAFETY_LOCK(network, "net_file");
- GETHOSTBYNAME(hostname, hp, hp_safe);
- SAFETY_UNLOCK(network);
+ hp = gethostbyname(hostname);
if ((sock->socketdes < 0) || (!sock->addr)) {
return APR_ENOTSOCK;
}
- if (!hp_safe) {
+ if (!hp) {
if (h_errno == TRY_AGAIN) {
return EAGAIN;
}
return h_errno;
}
- memcpy((char *)&sock->addr->sin_addr, hp_safe->h_addr_list[0],
hp_safe->h_length);
+ memcpy((char *)&sock->addr->sin_addr, hp->h_addr_list[0],
hp->h_length);
sock->addr_len = sizeof(*sock->addr);
}
1.10 +0 -9 apache-2.0/src/lib/apr/network_io/unix/sockopt.c
Index: sockopt.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/unix/sockopt.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- sockopt.c 1999/10/16 14:07:00 1.9
+++ sockopt.c 1999/10/19 19:21:20 1.10
@@ -57,7 +57,6 @@
#include "apr_network_io.h"
#include "apr_general.h"
#include "apr_lib.h"
-#include "apr_macro.h"
#include <errno.h>
#include <string.h>
#include <sys/socket.h>
@@ -67,10 +66,6 @@
#include <fcntl.h>
#include <netdb.h>
-#ifndef _POSIX_THREAD_SAFE_FUNCTIONS
-extern ap_lock_t *lock_network;
-#endif
-
static ap_status_t soblock(int sd)
{
int fd_flags;
@@ -208,13 +203,9 @@
ap_status_t ap_get_remote_hostname(char **name, struct socket_t *sock)
{
struct hostent *hptr;
- struct hostent *hp_safe;
- SAFETY_LOCK(network, "net_file");
- GETHOSTBYADDR((char *)&(sock->addr->sin_addr), hptr, hp_safe);
hptr = gethostbyaddr((char *)&(sock->addr->sin_addr),
sizeof(struct in_addr), AF_INET);
- SAFETY_UNLOCK(network);
if (hptr != NULL) {
*name = ap_pstrdup(sock->cntxt, hptr->h_name);
if (*name) {
1.10 +10 -12 apache-2.0/src/lib/apr/time/unix/time.c
Index: time.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/time/unix/time.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- time.c 1999/10/16 12:52:07 1.9
+++ time.c 1999/10/19 19:21:22 1.10
@@ -58,16 +58,10 @@
#include "apr_general.h"
#include "apr_lib.h"
#include "apr_portable.h"
-#include "apr_macro.h"
#include <time.h>
#include <errno.h>
#include <string.h>
-#ifndef _POSIX_THREAD_SAFE_FUNCTIONS
-static ap_lock_t *lock_time = NULL;
-#endif
-
-
/* ***APRDOC********************************************************
* ap_status_t ap_make_time(ap_context_t *, ap_time_t *)
* Create a time entity.
@@ -113,15 +107,19 @@
{
switch (type) {
case APR_LOCALTIME: {
- SAFETY_LOCK(time, "timefile");
- LOCALTIME_R(&atime->currtime->tv_sec, atime->explodedtime);
- SAFETY_UNLOCK(time);
+#if APR_HAS_THREADS && _POSIX_THREAD_SAFE_FUNCTIONS
+ localtime_r(&atime->currtime->tv_sec, atime->explodedtime);
+#else
+ atime->explodedtime = localtime(&atime->currtime->tv_sec);
+#endif
break;
}
case APR_UTCTIME: {
- SAFETY_LOCK(time, "timefile");
- GMTIME_R(&atime->currtime->tv_sec, atime->explodedtime);
- SAFETY_UNLOCK(time);
+#if APR_HAS_THREADS && _POSIX_THREAD_SAFE_FUNCTIONS
+ gmtime_r(&atime->currtime->tv_sec, atime->explodedtime);
+#else
+ atime->explodedtime = gmtime(&atime->currtime->tv_sec);
+#endif
break;
}
}