httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@hyperreal.org
Subject cvs commit: apache-2.0/src/modules/mpm/mpmt_pthread acceptlock.c acceptlock.h mpmt_pthread.c
Date Sun, 10 Oct 1999 17:08:11 GMT
ben         99/10/10 10:08:10

  Modified:    src      Configure
               src/lib/apr configure.in
               src/lib/apr/include apr_network_io.h
               src/lib/apr/network_io/unix networkio.h poll.c sockets.c
               src/modules/mpm/mpmt_pthread acceptlock.c acceptlock.h
                        mpmt_pthread.c
  Log:
  Attempt to port mpmt_pthreads to APR, but threads seem to be broken on my plaform
  so it is only partially tested.
  
  Revision  Changes    Path
  1.11      +10 -3     apache-2.0/src/Configure
  
  Index: Configure
  ===================================================================
  RCS file: /export/home/cvs/apache-2.0/src/Configure,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Configure	1999/10/10 12:17:42	1.10
  +++ Configure	1999/10/10 17:07:53	1.11
  @@ -1724,15 +1724,24 @@
   ####################################################################
   ## Add in the APR library.
   ##
  +TEXTRA_CFLAGS=`egrep '^EXTRA_CFLAGS=' Makefile.config | tail -1 |\
  +	       sed -e 's;^EXTRA_CFLAGS=;;' -e 's;\`.*\`;;'`
  +
   if [ -d ./lib/apr ]; then
       if helpers/PrintPath -s autoconf; then
           echo " + bootstrapping Apache Portable Runtime (APR)"
           (cd lib/apr && autoconf && autoheader)
       fi
       echo " + configuring Apache Portable Runtime (APR)"
  +    APR_FLAGS=`egrep ^APR_FLAGS= $file|sed -e 's/APR_FLAGS='//`
  +    if [ "x$APR_FLAGS" != "x" ]; then
  +	echo "    o with flags: $APR_FLAGS"
  +    fi
       cd lib/apr 
       stripped_CFLAGS=`echo "$CFLAGS " | sed -e 's/-DTARGET[^ ]*//'` # FIXME
  -    CC="$CC" CFLAGS="$TEXTRA_CFLAGS $stripped_CFLAGS" OPTIM="$TOPTIM $OPTIM" ./configure
>/dev/null
  +    # configure fails with -Werror, because it writes crap C for its tests...
  +    stripped_TEXTRA_CFLAGS=`echo "$TEXTRA_CFLAGS" | sed -e 's/-Werror//'`
  +    CC="$CC" CFLAGS="$stripped_TEXTRA_CFLAGS $stripped_CFLAGS" OPTIM="$TOPTIM $OPTIM" ./configure
