manoj       99/04/16 20:35:55

  Modified:    pthreads/src/include acceptlock.h http_accept.h
               pthreads/src/main Makefile.tmpl acceptlock.c
  Log:
  Add intraprocess support to the accept mutexes. This is needed by the
  USE_MULTI_ACCEPT model since threads within a process can compete with
  each other for the lock.
  
  Revision  Changes    Path
  1.4       +2 -1      apache-apr/pthreads/src/include/acceptlock.h
  
  Index: acceptlock.h
  ===================================================================
  RCS file: /home/cvs/apache-apr/pthreads/src/include/acceptlock.h,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -u -r1.3 -r1.4
  --- acceptlock.h      1999/04/14 22:44:55     1.3
  +++ acceptlock.h      1999/04/17 03:35:53     1.4
  @@ -79,12 +79,13 @@
   
   #elif defined (USE_SYSVSEM_SERIALIZED_ACCEPT)
   void accept_mutex_cleanup(void *);
  +void accept_mutex_child_init(pool *);
   void accept_mutex_init(pool *, int);
   void accept_mutex_on(int);
   void accept_mutex_off(int);
   
   #elif defined(USE_FCNTL_SERIALIZED_ACCEPT)
  -#define accept_mutex_child_init(x)
  +void accept_mutex_child_init(pool *);
   void accept_mutex_init(pool *, int);
   void accept_mutex_on(int);
   void accept_mutex_off(int);
  
  
  
  1.5       +4 -0      apache-apr/pthreads/src/include/http_accept.h
  
  Index: http_accept.h
  ===================================================================
  RCS file: /home/cvs/apache-apr/pthreads/src/include/http_accept.h,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -u -r1.4 -r1.5
  --- http_accept.h     1999/04/14 22:44:55     1.4
  +++ http_accept.h     1999/04/17 03:35:53     1.5
  @@ -85,6 +85,10 @@
   int  get_connection(struct sockaddr *);
   void stop_accepting_connections(pool*);
   
  +#ifdef USE_MULTI_ACCEPT
  +#define NEED_INTRAPROCESS_SERIALIZED_ACCEPT
  +#endif
  +
   #ifdef __cplusplus
   }
   #endif
  
  
  
  1.8       +2 -1      apache-apr/pthreads/src/main/Makefile.tmpl
  
  Index: Makefile.tmpl
  ===================================================================
  RCS file: /home/cvs/apache-apr/pthreads/src/main/Makefile.tmpl,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -u -r1.7 -r1.8
  --- Makefile.tmpl     1999/04/07 22:52:17     1.7
  +++ Makefile.tmpl     1999/04/17 03:35:54     1.8
  @@ -66,7 +66,8 @@
    $(INCDIR)/http_config.h $(INCDIR)/http_protocol.h \
    $(INCDIR)/http_request.h $(INCDIR)/http_conf_globals.h \
    $(INCDIR)/http_core.h $(INCDIR)/http_vhost.h \
  - $(INCDIR)/util_script.h $(INCDIR)/fdqueue.h $(INCDIR)/acceptlock.h
  + $(INCDIR)/util_script.h $(INCDIR)/fdqueue.h $(INCDIR)/acceptlock.h \
  + $(INCDIR)/http_accept.h
   alloc.o: alloc.c $(INCDIR)/httpd.h $(INCDIR)/ap_config.h \
    $(INCDIR)/ap_mmn.h $(INCDIR)/ap_config_auto.h $(OSDIR)/os.h \
    $(OSDIR)/os-inline.c $(INCDIR)/ap_ctype.h $(INCDIR)/hsregex.h \
  
  
  
  1.7       +69 -2     apache-apr/pthreads/src/main/acceptlock.c
  
  Index: acceptlock.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/pthreads/src/main/acceptlock.c,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -u -r1.6 -r1.7
  --- acceptlock.c      1999/04/16 04:43:01     1.6
  +++ acceptlock.c      1999/04/17 03:35:54     1.7
  @@ -68,6 +68,7 @@
   #include "util_uri.h" 
   #include "fdqueue.h"
   #include "acceptlock.h"
  +#include "http_accept.h"
   #include <netinet/tcp.h> 
   #include <stdio.h> 
   
  @@ -82,6 +83,56 @@
   /* Number of cross-process locks we're managing */
   static int lock_count;
   
  +/* Intraprocess locking used by other serialization techniques */
  +#ifdef NEED_INTRAPROCESS_SERIALIZED_ACCEPT
  +static pthread_mutex_t *intra_mutex = NULL;
  +
  +static void intra_mutex_cleanup(void *foo)
  +{
  +    int i;
  +
  +    for (i = 0; i < lock_count; i++) {
  +        (void) pthread_mutex_destroy(&intra_mutex[i]);
  +    }
  +}
  +
  +static void intra_mutex_init(pool *p)
  +{
  +    int i;
  +
  +    intra_mutex = (pthread_mutex_t *)ap_palloc(p, lock_count * 
sizeof(pthread_mutex_t ));
  +    for (i = 0; i < lock_count; i++) {
  +        if (pthread_mutex_init(&intra_mutex[i], NULL) != 0) {
  +            perror("intra_mutex_init");
  +         clean_child_exit(APEXIT_CHILDFATAL);
  +        }
  +    }
  +    ap_register_cleanup(p, NULL, intra_mutex_cleanup, ap_null_cleanup);
  +}
  +
  +static void intra_mutex_on(int locknum)
  +{
  +    if ((errno = pthread_mutex_lock(&intra_mutex[locknum])) != 0) {
  +        ap_log_error(APLOG_MARK, APLOG_EMERG, 
  +                  (const server_rec *) ap_get_server_conf(),
  +                  "Error getting intraprocess lock. Exiting!");
  +    }
  +}
  +
  +static void intra_mutex_off(int locknum)
  +{
  +    if (pthread_mutex_unlock(&intra_mutex[locknum]) != 0) {
  +        ap_log_error(APLOG_MARK, APLOG_EMERG, 
  +                  (const server_rec *) ap_get_server_conf(),
  +                  "Error releasing intraprocess lock. Exiting!");
  +    }
  +}
  +#else /* NEED_INTRAPROCESS_SERIALIZED_ACCEPT */
  +#define intra_mutex_init(x)
  +#define intra_mutex_on(x)
  +#define intra_mutex_off(x)
  +#endif /* NEED_INTRAPROCESS_SERIALIZED_ACCEPT */
  +
   #if defined(USE_FCNTL_SERIALIZED_ACCEPT) || 
