You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by rb...@hyperreal.org on 1999/05/17 15:11:52 UTC

cvs commit: apache-apr/apr/threadproc/unix thread.c

rbb         99/05/17 06:11:52

  Modified:    docs     time.txt
               apr      configure.in
               apr/locks/unix crossproc.c intraproc.c locks.c locks.h
               apr/test Makefile.in
               apr/threadproc/unix thread.c
  Added:       apr/test testthread.c
  Log:
  Test program for locks and threads.  Definately not a comprehensive test,
  but a good start.  This also fixes some major bugs in the locking and thread
  code.
  
  Revision  Changes    Path
  1.3       +145 -13   apache-apr/docs/time.txt
  
  Index: time.txt
  ===================================================================
  RCS file: /home/cvs/apache-apr/docs/time.txt,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- time.txt	1999/05/10 14:36:18	1.2
  +++ time.txt	1999/05/17 13:11:47	1.3
  @@ -5,29 +5,161 @@
   	am using seconds instead of milliseconds, because HTTP says we only
   	need second granularity, if this is not granular enough, it is easy to
   	change later.
  - APRStatus ap_current_time(APRTime *)
  +
  + ap_time_t *ap_make_time(ap_context_t *)
  +        Make a variable to store time.
  +     Arguments:
  +        arg 1)  Context to operate on.
  +        return) The new time structure.
  +
  + ap_statu_t *ap_current_time(ap_context_t *, ap_time_t *)
   	Returns the number of seconds since the epoch.  define the epoch
   	as midnight January 1, 1970, UTC.
  +     Arguments:
  +        arg 1)  The context to operate on
  +        arg 2)  The time strcuture to store the time to.
  +	return) current time on local machine.  NULL on error.
  + 
  + ap_status_t ap_explode_time(ap_context_t *, ap_time_t *, ap_timetype_e);
  +	Convert ap_time_t value into an expanded time format.
  +     Arguments:
  +	arg 1)  The context to operate on.
  +	arg 2)  The time to convert.
  +	arg 3)  The function to use to convert the time.
  +        return) APR_SUCCESS or APR_FAILURE.
  +
  + ap_int32_t ap_get_sec(ap_context_t *, ap_time_t *)
  +        Get the number of seconds into the minute [0,61]
  +     Arguments:
  +        arg 1)  The context to operate on.
  +        arg 2)  The The time value.
  +        return) The number of seconds.
  +NOTE:  ap_explode time MUST be called before this.
  +
  + ap_int32_t ap_get_min(ap_context_t *, ap_time_t *)
  +        Get the number of minutes into the hour [0,59]
  +     Arguments:
  +        arg 1)  The context to operate on.
  +        arg 2)  The The time value.
  +        return) The number of minute.
  +NOTE:  ap_explode time MUST be called before this.
  +
  + ap_int32_t ap_get_hour(ap_context_t *, ap_time_t *)
  +        Get the number of hours into the day [0,23]
  +     Arguments:
  +        arg 1)  The context to operate on.
  +        arg 2)  The The time value.
  +        return) The number of hours.
  +NOTE:  ap_explode time MUST be called before this.
  +
  + ap_int32_t ap_get_mday(ap_context_t *, ap_time_t *)
  +        Get the number of days into the month [1,31]
  +     Arguments:
  +        arg 1)  The context to operate on.
  +        arg 2)  The The time value.
  +        return) The number of days.
  +NOTE:  ap_explode time MUST be called before this.
  +
  + ap_int32_t ap_get_mon(ap_context_t *, ap_time_t *)
  +        Get the number of months into the year [0,11]
  +     Arguments:
  +        arg 1)  The context to operate on.
  +        arg 2)  The The time value.
  +        return) The number of monthss.
  +NOTE:  ap_explode time MUST be called before this.
  +
  + ap_int32_t ap_get_year(ap_context_t *, ap_time_t *)
  +        Get the number of years since 1900 
  +     Arguments:
  +        arg 1)  The context to operate on.
  +        arg 2)  The The time value.
  +        return) The number of years.
  +NOTE:  ap_explode time MUST be called before this.
  +
  + ap_int32_t ap_get_wday(ap_context_t *, ap_time_t *)
  +        Get the number of days since Sunday [0, 6] 
        Arguments:
  -	arg 1) current time on local machine.
  - APRStatus ap_implode_time(const APRExplodedTime *, APRTime)
  +        arg 1)  The context to operate on.
  +        arg 2)  The The time value.
  +        return) The number of days.
  +NOTE:  ap_explode time MUST be called before this.
  +
  + void ap_set_sec(ap_context_t *, ap_time_t *, ap_int32_t)
  +        Set the number of seconds into the minute [0,61]
  +     Arguments:
  +        arg 1)  The context to operate on.
  +        arg 2)  The The time value.
  +        return) The number of seconds.
  +NOTE:  ap_explode time MUST be called before this.
  +
  + void ap_set_min(ap_context_t *, ap_time_t *, ap_int32_t)
  +        Set the number of minutes into the hour [0,59]
  +     Arguments:
  +        arg 1)  The context to operate on.
  +        arg 2)  The The time value.
  +        return) The number of minute.
  +NOTE:  ap_explode time MUST be called before this.
  +
  + void ap_set_hour(ap_context_t *, ap_time_t *, ap_int32_t)
  +        Set the number of hours into the day [0,23]
  +     Arguments:
  +        arg 1)  The context to operate on.
  +        arg 2)  The The time value.
  +        return) The number of hours.
  +NOTE:  ap_explode time MUST be called before this.
  +
  + void ap_set_mday(ap_context_t *, ap_time_t *, ap_int32_t)
  +        Set the number of days into the month [1,31]
  +     Arguments:
  +        arg 1)  The context to operate on.
  +        arg 2)  The The time value.
  +        return) The number of days.
  +NOTE:  ap_explode time MUST be called before this.
  +
  + void ap_set_mon(ap_context_t *, ap_time_t *, ap_int32_t)
  +        Set the number of months into the year [0,11]
  +     Arguments:
  +        arg 1)  The context to operate on.
  +        arg 2)  The The time value.
  +        return) The number of monthss.
  +NOTE:  ap_explode time MUST be called before this.
  +
  + void ap_set_year(ap_context_t *, ap_time_t *, ap_int32_t)
  +        Set the number of years since 1900 
  +     Arguments:
  +        arg 1)  The context to operate on.
  +        arg 2)  The The time value.
  +        return) The number of years.
  +NOTE:  ap_explode time MUST be called before this.
  +
  + void ap_set_wday(ap_context_t *, ap_time_t *, ap_int32_t)
  +        Set the number of days since Sunday [0, 6] 
  +     Arguments:
  +        arg 1)  The context to operate on.
  +        arg 2)  The The time value.
  +        return) The number of days.
  +NOTE:  ap_explode time MUST be called before this.
  +
  +  ap_int64_t ap_get_curtime(ap_context_t *, ap_time_t *)
  +        Get the number of seconds since Jan 1 1970 (UTC)
  +     Arguments:
  +        arg 1)  context to operate on
  +        arg 2)  variable time is stored in.
  +        return) Number of seconds since epoch.
  +
  +  ap_status_t ap_implode_time(ap_context_t *, ap_time_t *)
   	Convert exploded time format into an APRTime value.
        Arguments:
  -	arg 1)  Time to convert in Exploded format
  -	arg 2)  converted time as seconds since epoch
  +	arg 1)  context to operate on 
  +	arg 2)  abstracted time structure.
  +        return) APR_SUCCESS or APR_FAILURE 
  +
    APRStatus ap_format_time(char *, APRUInt32, char *, APRExplodedTime,
   			   APRUInt32);
   	Format time into a buffer.
        Arguments:
   	arg 1)  Buffer to store string into
   	arg 2)  size of buffer.  Truncate if buffer not long enough
  -	arg 3)	format to convert to.  Use strftime formats (see posix 
  -		reference above)
  +	arg 3)	format to convert to.  Use strftime format
   	arg 4)  Time variable to convert
   	arg 5)  number of bytes of buffer used.
  - APRStatus ap_explode_time(APRTime, APRTimePARAMFN, APRExplodedTime);
  -	Convert APRTime vlaue into an expanded time format.
  -     Arguments:
  -	arg 1)  number of seconds since the epoch to convert to Expanded time
  -	arg 2)  Time parameter function of the specified time zone.
  -	arg 3)  structure to store expanded time into
  
  
  
  1.11      +1 -0      apache-apr/apr/configure.in
  
  Index: configure.in
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/configure.in,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- configure.in	1999/05/16 13:29:13	1.10
  +++ configure.in	1999/05/17 13:11:48	1.11
  @@ -22,6 +22,7 @@
   if (echo "$SYS_SW" | grep -qi 'Linux'); then
       SYS_KV=`echo $SYS_REL | awk -F. '{printf "%s%s", $1, $2}'`
       LDLIBS="$LDLIBS -ldl"
  +    CFLAGS="$CFLAGS -DUSE_PTHREAD_SERIALIZE -DUSE_FCNTL_SERIALIZE"
       PLATFORM="-DLINUX=$SYS_KV"
       OSDIR="unix"
       case "$SYS_KV" in
  
  
  
  1.2       +38 -35    apache-apr/apr/locks/unix/crossproc.c
  
  Index: crossproc.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/locks/unix/crossproc.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- crossproc.c	1999/05/10 17:57:53	1.1
  +++ crossproc.c	1999/05/17 13:11:49	1.2
  @@ -56,9 +56,12 @@
   #include "apr_lock.h"
   #include "apr_general.h"
   #include "locks.h"
  +#include <fcntlbits.h>
  +#include <unistd.h>
  +#include <sys/mman.h>
   
   #if defined (USE_SYSVSEM_SERIALIZE)  
  -ap_status_t lock_cleanup(ap_lock_t *lock)
  +ap_status_t lock_cleanup(struct lock_t *lock)
   {
       union semun ick;
       if (lock->curr_locked == 1) {
  @@ -68,7 +71,7 @@
       return APR_SUCCESS;
   }    
   
  -ap_status_t create_inter_lock(ap_context_t *cont, ap_lock_t *new)
  +ap_status_t create_inter_lock(ap_context_t *cont, struct lock_t *new)
   {
       union semun ick;
       struct semid_ds buf;
  @@ -76,12 +79,12 @@
       new->interproc = semget(IPC_PRIVATE, 1, IPC_CREATE | 0600);
   
       if (new->interproc < 0) {
  -        lock_cleanup(cont, new);
  +        lock_cleanup(new);
           return APR_FAILURE;
       }
       ick.val = 1;
       if (senctl(new->interproc, 0, SETVAL, ick) < 0) {
  -        lock_cleanup(cont, new);
  +        lock_cleanup(new);
           return APR_FAILURE;
       }
               /* pre-initialize these */
  @@ -97,7 +100,7 @@
       return APR_SUCCESS;
   }
   
  -ap_status_t lock_inter(ap_context_t *cont, ap_lock_t *lock)
  +ap_status_t lock_inter(ap_context_t *cont, struct lock_t *lock)
   {
       new->curr_locked == 1;
       if (semop(lock->interproc, &lock->op_on, 1) < 0) {
  @@ -106,7 +109,7 @@
       return APR_SUCCESS;
   }
   
  -ap_status_t unlock_inter(ap_context_t *cont, ap_lock_t *lock)
  +ap_status_t unlock_inter(ap_context_t *cont, struct lock_t *lock)
   {
       if (semop(lock->interproc, &lock->op_off, 1) < 0) {
           return(APR_FAILURE);
  @@ -115,7 +118,7 @@
       return APR_SUCCESS;
   }
   
  -ap_status_t destroy_inter_lock(ap_context_t *cont, ap_lock_t *lock)
  +ap_status_t destroy_inter_lock(ap_context_t *cont, struct lock_t *lock)
   {
       if (lock_cleanup(lock) == APR_SUCCESS) {
           ap_kill_cleanup(cont->pool, lock, lock_cleanup);
  @@ -123,25 +126,25 @@
       }
       return APR_FAILURE;
   }
  -#elif defined (USE_PTHREAD_SERIALIZE)  
  +#elif defined (USE_PROC_PTHREAD_SERIALIZE)  
   
  -ap_status_t lock_cleanup(ap_lock_t *lock)
  +ap_status_t lock_cleanup(struct lock_t *lock)
   {
       if (lock->curr_locked == 1) {
           if (pthread_mutex_unlock(lock->interproc)) {
               return APR_FAILURE;
           } 
  -        if (munmap((caddr_t)lock->interproc, sizeof(pthread_mutex_t)){
  +        if (munmap((caddr_t)lock->interproc, sizeof(pthread_mutex_t))){
               return APR_FAILURE;
           }
       }
       return APR_SUCCESS;
   }    
   
  -ap_status_t create_inter_lock(ap_context_t *cont, ap_lock_t *new)
  +ap_status_t create_inter_lock(ap_context_t *cont, struct lock_t *new)
   {
       int fd;
  -    pthread_mutex_attr_t mattr;
  +    pthread_mutexattr_t mattr;
   
       fd = open("/dev/zero", O_RDWR);
       if (fd < 0) {
  @@ -156,22 +159,22 @@
       }
       close(fd);
       if ((errno = pthread_mutexattr_init(&mattr))) {
  -        lock_cleanup(cont, new);
  +        lock_cleanup(new);
           return APR_FAILURE;
       }
       if ((errno = pthread_mutexattr_setpshared(&mattr, 
                                                 PTHREAD_PROCESS_SHARED))) {
  -        lock_cleanup(cont, new);
  +        lock_cleanup(new);
           return APR_FAILURE;
       }
   
       if ((errno = pthread_mutex_init(new->interproc, &mattr))) {
  -        lock_cleanup(cont, new);
  +        lock_cleanup(new);
           return APR_FAILURE;
       }
   
       if ((errno = pthread_mutex_destroy(&mattr))) {
  -        lock_cleanup(cont, new);
  +        lock_cleanup(new);
           return APR_FAILURE;
       }
   
  @@ -180,7 +183,7 @@
       return APR_SUCCESS;
   }
   
  -ap_status_t lock_inter(ap_context_t *cont, ap_lock_t *lock)
  +ap_status_t lock_inter(ap_context_t *cont, struct lock_t *lock)
   {
       new->curr_locked == 1;
       if (errno = pthread_mutex_lock(lock->interproc)) {
  @@ -189,7 +192,7 @@
       return APR_SUCCESS;
   }
   
  -ap_status_t unlock_inter(ap_context_t *cont, ap_lock_t *lock)
  +ap_status_t unlock_inter(ap_context_t *cont, struct lock_t *lock)
   {
       if (errno = pthread_mutex_unlock(lock->interproc)) {
           return(APR_FAILURE);
  @@ -198,7 +201,7 @@
       return APR_SUCCESS;
   }
   
  -ap_status_t destroy_inter_lock(ap_context_t *cont, ap_lock_t *lock)
  +ap_status_t destroy_inter_lock(ap_context_t *cont, struct lock_t *lock)
   {
       if (lock_cleanup(lock) == APR_SUCCESS) {
           ap_kill_cleanup(cont->pool, lock, lock_cleanup);
  @@ -209,23 +212,23 @@
   
   #elif defined (USE_FCNTL_SERIALIZE)  
   
  -ap_status_t lock_cleanup(ap_lock_t *lock)
  +ap_status_t lock_cleanup(struct lock_t *lock)
   {
       if (lock->curr_locked == 1) {
           if (fcntl(lock->interproc, F_SETLKW, &lock->unlock_it) < 0) {
               return(APR_FAILURE);
           }
  -        new->curr_locked == 0;
  +        lock->curr_locked == 0;
       }
       return APR_SUCCESS;
   }    
   
  -ap_status_t create_inter_lock(ap_context_t *cont, ap_lock_t *new)
  +ap_status_t create_inter_lock(ap_context_t *cont, struct lock_t *new)
   {
  -    new->interproc = open(new->fname, O_CREATE | O_WRONLY | O_EXCL, 0644);
  +    new->interproc = open(new->fname, O_CREAT | O_WRONLY | O_EXCL, 0644);
   
       if (new->interproc < 0) {
  -        lock_cleanup(cont, new);
  +        lock_cleanup(new);
           return APR_FAILURE;
       }
               /* pre-initialize these */
  @@ -246,25 +249,25 @@
       return APR_SUCCESS; 
   }
   
  -ap_status_t lock_inter(ap_context_t *cont, ap_lock_t *lock)
  +ap_status_t lock_inter(ap_context_t *cont, struct lock_t *lock)
   {
  -    new->curr_locked == 1;
  +    lock->curr_locked == 1;
       if (fcntl(lock->interproc, F_SETLKW, &lock->lock_it) < 0) {
           return(APR_FAILURE);
       }
       return APR_SUCCESS;
   }
   
  -ap_status_t unlock_inter(ap_context_t *cont, ap_lock_t *lock)
  +ap_status_t unlock_inter(ap_context_t *cont, struct lock_t *lock)
   {
       if (fcntl(lock->interproc, F_SETLKW, &lock->unlock_it) < 0) {
           return(APR_FAILURE);
       }
  -    new->curr_locked == 0;
  +    lock->curr_locked == 0;
       return APR_SUCCESS;
   }
   
  -ap_status_t destroy_inter_lock(ap_context_t *cont, ap_lock_t *lock)
  +ap_status_t destroy_inter_lock(ap_context_t *cont, struct lock_t *lock)
   {
       if (lock_cleanup(lock) == APR_SUCCESS) {
           ap_kill_cleanup(cont->pool, lock, lock_cleanup);
  @@ -273,7 +276,7 @@
       return APR_FAILURE;
   }
   #elif defined (USE_FLOCK_SERIALIZE)
  -ap_status_t lock_cleanup(ap_lock_t *lock)
  +ap_status_t lock_cleanup(struct lock_t *lock)
   {
       if (lock->curr_locked == 1) {
           if (flock(lock->interproc, LOCK_UN) < 0) {
  @@ -285,12 +288,12 @@
       return APR_SUCCESS;
   }    
   
  -ap_status_t create_inter_lock(ap_context_t *cont, ap_lock_t *new)
  +ap_status_t create_inter_lock(ap_context_t *cont, struct lock_t *new)
   {
       new->interproc = open(new->fname, O_CREAT | O_WRONLY | O_EXCL, 0600);
   
       if (new->interproc < 0) {
  -        lock_cleanup(cont, new);
  +        lock_cleanup(new);
           return APR_FAILURE;
       }
       new->curr_locked == 0;
  @@ -298,7 +301,7 @@
       return APR_SUCCESS;
   }
   
  -ap_status_t lock_inter(ap_context_t *cont, ap_lock_t *lock)
  +ap_status_t lock_inter(ap_context_t *cont, struct lock_t *lock)
   {
       new->curr_locked == 1;
       if (flock(lock->interproc, LOCK_EX) < 0) {
  @@ -307,7 +310,7 @@
       return APR_SUCCESS;
   }
   
  -ap_status_t unlock_inter(ap_context_t *cont, ap_lock_t *lock)
  +ap_status_t unlock_inter(ap_context_t *cont, struct lock_t *lock)
   {
       if (flock(lock->interproc, LOCK_UN) < 0) {
           return(APR_FAILURE);
  @@ -316,7 +319,7 @@
       return APR_SUCCESS;
   }
   
  -ap_status_t destroy_inter_lock(ap_context_t *cont, ap_lock_t *lock)
  +ap_status_t destroy_inter_lock(ap_context_t *cont, struct lock_t *lock)
   {
       if (lock_cleanup(lock) == APR_SUCCESS) {
           ap_kill_cleanup(cont->pool, lock, lock_cleanup);
  
  
  
  1.2       +22 -28    apache-apr/apr/locks/unix/intraproc.c
  
  Index: intraproc.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/locks/unix/intraproc.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- intraproc.c	1999/05/10 17:57:53	1.1
  +++ intraproc.c	1999/05/17 13:11:49	1.2
  @@ -56,77 +56,71 @@
   #include "apr_lock.h"
   #include "apr_general.h"
   #include "locks.h"
  +#include <fcntlbits.h>
   
   #if defined (USE_PTHREAD_SERIALIZE)  
   
  -ap_status_t lock_cleanup(ap_lock_t *lock)
  +ap_status_t lock_intra_cleanup(struct lock_t *lock)
   {
       if (lock->curr_locked == 1) {
  -        if (pthread_mutex_unlock(lock->interproc)) {
  +        if (pthread_mutex_unlock(lock->intraproc)) {
               return APR_FAILURE;
           } 
       }
       return APR_SUCCESS;
   }    
   
  -ap_status_t create_inter_lock(ap_context_t *cont, ap_lock_t *new)
  +ap_status_t create_intra_lock(ap_context_t *cont, struct lock_t *new)
   {
  -    int fd;
  -    pthread_mutex_attr_t mattr;
  +    pthread_mutexattr_t mattr;
   
  -    fd = open("/dev/zero", O_RDWR);
  -    if (fd < 0) {
  -        return APR_FAILURE;
  -    }
  -
  -    new->interproc = (pthread_mutex_t *)ap_palloc(cont->pool, 
  +    new->intraproc = (pthread_mutex_t *)ap_palloc(cont->pool, 
                                 sizeof(pthread_mutex_t));
  -    if (new->interproc = (void *) (caddr_t) -1) {
  +    if (new->intraproc == NULL ) {
           return APR_FAILURE;
       }
  -    close(fd);
       if ((errno = pthread_mutexattr_init(&mattr))) {
  -        lock_cleanup(cont, new);
  +        lock_intra_cleanup(new);
           return APR_FAILURE;
       }
   
  -    if ((errno = pthread_mutex_init(new->interproc, &mattr))) {
  -        lock_cleanup(cont, new);
  +    if ((errno = pthread_mutex_init(new->intraproc, &mattr))) {
  +        lock_intra_cleanup(new);
           return APR_FAILURE;
       }
   
  -    if ((errno = pthread_mutex_destroy(&mattr))) {
  -        lock_cleanup(cont, new);
  +    if ((errno = pthread_mutex_destroy(new->intraproc))) {
  +        lock_intra_cleanup(new);
           return APR_FAILURE;
       }
   
       new->curr_locked == 0;
  -    ap_register_cleanup(cont->pool, (void *)new, lock_cleanup, NULL);
  +    ap_register_cleanup(cont->pool, (void *)new, lock_intra_cleanup, NULL);
       return APR_SUCCESS;
   }
   
  -ap_status_t lock_inter(ap_context_t *cont, ap_lock_t *lock)
  +ap_status_t lock_intra(ap_context_t *cont, struct lock_t *lock)
   {
  -    new->curr_locked == 1;
  -    if (errno = pthread_mutex_lock(lock->interproc)) {
  +    lock->curr_locked == 1;
  +    if (errno = pthread_mutex_lock(lock->intraproc)) {
           return(APR_FAILURE);
       }
       return APR_SUCCESS;
   }
   
  -ap_status_t unlock_inter(ap_context_t *cont, ap_lock_t *lock)
  +ap_status_t unlock_intra(ap_context_t *cont, struct lock_t *lock)
   {
  -    if (errno = pthread_mutex_unlock(lock->interproc)) {
  +    if (errno = pthread_mutex_unlock(lock->intraproc)) {
           return(APR_FAILURE);
       }
  -    new->curr_locked == 0;
  +    lock->curr_locked == 0;
       return APR_SUCCESS;
   }
   
  -ap_status_t destroy_inter_lock(ap_context_t *cont, ap_lock_t *lock)
  +ap_status_t destroy_intra_lock(ap_context_t *cont, struct lock_t *lock)
   {
  -    if (lock_cleanup(lock) == APR_SUCCESS) {
  -        ap_kill_cleanup(cont->pool, lock, lock_cleanup);
  +    if (lock_intra_cleanup(lock) == APR_SUCCESS) {
  +        ap_kill_cleanup(cont->pool, lock, lock_intra_cleanup);
           return APR_SUCCESS;
       }
       return APR_FAILURE;
  
  
  
  1.2       +6 -7      apache-apr/apr/locks/unix/locks.c
  
  Index: locks.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/locks/unix/locks.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- locks.c	1999/05/10 17:57:53	1.1
  +++ locks.c	1999/05/17 13:11:49	1.2
  @@ -53,16 +53,15 @@
    *
    */
   
  -#include "apr_lock.h"
   #include "apr_general.h"
   #include "locks.h"
   #include <strings.h>
   
  -ap_lock_t *ap_create_lock(ap_context_t *cont, ap_locktype_e type, char *fname)
  +struct lock_t *ap_create_lock(ap_context_t *cont, ap_locktype_e type, char *fname)
   {
  -    ap_lock_t *new;
  +    struct lock_t *new;
   
  -    new = (ap_lock_t *)ap_palloc(cont->pool, sizeof(ap_lock_t));
  +    new = (struct lock_t *)ap_palloc(cont->pool, sizeof(struct lock_t));
   
       new->type = type;
       new->fname = strdup(fname);
  @@ -80,7 +79,7 @@
       return new;
   }
   
  -ap_status_t ap_lock(ap_context_t *cont, ap_lock_t *lock)
  +ap_status_t ap_lock(ap_context_t *cont, struct lock_t *lock)
   {
       if (lock->type != APR_CROSS_PROCESS) {
           if (lock_intra(cont, lock) == APR_FAILURE) {
  @@ -95,7 +94,7 @@
       return APR_SUCCESS;
   }
   
  -ap_status_t ap_unlock(ap_context_t *cont, ap_lock_t *lock)
  +ap_status_t ap_unlock(ap_context_t *cont, struct lock_t *lock)
   {
       if (lock->type != APR_CROSS_PROCESS) {
           if (unlock_intra(cont, lock) == APR_FAILURE) {
  @@ -110,7 +109,7 @@
       return APR_SUCCESS;
   }
   
  -ap_status_t ap_destroy_lock(ap_context_t *cont, ap_lock_t *lock)
  +ap_status_t ap_destroy_lock(ap_context_t *cont, struct lock_t *lock)
   {
       if (lock->type != APR_CROSS_PROCESS) {
           if (destroy_intra_lock(cont, lock) == APR_FAILURE) {
  
  
  
  1.3       +6 -1      apache-apr/apr/locks/unix/locks.h
  
  Index: locks.h
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/locks/unix/locks.h,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- locks.h	1999/05/12 12:01:10	1.2
  +++ locks.h	1999/05/17 13:11:49	1.3
  @@ -61,10 +61,13 @@
   #if defined (USE_USLOCK_SERIALIZE)
   #include <uslocks.h>
   #elif defined (USE_SYSVSEM_SERIALIZE)
  +#include <sys/file.h>
   #include <sys/types.h>
   #include <sys/ipc.h>
   #include <sys/sem.h>
   #endif
  +#include <fcntlbits.h>
  +#include <stdio.h>
   #include <pthread.h>
   
   #ifdef NEED_UNION_SEMUN
  @@ -88,14 +91,16 @@
       int interproc;
       struct flock lock_it;
       struct flock unlock_it;
  -#elif defined (USE_PTHREAD_MUTEX)
  +#elif defined (USE_PROC_PTHREAD_SERIALIZE)
       pthread_mutex_t *interproc;
   #elif defined (USE_FLOCK_SERIALIZE)
       int interproc;
   #else
       /* No Interprocess serialization.  Too bad. */
   #endif 
  +#if defined (USE_PTHREAD_SERIALIZE)
       pthread_mutex_t *intraproc;
  +#endif
       /* At some point, we should do a type for both inter and intra process
        *  locking here.  Something like pthread_mutex with PTHREAD_PROCESS_SHARED
        */    
  
  
  
  1.4       +7 -1      apache-apr/apr/test/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/test/Makefile.in,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Makefile.in	1999/05/16 13:29:14	1.3
  +++ Makefile.in	1999/05/17 13:11:51	1.4
  @@ -1,3 +1,4 @@
  +# Generated automatically from Makefile.in by configure.
   #CFLAGS=$(OPTIM) $(CFLAGS1) $(EXTRA_CFLAGS)
   #LIBS=$(EXTRA_LIBS) $(LIBS1)
   #INCLUDES=$(INCLUDES1) $(INCLUDES0) $(EXTRA_INCLUDES)
  @@ -6,7 +7,7 @@
   CC=gcc
   RANLIB=ranlib
   CFLAGS=-DLINUX=20 -g -O2 
  -LDLIBS= -ldl -lm -L../network_io -lnetwork -L../threadproc -lthreadproc -L../file_io -lfile -L../misc -lmisc -L../lib -lapr -L../time -ltime
  +LDLIBS= -ldl -lm -lpthread -L../network_io -lnetwork -L../threadproc -lthreadproc -L../file_io -lfile -L../misc -lmisc -L../lib -lapr -L../time -ltime -L../locks -llock
   LDFLAGS= $(LDLIBS)
   INCDIR=../../include
   INCDIR1=../../../include
  @@ -15,11 +16,13 @@
   TARGETS= testfile \
   	testproc \
   	testsock \
  +	testthread \
   	testtime
   
   OBJS= testfile.o \
   	testproc.o \
   	testsock.o \
  +	testthread.o \
   	testtime.o
   
   .c.o:
  @@ -32,6 +35,9 @@
   
   testproc: testproc.o
   	$(CC) $(CFLAGS) testproc.o -o testproc $(LDFLAGS)
  +
  +testthread: testthread.o
  +	$(CC) $(CFLAGS) testthread.o -o testthread $(LDFLAGS)
   
   testsock: testsock.o client.o server.o 
   	$(CC) $(CFLAGS) testsock.o -o testsock  $(LDFLAGS)
  
  
  
  1.1                  apache-apr/apr/test/testthread.c
  
  Index: testthread.c
  ===================================================================
  /* ====================================================================
   * Copyright (c) 1999 The Apache Group.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * 4. The names "Apache Server" and "Apache Group" must not be used to
   *    endorse or promote products derived from this software without
   *    prior written permission. For written permission, please contact
   *    apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Group.
   * For more information on the Apache Group and the Apache HTTP server
   * project, please see <http://www.apache.org/>.
   *
   */
  #include "apr_thread_proc.h"
  #include "apr_lock.h"
  #include "apr_errno.h"
  #include "apr_general.h"
  #include "errno.h"
  #include <stdio.h>
  #ifdef BEOS
  #include <unistd.h>
  #endif
  
  ap_lock_t *thread_lock;
  ap_context_t *context;
  int x = 0;
  
  void *thread_func1(void *data)
  {
      int i;
      for (i = 0; i < 10000; i++) {
          ap_lock(context, thread_lock);
          x++;
          ap_unlock(context, thread_lock);
      }
  } 
  
  void *thread_func2(void *data)
  {
      int i;
      for (i = 0; i < 10000; i++) {
          ap_lock(context, thread_lock);
          x++;
          ap_unlock(context, thread_lock);
      }
  } 
  
  void *thread_func3(void *data)
  {
      int i;
      for (i = 0; i < 10000; i++) {
          ap_lock(context, thread_lock);
          x++;
          ap_unlock(context, thread_lock);
      }
  } 
  
  void *thread_func4(void *data)
  {
      int i;
      for (i = 0; i < 10000; i++) {
          ap_lock(context, thread_lock);
          x++;
          ap_unlock(context, thread_lock);
      }
  } 
  
  int main()
  {
      ap_thread_t *t1;
      ap_thread_t *t2;
      ap_thread_t *t3;
      ap_thread_t *t4;
      ap_threadattr_t *tattr;
      ap_status_t st;
  
      fprintf(stdout, "Initializing the context......."); 
      context = ap_initialize(NULL);
      if (context == NULL) {
          fprintf(stderr, "could not initialize\n");
          exit(-1);
      }
      fprintf(stdout, "OK\n");
  
      fprintf(stdout, "Initializing the lock......."); 
      thread_lock = ap_create_lock(context, APR_INTRAPROCESS, "lock.file"); 
      if (thread_lock == NULL) {
          fprintf(stderr, "Could not create lock\n");
          exit(-1);
      }
      fprintf(stdout, "OK\n");
  
      fprintf(stdout, "Starting all the threads......."); 
      t1 = ap_create_thread(context, NULL, thread_func1, NULL);
      t2 = ap_create_thread(context, NULL, thread_func2, NULL);
      t3 = ap_create_thread(context, NULL, thread_func3, NULL);
      t4 = ap_create_thread(context, NULL, thread_func4, NULL);
      if (t1 == NULL || t2 == NULL || t3 == NULL || t4 == NULL) {
          fprintf(stderr, "Error starting thread\n");
          exit(-1);
      }
      fprintf(stdout, "OK\n");
  
      fprintf(stdout, "Waiting for threads to exit.......");
      ap_thread_join(context, t1, &st);
      ap_thread_join(context, t2, &st);
      ap_thread_join(context, t3, &st);
      ap_thread_join(context, t4, &st);
      fprintf (stdout, "OK\n");   
  
      fprintf(stdout, "Checking if locks worked......."); 
      if (x != 40000) {
          fprintf(stderr, "The locks didn't work????\n");
      }
      else {
          fprintf(stdout, "Everything is working!\n");
      }
  
      exit(1);
  }
  
  
  
  1.3       +10 -2     apache-apr/apr/threadproc/unix/thread.c
  
  Index: thread.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/threadproc/unix/thread.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- thread.c	1999/05/12 20:04:24	1.2
  +++ thread.c	1999/05/17 13:11:51	1.3
  @@ -90,10 +90,18 @@
   struct thread_t *ap_create_thread(ap_context_t *cont, struct threadattr_t *attr, ap_thread_start_t func, void *data)
   {
       struct thread_t *new;
  -
  +    pthread_attr_t *temp;
  + 
       new = (struct thread_t *)ap_palloc(cont->pool, sizeof(struct thread_t));
  +
  +    new->td = (pthread_t *)ap_palloc(cont->pool, sizeof(pthread_t));
  +
  +    if (attr)
  +        temp = attr->attr;
  +    else
  +        temp = NULL;
   
  -    if (pthread_create(new->td, attr->attr, func, data) == 0) {
  +    if (pthread_create(new->td, temp, func, data) == 0) {
           return new;
       }
       else {