$APR_FLAGS > /dev/null
       if [ $? -ne 0 ]; then
           echo "** FAILED to configure APR"
           exit 1
  @@ -2161,8 +2170,6 @@
   ## ap_config_auto.h so they are available to external modules needing to
   ## include Apache header files.
   ##
  -TEXTRA_CFLAGS=`egrep '^EXTRA_CFLAGS=' Makefile.config | tail -1 |\
  -	       sed -e 's;^EXTRA_CFLAGS=;;' -e 's;\`.*\`;;'`
   tmpstr=`echo $CFLAGS $TEXTRA_CFLAGS |\
   	sed -e 's;[ 	]\([+-]\);!\1;g' -e 's/\([^\\\]\)"/\1/g' -e 's/\\\"/\"/g'`
   OIFS="$IFS"
  
  
  
  1.16      +3 -0      apache-2.0/src/lib/apr/configure.in
  
  Index: configure.in
  ===================================================================
  RCS file: /export/home/cvs/apache-2.0/src/lib/apr/configure.in,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- configure.in	1999/10/08 16:07:38	1.15
  +++ configure.in	1999/10/10 17:07:57	1.16
  @@ -28,6 +28,9 @@
   AC_CHECK_PROG(RM, rm, rm)
   AC_CHECK_PROG(AR, ar, ar)
   
  +AC_ARG_WITH(debug,[  --with-debug              Turn on debugging and compile time warnings],
  +	[if test "$GCC" = "yes"; then CFLAGS="$CFLAGS -g -Wall"; else CFLAGS="$CFLAGS -g"; fi])
  +
   dnl # this is the place to put specific options for platform/compiler
   dnl # combinations
   case "$OS:$CC" in
  
  
  
  1.9       +6 -3      apache-2.0/src/lib/apr/include/apr_network_io.h
  
  Index: apr_network_io.h
  ===================================================================
  RCS file: /export/home/cvs/apache-2.0/src/lib/apr/include/apr_network_io.h,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- apr_network_io.h	1999/10/04 16:36:54	1.8
  +++ apr_network_io.h	1999/10/10 17:07:59	1.9
  @@ -128,9 +128,12 @@
   ap_status_t ap_getport(ap_socket_t *, ap_uint32_t *);
   ap_status_t ap_getipaddr(char *buf, ap_ssize_t len, const ap_socket_t *sock);
   
  -ap_status_t ap_setup_poll(ap_pollfd_t **, ap_context_t *, ap_int32_t);
  -ap_status_t ap_poll(ap_pollfd_t *, ap_int32_t *, ap_int32_t);
  -ap_status_t ap_add_poll_socket(ap_pollfd_t *, ap_socket_t *, ap_int16_t);
  +ap_status_t ap_setup_poll(ap_pollfd_t **pollset, ap_context_t *ctx,
  +			  ap_int32_t nsocks);
  +ap_status_t ap_poll(struct pollfd_t *pollset, ap_int32_t *nsocks, 
  +		    ap_int32_t timeout);
  +ap_status_t ap_add_poll_socket(ap_pollfd_t *pollset, ap_socket_t *sock,
  +			       ap_int16_t events);
   ap_status_t ap_remove_poll_socket(ap_pollfd_t *, ap_socket_t *, ap_int16_t);
   ap_status_t ap_clear_poll_sockets(ap_pollfd_t *, ap_int16_t);
   ap_status_t ap_get_revents(ap_pollfd_t *, ap_socket_t *, ap_int16_t *);
  
  
  
  1.6       +3 -0      apache-2.0/src/lib/apr/network_io/unix/networkio.h
  
  Index: networkio.h
  ===================================================================
  RCS file: /export/home/cvs/apache-2.0/src/lib/apr/network_io/unix/networkio.h,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- networkio.h	1999/10/08 19:44:30	1.5
  +++ networkio.h	1999/10/10 17:08:00	1.6
  @@ -68,6 +68,9 @@
       struct sockaddr_in *addr;
       size_t addr_len;
       int timeout; 
  +#ifndef HAVE_POLL
  +    int connected;
  +#endif
   };
   
   struct pollfd_t {
  
  
  
  1.12      +8 -9      apache-2.0/src/lib/apr/network_io/unix/poll.c
  
  Index: poll.c
  ===================================================================
  RCS file: /export/home/cvs/apache-2.0/src/lib/apr/network_io/unix/poll.c,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- poll.c	1999/10/10 13:19:57	1.11
  +++ poll.c	1999/10/10 17:08:00	1.12
  @@ -349,8 +349,7 @@
   ap_status_t ap_get_revents(struct pollfd_t *aprset, struct socket_t *sock, ap_int16_t *event)
   {
       ap_int16_t revents = 0;
  -    char data[256];
  -    int dummy = 256;
  +    char data[1];
       int flags = MSG_PEEK;
   
       /* We just want to PEEK at the data, so I am setting up a dummy WSABUF
  @@ -358,24 +357,24 @@
        */
       if (FD_ISSET(sock->socketdes, aprset->read)) {
           revents |= APR_POLLIN;
  -        if (recv(sock->socketdes, &data, dummy, flags) == -1) {
  +        if (sock->connected
  +	    && recv(sock->socketdes, data, sizeof data, flags) == -1) {
               switch (errno) {
                   case ECONNRESET:
                   case ECONNABORTED:
                   case ESHUTDOWN:
  -                case ENETRESET: {
  +                case ENETRESET:
                       revents ^= APR_POLLIN;
                       revents |= APR_POLLHUP;
                       break;
  -                }
  -                case ENOTSOCK: {
  +                case ENOTSOCK:
                       revents ^= APR_POLLIN;
                       revents |= APR_POLLNVAL;
  -                }
  -                default: {
  +		    break;
  +                default:
                       revents ^= APR_POLLIN;
                       revents |= APR_POLLERR;
  -                }
  +		    break;
               }
           }
       }
  
  
  
  1.14      +6 -0      apache-2.0/src/lib/apr/network_io/unix/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /export/home/cvs/apache-2.0/src/lib/apr/network_io/unix/sockets.c,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- sockets.c	1999/10/08 20:04:18	1.13
  +++ sockets.c	1999/10/10 17:08:00	1.14
  @@ -258,6 +258,9 @@
       (*new)->addr = (struct sockaddr_in *)ap_palloc((*new)->cntxt, 
                    sizeof(struct sockaddr_in));
       (*new)->addr_len = sizeof(struct sockaddr_in);
  +#ifndef HAVE_POLL
  +    (*new)->connected = 1;
  +#endif
   
       (*new)->socketdes = accept(sock->socketdes, (struct sockaddr *)(*new)->addr,
                           &(*new)->addr_len);
  @@ -307,6 +310,9 @@
           return errno;
       }
       else {
  +#ifndef HAVE_POLL
  +	sock->connected=1;
  +#endif
           return APR_SUCCESS;
       }
   }
  
  
  
  1.12      +8 -7      apache-2.0/src/modules/mpm/mpmt_pthread/acceptlock.c
  
  Index: acceptlock.c
  ===================================================================
  RCS file: /export/home/cvs/apache-2.0/src/modules/mpm/mpmt_pthread/acceptlock.c,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- acceptlock.c	1999/10/06 23:04:12	1.11
  +++ acceptlock.c	1999/10/10 17:08:06	1.12
  @@ -257,7 +257,7 @@
   #endif
   }
   
  -void accept_mutex_cleanup(void *foo)
  +ap_status_t accept_mutex_cleanup(void *foo)
   {
       int i;
      
  @@ -394,7 +394,7 @@
    * means we have to be sure to clean this up or else we'll leak
    * semaphores.
    */
  -void accept_mutex_cleanup(void *foo)
  +ap_status_t accept_mutex_cleanup(void *foo)
   {
       union semun ick;
       int i;
  @@ -555,7 +555,7 @@
   
   static int *lock_fd = NULL;
   
  -void accept_mutex_cleanup(void *foo)
  +ap_status_t accept_mutex_cleanup(void *foo)
   {
       int i;
     
  @@ -564,6 +564,7 @@
           lock_fname = expand_lock_fname(foo, i);
           unlink(lock_fname);
       }
  +    return APR_SUCCESS;
   }
   
   /*
  @@ -605,8 +606,8 @@
       for (i = 0; i < lock_count; i++) {
           lock_fname = expand_lock_fname(p, i);
           unlink(lock_fname);
  -        ap_open(p, lock_fname, APR_CREATE | APR_WRITE | APR_EXCL,
  -                APR_UREAD | APR_UWRITE, &tempfile);
  +        ap_open(&tempfile, p, lock_fname, APR_CREATE | APR_WRITE | APR_EXCL,
  +                APR_UREAD | APR_UWRITE);
           ap_get_os_file(&lock_fd[i], tempfile);
           if (lock_fd[i] == -1) {
   	    ap_log_error(APLOG_MARK, APLOG_EMERG, 
  @@ -647,7 +648,7 @@
   
   static HMTX *lock_sem = NULL;
   
  -void accept_mutex_cleanup(void *foo)
  +ap_status_t accept_mutex_cleanup(void *foo)
   { 
       int i;
     
  @@ -726,7 +727,7 @@
   
   static int tpf_core_held;
   
  -static void accept_mutex_cleanup(void *foo)
  +static ap_status_t accept_mutex_cleanup(void *foo)
   {
       if(tpf_core_held)
           coruc(RESOURCE_KEY);
  
  
  
  1.5       +4 -4      apache-2.0/src/modules/mpm/mpmt_pthread/acceptlock.h
  
  Index: acceptlock.h
  ===================================================================
  RCS file: /export/home/cvs/apache-2.0/src/modules/mpm/mpmt_pthread/acceptlock.h,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- acceptlock.h	1999/08/31 05:33:22	1.4
  +++ acceptlock.h	1999/10/10 17:08:07	1.5
  @@ -82,13 +82,13 @@
   #elif defined (USE_PTHREAD_SERIALIZED_ACCEPT)
   void accept_mutex_child_cleanup(void *);
   void accept_mutex_child_init(ap_context_t *);
  -void accept_mutex_cleanup(void *);
  +ap_status_t accept_mutex_cleanup(void *);
   void accept_mutex_init(ap_context_t *, int);
   void accept_mutex_on(int);
   void accept_mutex_off(int);
   
   #elif defined (USE_SYSVSEM_SERIALIZED_ACCEPT)
  -void accept_mutex_cleanup(void *);
  +ap_status_t accept_mutex_cleanup(void *);
   #define accept_mutex_child_init(x)
   void accept_mutex_init(ap_context_t *, int);
   void accept_mutex_on(int);
  @@ -101,14 +101,14 @@
   void accept_mutex_off(int);
   
   #elif defined(USE_FLOCK_SERIALIZED_ACCEPT)
  -void accept_mutex_cleanup(void *);
  +ap_status_t accept_mutex_cleanup(void *);
   void accept_mutex_child_init(ap_context_t *);
   void accept_mutex_init(ap_context_t *, int);
   void accept_mutex_on(int);
   void accept_mutex_off(int);
   
   #elif defined(USE_OS2SEM_SERIALIZED_ACCEPT)
  -void accept_mutex_cleanup(void *);
  +ap_status_t accept_mutex_cleanup(void *);
   void accept_mutex_child_init(ap_context_t *);
   void accept_mutex_init(ap_context_t *, int);
   void accept_mutex_on(int);
  
  
  
  1.36      +32 -25    apache-2.0/src/modules/mpm/mpmt_pthread/mpmt_pthread.c
  
  Index: mpmt_pthread.c
  ===================================================================
  RCS file: /export/home/cvs/apache-2.0/src/modules/mpm/mpmt_pthread/mpmt_pthread.c,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- mpmt_pthread.c	1999/10/07 20:48:13	1.35
  +++ mpmt_pthread.c	1999/10/10 17:08:07	1.36
  @@ -71,7 +71,6 @@
   #include "scoreboard.h" 
   #include "acceptlock.h"
   
  -#include <poll.h>
   #include <netinet/tcp.h> 
   #include <pthread.h>
   
  @@ -91,8 +90,8 @@
   API_VAR_EXPORT int ap_extended_status = 0;
   static int workers_may_exit = 0;
   static int requests_this_child;
  -static int num_listenfds = 0;
  -static struct pollfd *listenfds;
  +static int num_listensocks = 0;
  +static ap_socket_t **listensocks;
   
   /* The structure used to pass unique initialization info to each thread */
   typedef struct {
  @@ -776,11 +775,12 @@
   {
       pthread_mutex_lock(&pipe_of_death_mutex);
       if (!workers_may_exit) {
  -        int ret;
  +        ap_status_t ret;
           char pipe_read_char;
  +	int n=1;
   
  -        ret = read(listenfds[0].fd, &pipe_read_char, 1);
  -        if (ret == -1 && errno == EAGAIN) {
  +        ret = ap_recv(listensocks[0], &pipe_read_char, &n);
  +        if (ret == APR_EAGAIN) {
               /* It lost the lottery. It must continue to suffer
                * through a life of servitude. */
           }
  @@ -803,9 +803,10 @@
       ap_socket_t *csd = NULL;
       ap_context_t *ptrans;		/* Pool for per-transaction stuff */
       ap_socket_t *sd = NULL;
  -    int srv;
  +    int n;
       int curr_pollfd, last_pollfd = 0;
       int thesock;
  +    ap_pollfd_t *pollset;
   
       free(ti);
   
  @@ -815,6 +816,10 @@
       worker_thread_count++;
       pthread_mutex_unlock(&worker_thread_count_mutex);
   
  +    ap_setup_poll(&pollset, tpool, num_listensocks+1);
  +    for(n=0 ; n <= num_listensocks ; ++n)
  +	ap_add_poll_socket(pollset, listensocks[n], APR_POLLIN);
  +
       /* TODO: Switch to a system where threads reuse the results from earlier
          poll calls - manoj */
       while (!workers_may_exit) {
  @@ -830,9 +835,12 @@
           }
           SAFE_ACCEPT(accept_mutex_on(0));
           while (!workers_may_exit) {
  -            srv = poll(listenfds, num_listenfds + 1, -1);
  -            if (srv < 0) {
  -                if (errno == EINTR) {
  +	    ap_status_t ret;
  +	    ap_int16_t event;
  +
  +            ret = ap_poll(pollset, &n, -1);
  +            if (ret != APR_SUCCESS) {
  +                if (ret == APR_EINTR) {
                       continue;
                   }
   
  @@ -845,14 +853,15 @@
   
               if (workers_may_exit) break;
   
  -            if (listenfds[0].revents & POLLIN) {
  +	    ap_get_revents(pollset, listensocks[0], &event);
  +            if (event & APR_POLLIN) {
                   /* A process got a signal on the shutdown pipe. Check if we're
                    * the lucky process to die. */
                   check_pipe_of_death();
                   continue;
               }
   
  -            if (num_listenfds == 1) {
  +            if (num_listensocks == 1) {
                   sd = ap_listeners->sd;
                   goto got_fd;
               }
  @@ -861,13 +870,14 @@
                   curr_pollfd = last_pollfd;
                   do {
                       curr_pollfd++;
  -                    if (curr_pollfd > num_listenfds) {
  +                    if (curr_pollfd > num_listensocks) {
                           curr_pollfd = 1;
                       }
                       /* XXX: Should we check for POLLERR? */
  -                    if (listenfds[curr_pollfd].revents & POLLIN) {
  +		    ap_get_revents(pollset, listensocks[curr_pollfd], &event);
  +                    if (event & APR_POLLIN) {
                           last_pollfd = curr_pollfd;
  -                        ap_put_os_sock(&sd, &listenfds[curr_pollfd].fd, tpool);

  +			sd=listensocks[curr_pollfd];
                           goto got_fd;
                       }
                   } while (curr_pollfd != last_pollfd);
  @@ -944,15 +954,12 @@
       requests_this_child = ap_max_requests_per_child;
       
       /* Set up the pollfd array */
  -    listenfds = ap_palloc(pchild, sizeof(struct pollfd) * (num_listenfds + 1));
  -    listenfds[0].fd = pipe_of_death[0];
  -    listenfds[0].events = POLLIN;
  -    listenfds[0].revents = 0;
  -    for (lr = ap_listeners, i = 1; i <= num_listenfds; lr = lr->next, ++i) {
  -        ap_get_os_sock(lr->sd, &listenfds[i].fd);
  -        listenfds[i].events = POLLIN; /* should we add POLLPRI ?*/
  -        listenfds[i].revents = 0;
  -    }
  +    listensocks = ap_palloc(pchild,
  +			    sizeof(*listensocks) * (num_listensocks + 1));
  +    ap_create_tcp_socket(&listensocks[0], pchild);
  +    ap_put_os_sock(&listensocks[0], &pipe_of_death[0], pchild);
  +    for (lr = ap_listeners, i = 1; i <= num_listensocks; lr = lr->next, ++i)
  +	listensocks[i]=lr->sd;
   
       /* Setup worker threads */
   
  @@ -1303,7 +1310,7 @@
           exit(1);
       }
       server_conf = s;
  -    if ((num_listenfds = setup_listeners(server_conf)) < 1) {
  +    if ((num_listensocks = setup_listeners(server_conf)) < 1) {
           /* XXX: hey, what's the right way for the mpm to indicate a fatal error? */
           ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, s,
               "no listening sockets available, shutting down");
  
  
  

Mime
View raw message