defined(USE_FLOCK_SERIALIZED_ACCEPT)
   static void init_lock_fname(pool *p)
   {
  @@ -97,6 +148,7 @@
   #endif
   
   #if defined (USE_USLOCK_SERIALIZED_ACCEPT)
  +/* XXX - Don't know if we need the intraprocess locks here */
   
   #include <ulocks.h>
   
  @@ -402,8 +454,14 @@
       }
   }
   
  +void accept_mutex_child_init(pool *p)
  +{
  +    intra_mutex_init(p);
  +}
  +
   void accept_mutex_on(int locknum)
   {
  +    intra_mutex_on(locknum);
       if (semop(sem_id[locknum], &op_on, 1) < 0) {
        perror("accept_mutex_on");
        clean_child_exit(APEXIT_CHILDFATAL);
  @@ -416,6 +474,7 @@
        perror("accept_mutex_off");
        clean_child_exit(APEXIT_CHILDFATAL);
       }
  +    intra_mutex_off(locknum);
   }
   
   #elif defined(USE_FCNTL_SERIALIZED_ACCEPT)
  @@ -424,8 +483,6 @@
   
   static int *lock_fd = NULL;
   
  -
  -
   /*
    * Initialize mutex lock.
    * Must be safe to call this on a restart.
  @@ -462,10 +519,16 @@
       }
   }
   
  +void accept_mutex_child_init(pool *p)
  +{
  +    intra_mutex_init(p);
  +}
  +
   void accept_mutex_on(int locknum)
   {
       int ret;
   
  +    intra_mutex_on(locknum);
       while ((ret = fcntl(lock_fd[locknum], F_SETLKW, &lock_it)) < 0 && 
           errno != EINTR) {
        /* nop */
  @@ -495,6 +558,7 @@
                    "your lock file on a local disk!");
        clean_child_exit(APEXIT_CHILDFATAL);
       }
  +    intra_mutex_off(locknum);
   }
   
   #elif defined(USE_FLOCK_SERIALIZED_ACCEPT)
  @@ -520,6 +584,7 @@
   {
       int i;
     
  +    intra_mutex_init(p);
       for (i = 0; i < lock_count; i++) {
           char *lock_fname = expand_lock_fname(p, i);
       
  @@ -564,6 +629,7 @@
   {
       int ret;
   
  +    intra_mutex_on(locknum);
       while ((ret = flock(lock_fd[locknum], LOCK_EX)) < 0 && errno != EINTR)
           continue;
   
  @@ -583,6 +649,7 @@
                     "flock: LOCK_UN: Error freeing accept lock. Exiting!");
        clean_child_exit(APEXIT_CHILDFATAL);
       }
  +    intra_mutex_off(locknum);
   }
   
   #elif defined(USE_OS2SEM_SERIALIZED_ACCEPT)
  
  
  

Reply via email to