httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@hyperreal.org
Subject cvs commit: apache-apr/pthreads/src/main acceptlock.c
Date Wed, 14 Apr 1999 06:26:13 GMT
manoj       99/04/13 23:26:12

  Modified:    pthreads/src/main acceptlock.c
  Log:
  Make USE_PTHREAD_SERIALIZED_ACCEPT functional. A few bugs are fixed, and
  mmap usage is optimized (I hope).
  
  Revision  Changes    Path
  1.4       +48 -44    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.3
  retrieving revision 1.4
  diff -u -u -r1.3 -r1.4
  --- acceptlock.c	1999/04/09 03:15:40	1.3
  +++ acceptlock.c	1999/04/14 06:26:12	1.4
  @@ -170,7 +170,7 @@
   
   #include <pthread.h>
   
  -static pthread_mutex_t **accept_mutex = (void *)(caddr_t) -1;
  +static pthread_mutex_t *accept_mutex = (void *)(caddr_t) -1;
   static int *have_accept_mutex;
   static sigset_t accept_block_mask;
   static sigset_t accept_previous_mask;
  @@ -179,10 +179,11 @@
   {
       int i;
      
  -    for (i = 0; i < ap_acceptors_per_child; i++) {
  -        if (accept_mutex[i] != (void *)(caddr_t)-1
  -	      && have_accept_mutex[i]) {
  -  	    pthread_mutex_unlock(accept_mutex[i]);
  +    if (accept_mutex != (void *)(caddr_t)-1) {
  +        for (i = 0; i < ap_acceptors_per_child; i++) {
  +	    if (have_accept_mutex[i]) {
  +  	        pthread_mutex_unlock(&accept_mutex[i]);
  +            }
   	}
       }
   }
  @@ -195,13 +196,12 @@
   {
       int i;
      
  -    for (i = 0; i < ap_acceptors_per_child; i++) {
  -        if (accept_mutex[i] != (void *)(caddr_t)-1
  -	      && munmap((caddr_t) accept_mutex[i], sizeof(pthread_mutex_t))) {
  -	    perror("munmap");
  -	}
  -	accept_mutex[i] = (void *)(caddr_t)-1;
  +    if (accept_mutex != (void *)(caddr_t)-1
  +        && munmap((caddr_t) accept_mutex,
  +                  sizeof(pthread_mutex_t) * ap_acceptors_per_child)) {
  +	perror("munmap");
       }
  +    accept_mutex = (void *)(caddr_t)-1;
   }
   
   void accept_mutex_init(pool *p)
  @@ -210,56 +210,60 @@
       int fd;
       int i;
      
  -    accept_mutex = (pthread_mutex_t *)ap_palloc(p, 
  -		    ap_acceptors_per_child * sizeof(pthread_mutex_t *));
       have_accept_mutex = (int *)ap_palloc(p, 
   		    ap_acceptors_per_child * sizeof(int));
   
  -
  +    fd = open("/dev/zero", O_RDWR);
  +    if (fd == -1) {
  +        perror("open(/dev/zero)");
  +        exit(APEXIT_INIT);
  +    }
  +    accept_mutex = (pthread_mutex_t *) mmap((caddr_t) 0, 
  +                           sizeof(pthread_mutex_t) * ap_acceptors_per_child, 
  +    			   PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  +    if (accept_mutex == (void *) (caddr_t) - 1) {
  +        perror("mmap");
  +        exit(APEXIT_INIT);
  +    }
  +    close(fd);
  +    if ((errno = pthread_mutexattr_init(&mattr))) {
  +        perror("pthread_mutexattr_init");
  +        exit(APEXIT_INIT);
  +    }
  +    if ((errno = pthread_mutexattr_setpshared(&mattr,
  +    					  PTHREAD_PROCESS_SHARED))) {
  +        perror("pthread_mutexattr_setpshared");
  +        exit(APEXIT_INIT);
  +    }
       for (i = 0; i < ap_acceptors_per_child; i++) {
  -        fd = open("/dev/zero", O_RDWR);
  -	if (fd == -1) {
  -	    perror("open(/dev/zero)");
  -	    exit(APEXIT_INIT);
  -	}
  -	accept_mutex[i] = (pthread_mutex_t *) mmap((caddr_t) 0, 
  -						   sizeof(*accept_mutex),
  -						   PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  -	if (accept_mutex[i] == (void *) (caddr_t) - 1) {
  -	    perror("mmap");
  -	    exit(APEXIT_INIT);
  -	}
  -	close(fd);
  -	if ((errno = pthread_mutexattr_init(&mattr))) {
  -	    perror("pthread_mutexattr_init");
  -	    exit(APEXIT_INIT);
  -	}
  -	if ((errno = pthread_mutexattr_setpshared(&mattr,
  -						  PTHREAD_PROCESS_SHARED))) {
  -	    perror("pthread_mutexattr_setpshared");
  -	    exit(APEXIT_INIT);
  -	}
  -	if ((errno = pthread_mutex_init(accept_mutex, &mattr))) {
  +	if ((errno = pthread_mutex_init(&accept_mutex[i], &mattr))) {
   	    perror("pthread_mutex_init");
   	    exit(APEXIT_INIT);
   	}
  -	sigfillset(&accept_block_mask);
  -	sigdelset(&accept_block_mask, SIGHUP);
  -	sigdelset(&accept_block_mask, SIGTERM);
  -	sigdelset(&accept_block_mask, SIGWINCH);
  -	ap_register_cleanup(p, NULL, accept_mutex_cleanup, ap_null_cleanup);
       }
  +    if ((errno = pthread_mutexattr_destroy(&mattr))) {
  +        perror("pthread_mutexattr_destroy");
  +        exit(APEXIT_INIT);
  +    }
  +    sigfillset(&accept_block_mask);
  +    sigdelset(&accept_block_mask, SIGHUP);
  +    sigdelset(&accept_block_mask, SIGTERM);
  +    sigdelset(&accept_block_mask, SIGWINCH);
  +    ap_register_cleanup(p, NULL, accept_mutex_cleanup, ap_null_cleanup);
   }
   
   void accept_mutex_on(int locknum)
   {
       int err;
   
  +    /* Already blocking out all signals in worker threads. */
  +#if 0
       if (sigprocmask(SIG_BLOCK, &accept_block_mask, &accept_previous_mask)) {
   	perror("sigprocmask(SIG_BLOCK)");
   	clean_child_exit(APEXIT_CHILDFATAL);
       }
  -    if ((err = pthread_mutex_lock(accept_mutex[locknum]))) {
  +#endif
  +    if ((err = pthread_mutex_lock(&accept_mutex[locknum]))) {
   	errno = err;
   	perror("pthread_mutex_lock");
   	clean_child_exit(APEXIT_CHILDFATAL);
  @@ -271,7 +275,7 @@
   {
       int err;
   
  -    if ((err = pthread_mutex_unlock(accept_mutex[locknum]))) {
  +    if ((err = pthread_mutex_unlock(&accept_mutex[locknum]))) {
   	errno = err;
   	perror("pthread_mutex_unlock");
   	clean_child_exit(APEXIT_CHILDFATAL);
  
  
  

Mime
View raw message