apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject cvs commit: apr/locks/unix crossproc.c intraproc.c locks.c
Date Mon, 25 Jun 2001 18:53:36 GMT
trawick     01/06/25 11:53:36

  Modified:    include/arch/unix locks.h
               locks/unix crossproc.c intraproc.c locks.c
  Log:
  Teach the Unix implementation of locks to:
  
  1) build in as many implementation mechanisms (e.g., fcntl(), flock()) as the
     platform supports
  2) use function pointers set up during apr_lock_create() processing to call the
     low-level routines
  
  Revision  Changes    Path
  1.31      +53 -23    apr/include/arch/unix/locks.h
  
  Index: locks.h
  ===================================================================
  RCS file: /home/cvs/apr/include/arch/unix/locks.h,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- locks.h	2001/06/06 18:11:28	1.30
  +++ locks.h	2001/06/25 18:53:34	1.31
  @@ -100,7 +100,51 @@
   #endif
   /* End System Headers */
   
  -#if !APR_HAVE_UNION_SEMUN && APR_USE_SYSVSEM_SERIALIZE
  +struct apr_unix_lock_methods_t {
  +    apr_status_t (*create)(apr_lock_t *, const char *);
  +    apr_status_t (*acquire)(apr_lock_t *);
  +    apr_status_t (*release)(apr_lock_t *);
  +    apr_status_t (*destroy)(apr_lock_t *);
  +    apr_status_t (*child_init)(apr_lock_t **, apr_pool_t *, const char *);
  +};
  +typedef struct apr_unix_lock_methods_t apr_unix_lock_methods_t;
  +
  +#if defined(HAVE_SEMCTL) && defined(HAVE_SEMGET)
  +#define APR_HAS_SYSVSEM_SERIALIZE      1
  +extern const apr_unix_lock_methods_t apr_unix_sysv_methods;
  +#else
  +#define APR_HAS_SYSVSEM_SERIALIZE      0
  +#endif
  +
  +#if defined(HAVE_FCNTL_H) && defined(HAVE_F_SETLK)
  +#define APR_HAS_FCNTL_SERIALIZE        1
  +extern const apr_unix_lock_methods_t apr_unix_fcntl_methods;
  +#else
  +#define APR_HAS_FCNTL_SERIALIZE        0
  +#endif
  +
  +#if defined(HAVE_SYS_FILE_H) && defined(HAVE_LOCK_EX)
  +#define APR_HAS_FLOCK_SERIALIZE        1
  +extern const apr_unix_lock_methods_t apr_unix_flock_methods;
  +#else
  +#define APR_HAS_FLOCK_SERIALIZE        0
  +#endif
  +
  +#if defined(HAVE_PTHREAD_H) && defined(HAVE_PTHREAD_PROCESS_SHARED) &&
defined(HAVE_PTHREAD_MUTEXATTR_SETPSHARED)
  +#define APR_HAS_PROC_PTHREAD_SERIALIZE 1
  +extern const apr_unix_lock_methods_t apr_unix_proc_pthread_methods;
  +#else
  +#define APR_HAS_PROC_PTHREAD_SERIALIZE 0
  +#endif
  +
  +#if defined(HAVE_PTHREAD_RWLOCK_INIT)
  +#define APR_HAS_RWLOCK_SERIALIZE       1
  +extern const apr_unix_lock_methods_t apr_unix_rwlock_methods;
  +#else
  +#define APR_HAS_RWLOCK_SERIALIZE       0
  +#endif
  +
  +#if !APR_HAVE_UNION_SEMUN && defined(APR_HAS_SYSVSEM_SERIALIZE)
   /* it makes no sense, but this isn't defined on solaris */
   union semun {
       long val;
  @@ -111,22 +155,18 @@
   
   struct apr_lock_t {
       apr_pool_t *pool;
  +    const apr_unix_lock_methods_t *meth;
  +    const apr_unix_lock_methods_t *inter_meth, *intra_meth; /* for APR_LOCK_ALL */
       apr_locktype_e type;
       apr_lockscope_e scope;
       int curr_locked;
       char *fname;
  -
  -#if APR_USE_SYSVSEM_SERIALIZE
  +#if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE
       int interproc;
  -#elif APR_USE_FCNTL_SERIALIZE
  -    int interproc;
  -#elif APR_USE_PROC_PTHREAD_SERIALIZE
  -    pthread_mutex_t *interproc;
  -#elif APR_USE_FLOCK_SERIALIZE
  -    int interproc;
  -#else
  -    /* No Interprocess serialization.  Too bad. */
  -#endif 
  +#endif
  +#if APR_HAS_PROC_PTHREAD_SERIALIZE
  +    pthread_mutex_t *pthread_interproc;
  +#endif
   #if APR_HAS_THREADS
       /* APR doesn't have threads, no sense in having an thread lock mechanism.
        */
  @@ -147,20 +187,10 @@
   };
   
   #if APR_HAS_THREADS
  -apr_status_t apr_unix_create_intra_lock(struct apr_lock_t *new);
  -apr_status_t apr_unix_lock_intra(struct apr_lock_t *lock);
  -apr_status_t apr_unix_unlock_intra(struct apr_lock_t *lock);
  -apr_status_t apr_unix_destroy_intra_lock(struct apr_lock_t *lock);
  +extern const apr_unix_lock_methods_t apr_unix_intra_methods;
   #endif
   
   void apr_unix_setup_lock(void);
  -apr_status_t apr_unix_create_inter_lock(struct apr_lock_t *new);
  -apr_status_t apr_unix_lock_inter(struct apr_lock_t *lock);
  -apr_status_t apr_unix_unlock_inter(struct apr_lock_t *lock);
  -apr_status_t apr_unix_destroy_inter_lock(struct apr_lock_t *lock);
  -
  -apr_status_t apr_unix_child_init_lock(struct apr_lock_t **lock, 
  -                                      apr_pool_t *cont, const char *fname);
   
   #endif  /* LOCKS_H */
   
  
  
  
  1.46      +131 -75   apr/locks/unix/crossproc.c
  
  Index: crossproc.c
  ===================================================================
  RCS file: /home/cvs/apr/locks/unix/crossproc.c,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- crossproc.c	2001/06/06 18:11:55	1.45
  +++ crossproc.c	2001/06/25 18:53:35	1.46
  @@ -57,12 +57,12 @@
   #include "locks.h"
   #include "fileio.h" /* for apr_mkstemp() */
   
  -#if APR_USE_SYSVSEM_SERIALIZE  
  +#if APR_HAS_SYSVSEM_SERIALIZE
   
   static struct sembuf op_on;
   static struct sembuf op_off;
   
  -void apr_unix_setup_lock(void)
  +static void sysv_setup(void)
   {
       op_on.sem_num = 0;
       op_on.sem_op = -1;
  @@ -72,7 +72,7 @@
       op_off.sem_flg = SEM_UNDO;
   }
   
  -static apr_status_t lock_cleanup(void *lock_)
  +static apr_status_t sysv_cleanup(void *lock_)
   {
       apr_lock_t *lock=lock_;
       union semun ick;
  @@ -84,28 +84,28 @@
       return APR_SUCCESS;
   }    
   
  -apr_status_t apr_unix_create_inter_lock(apr_lock_t *new)
  +static apr_status_t sysv_create(apr_lock_t *new, const char *fname)
   {
       union semun ick;
       
       new->interproc = semget(IPC_PRIVATE, 1, IPC_CREAT | 0600);
   
       if (new->interproc < 0) {
  -        lock_cleanup(new);
  +        sysv_cleanup(new);
           return errno;
       }
       ick.val = 1;
       if (semctl(new->interproc, 0, SETVAL, ick) < 0) {
  -        lock_cleanup(new);
  +        sysv_cleanup(new);
           return errno;
       }
       new->curr_locked = 0;
  -    apr_pool_cleanup_register(new->pool, (void *)new, lock_cleanup, 
  +    apr_pool_cleanup_register(new->pool, (void *)new, sysv_cleanup, 
                                 apr_pool_cleanup_null);
       return APR_SUCCESS;
   }
   
  -apr_status_t apr_unix_lock_inter(apr_lock_t *lock)
  +static apr_status_t sysv_acquire(apr_lock_t *lock)
   {
       int rc;
   
  @@ -119,7 +119,7 @@
       return APR_SUCCESS;
   }
   
  -apr_status_t apr_unix_unlock_inter(apr_lock_t *lock)
  +static apr_status_t sysv_release(apr_lock_t *lock)
   {
       int rc;
   
  @@ -133,48 +133,59 @@
       return APR_SUCCESS;
   }
   
  -apr_status_t apr_unix_destroy_inter_lock(apr_lock_t *lock)
  +static apr_status_t sysv_destroy(apr_lock_t *lock)
   {
       apr_status_t stat;
   
  -    if ((stat = lock_cleanup(lock)) == APR_SUCCESS) {
  -        apr_pool_cleanup_kill(lock->pool, lock, lock_cleanup);
  +    if ((stat = sysv_cleanup(lock)) == APR_SUCCESS) {
  +        apr_pool_cleanup_kill(lock->pool, lock, sysv_cleanup);
           return APR_SUCCESS;
       }
       return stat;
   }
   
  -apr_status_t apr_unix_child_init_lock(apr_lock_t **lock, apr_pool_t *cont, const char *fname)
  +static apr_status_t sysv_child_init(apr_lock_t **lock, apr_pool_t *cont, const char *fname)
   {
       return APR_SUCCESS;
   }
   
  -#elif (APR_USE_PROC_PTHREAD_SERIALIZE)  
  +const apr_unix_lock_methods_t apr_unix_sysv_methods =
  +{
  +    sysv_create,
  +    sysv_acquire,
  +    sysv_release,
  +    sysv_destroy,
  +    sysv_child_init
  +};
   
  -void apr_unix_setup_lock(void)
  +#endif /* SysV sem implementation */
  +
  +#if APR_HAS_PROC_PTHREAD_SERIALIZE
  +
  +static void proc_pthread_setup(void)
   {
   }
   
  -static apr_status_t lock_cleanup(void *lock_)
  +static apr_status_t proc_pthread_cleanup(void *lock_)
   {
       apr_lock_t *lock=lock_;
       apr_status_t stat;
   
       if (lock->curr_locked == 1) {
  -        if ((stat = pthread_mutex_unlock(lock->interproc))) {
  +        if ((stat = pthread_mutex_unlock(lock->pthread_interproc))) {
   #ifdef PTHREAD_SETS_ERRNO
               stat = errno;
   #endif
               return stat;
           } 
  -        if (munmap((caddr_t)lock->interproc, sizeof(pthread_mutex_t))){
  +        if (munmap((caddr_t)lock->pthread_interproc, sizeof(pthread_mutex_t))){
               return errno;
           }
       }
       return APR_SUCCESS;
   }    
   
  -apr_status_t apr_unix_create_inter_lock(apr_lock_t *new)
  +static apr_status_t proc_pthread_create(apr_lock_t *new, const char *fname)
   {
       apr_status_t stat;
       int fd;
  @@ -185,10 +196,10 @@
           return errno;
       }
   
  -    new->interproc = (pthread_mutex_t *)mmap((caddr_t) 0, 
  -                              sizeof(pthread_mutex_t), 
  -                              PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); 
  -    if (new->interproc == (pthread_mutex_t *) (caddr_t) -1) {
  +    new->pthread_interproc = (pthread_mutex_t *)mmap((caddr_t) 0, 
  +                                                     sizeof(pthread_mutex_t), 
  +                                                     PROT_READ | PROT_WRITE, MAP_SHARED,
fd, 0); 
  +    if (new->pthread_interproc == (pthread_mutex_t *) (caddr_t) -1) {
           return errno;
       }
       close(fd);
  @@ -196,22 +207,22 @@
   #ifdef PTHREAD_SETS_ERRNO
           stat = errno;
   #endif
  -        lock_cleanup(new);
  +        proc_pthread_cleanup(new);
           return stat;
       }
       if ((stat = pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED))) {
   #ifdef PTHREAD_SETS_ERRNO
           stat = errno;
   #endif
  -        lock_cleanup(new);
  +        proc_pthread_cleanup(new);
           return stat;
       }
   
  -    if ((stat = pthread_mutex_init(new->interproc, &mattr))) {
  +    if ((stat = pthread_mutex_init(new->pthread_interproc, &mattr))) {
   #ifdef PTHREAD_SETS_ERRNO
           stat = errno;
   #endif
  -        lock_cleanup(new);
  +        proc_pthread_cleanup(new);
           return stat;
       }
   
  @@ -219,21 +230,21 @@
   #ifdef PTHREAD_SETS_ERRNO
           stat = errno;
   #endif
  -        lock_cleanup(new);
  +        proc_pthread_cleanup(new);
           return stat;
       }
   
       new->curr_locked = 0;
  -    apr_pool_register_cleanup(new->pool, (void *)new, lock_cleanup, 
  +    apr_pool_cleanup_register(new->pool, (void *)new, proc_pthread_cleanup, 
                                 apr_pool_cleanup_null);
       return APR_SUCCESS;
   }
   
  -apr_status_t apr_unix_lock_inter(apr_lock_t *lock)
  +static apr_status_t proc_pthread_acquire(apr_lock_t *lock)
   {
       apr_status_t stat;
   
  -    if ((stat = pthread_mutex_lock(lock->interproc))) {
  +    if ((stat = pthread_mutex_lock(lock->pthread_interproc))) {
   #ifdef PTHREAD_SETS_ERRNO
           stat = errno;
   #endif
  @@ -243,11 +254,11 @@
       return APR_SUCCESS;
   }
   
  -apr_status_t apr_unix_unlock_inter(apr_lock_t *lock)
  +static apr_status_t proc_pthread_release(apr_lock_t *lock)
   {
       apr_status_t stat;
   
  -    if ((stat = pthread_mutex_unlock(lock->interproc))) {
  +    if ((stat = pthread_mutex_unlock(lock->pthread_interproc))) {
   #ifdef PTHREAD_SETS_ERRNO
           stat = errno;
   #endif
  @@ -257,27 +268,40 @@
       return APR_SUCCESS;
   }
   
  -apr_status_t apr_unix_destroy_inter_lock(apr_lock_t *lock)
  +static apr_status_t proc_pthread_destroy(apr_lock_t *lock)
   {
       apr_status_t stat;
  -    if ((stat = lock_cleanup(lock)) == APR_SUCCESS) {
  -        apr_pool_cleanup_kill(lock->pool, lock, lock_cleanup);
  +    if ((stat = proc_pthread_cleanup(lock)) == APR_SUCCESS) {
  +        apr_pool_cleanup_kill(lock->pool, lock, proc_pthread_cleanup);
           return APR_SUCCESS;
       }
       return stat;
   }
   
  -apr_status_t apr_unix_child_init_lock(apr_lock_t **lock, apr_pool_t *cont, const char *fname)
  +static apr_status_t proc_pthread_child_init(apr_lock_t **lock, apr_pool_t *cont, const
char *fname)
   {
       return APR_SUCCESS;
   }
  +
  +const apr_unix_lock_methods_t apr_unix_proc_pthread_methods =
  +{
  +    proc_pthread_create,
  +    proc_pthread_acquire,
  +    proc_pthread_release,
  +    proc_pthread_destroy,
  +    proc_pthread_child_init
  +};
  +
  +#endif
   
  -#elif (APR_USE_FCNTL_SERIALIZE)  
  +#if APR_HAS_FCNTL_SERIALIZE
   
   static struct flock lock_it;
   static struct flock unlock_it;
   
  -void apr_unix_setup_lock(void)
  +static apr_status_t fcntl_release(apr_lock_t *);
  +
  +static void fcntl_setup(void)
   {
       lock_it.l_whence = SEEK_SET;        /* from current point */
       lock_it.l_start = 0;                /* -"- */
  @@ -291,19 +315,20 @@
       unlock_it.l_pid = 0;                /* pid not actually interesting */
   }
   
  -static apr_status_t lock_cleanup(void *lock_)
  +static apr_status_t fcntl_cleanup(void *lock_)
   {
       apr_lock_t *lock=lock_;
   
       if (lock->curr_locked == 1) {
  -        return apr_unix_unlock_inter(lock);
  +        return fcntl_release(lock);
       }
       return APR_SUCCESS;
   }    
   
  -apr_status_t apr_unix_create_inter_lock(apr_lock_t *new)
  +static apr_status_t fcntl_create(apr_lock_t *new, const char *fname)
   {
  -    if (new->fname) {
  +    if (fname) {
  +        new->fname = apr_pstrdup(new->pool, fname);
           new->interproc = open(new->fname, O_CREAT | O_WRONLY | O_EXCL, 0644);
       }
       else {
  @@ -312,18 +337,18 @@
       }
   
       if (new->interproc < 0) {
  -        lock_cleanup(new);
  +        fcntl_cleanup(new);
           return errno;
       }
   
       new->curr_locked=0;
       unlink(new->fname);
  -    apr_pool_cleanup_register(new->pool, (void*)new, lock_cleanup, 
  +    apr_pool_cleanup_register(new->pool, (void*)new, fcntl_cleanup, 
                                 apr_pool_cleanup_null);
       return APR_SUCCESS; 
   }
   
  -apr_status_t apr_unix_lock_inter(apr_lock_t *lock)
  +static apr_status_t fcntl_acquire(apr_lock_t *lock)
   {
       int rc;
   
  @@ -337,7 +362,7 @@
       return APR_SUCCESS;
   }
   
  -apr_status_t apr_unix_unlock_inter(apr_lock_t *lock)
  +static apr_status_t fcntl_release(apr_lock_t *lock)
   {
       int rc;
   
  @@ -351,43 +376,56 @@
       return APR_SUCCESS;
   }
   
  -apr_status_t apr_unix_destroy_inter_lock(apr_lock_t *lock)
  +static apr_status_t fcntl_destroy(apr_lock_t *lock)
   {
       apr_status_t stat;
  -    if ((stat = lock_cleanup(lock)) == APR_SUCCESS) {
  -        apr_pool_cleanup_kill(lock->pool, lock, lock_cleanup);
  +    if ((stat = fcntl_cleanup(lock)) == APR_SUCCESS) {
  +        apr_pool_cleanup_kill(lock->pool, lock, fcntl_cleanup);
           return APR_SUCCESS;
       }
       return stat;
   }
   
  -apr_status_t apr_unix_child_init_lock(apr_lock_t **lock, apr_pool_t *cont, 
  -                                    const char *fname)
  +static apr_status_t fcntl_child_init(apr_lock_t **lock, apr_pool_t *cont, 
  +                                     const char *fname)
   {
       return APR_SUCCESS;
   }
   
  +const apr_unix_lock_methods_t apr_unix_fcntl_methods =
  +{
  +    fcntl_create,
  +    fcntl_acquire,
  +    fcntl_release,
  +    fcntl_destroy,
  +    fcntl_child_init
  +};
  +
  +#endif /* fcntl implementation */
   
  -#elif (APR_USE_FLOCK_SERIALIZE)
  +#if APR_HAS_FLOCK_SERIALIZE
   
  -void apr_unix_setup_lock(void)
  +static apr_status_t flock_release(apr_lock_t *);
  +
  +static void flock_setup(void)
   {
   }
   
  -static apr_status_t lock_cleanup(void *lock_)
  +static apr_status_t flock_cleanup(void *lock_)
   {
       apr_lock_t *lock=lock_;
   
       if (lock->curr_locked == 1) {
  -        return apr_unix_unlock_inter(lock);
  +        return flock_release(lock);
       }
       unlink(lock->fname);
       return APR_SUCCESS;
   }    
   
  -apr_status_t apr_unix_create_inter_lock(apr_lock_t *new)
  +static apr_status_t flock_create(apr_lock_t *new, const char *fname)
   {
  -    if (new->fname) {
  +    if (fname) {
  +        new->fname = apr_pstrdup(new->pool, fname);
           new->interproc = open(new->fname, O_CREAT | O_WRONLY | O_EXCL, 0600);
       }
       else {
  @@ -396,16 +434,16 @@
       }
   
       if (new->interproc < 0) {
  -        lock_cleanup(new);
  +        flock_cleanup(new);
           return errno;
       }
       new->curr_locked = 0;
  -    apr_pool_cleanup_register(new->pool, (void *)new, lock_cleanup,
  +    apr_pool_cleanup_register(new->pool, (void *)new, flock_cleanup,
                                 apr_pool_cleanup_null);
       return APR_SUCCESS;
   }
   
  -apr_status_t apr_unix_lock_inter(apr_lock_t *lock)
  +static apr_status_t flock_acquire(apr_lock_t *lock)
   {
       int rc;
   
  @@ -419,7 +457,7 @@
       return APR_SUCCESS;
   }
   
  -apr_status_t apr_unix_unlock_inter(apr_lock_t *lock)
  +static apr_status_t flock_release(apr_lock_t *lock)
   {
       int rc;
   
  @@ -433,18 +471,18 @@
       return APR_SUCCESS;
   }
   
  -apr_status_t apr_unix_destroy_inter_lock(apr_lock_t *lock)
  +static apr_status_t flock_destroy(apr_lock_t *lock)
   {
       apr_status_t stat;
  -    if ((stat = lock_cleanup(lock)) == APR_SUCCESS) {
  -        apr_pool_cleanup_kill(lock->new, lock, lock_cleanup);
  +    if ((stat = flock_cleanup(lock)) == APR_SUCCESS) {
  +        apr_pool_cleanup_kill(lock->pool, lock, flock_cleanup);
           return APR_SUCCESS;
       }
       return stat;
   }
   
  -apr_status_t apr_unix_child_init_lock(apr_lock_t **lock, apr_pool_t *cont, 
  -                            const char *fname)
  +static apr_status_t flock_child_init(apr_lock_t **lock, apr_pool_t *cont, 
  +                                     const char *fname)
   {
       apr_lock_t *new;
   
  @@ -453,18 +491,36 @@
       new->fname = apr_pstrdup(cont, fname);
       new->interproc = open(new->fname, O_WRONLY, 0600);
       if (new->interproc == -1) {
  -        apr_unix_destroy_inter_lock(new);
  +        flock_destroy(new);
           return errno;
       }
       *lock = new;
       return APR_SUCCESS;
   }
  +
  +const apr_unix_lock_methods_t apr_unix_flock_methods =
  +{
  +    flock_create,
  +    flock_acquire,
  +    flock_release,
  +    flock_destroy,
  +    flock_child_init
  +};
  +
  +#endif /* flock implementation */
   
  -#else
  -/* No inter-process mutex on this platform.  Use at your own risk */
  -#define create_inter_lock(x, y)
  -#define lock_inter(x, y)
  -#define unlock_inter(x, y)
  -#define destroy_inter_lock(x, y)
  -#define child_init_lock(x, y, z)
  +void apr_unix_setup_lock(void)
  +{
  +#if APR_HAS_SYSVSEM_SERIALIZE
  +    sysv_setup();
  +#endif
  +#if APR_HAS_PROC_PTHREAD_SERIALIZE
  +    proc_pthread_setup();
   #endif
  +#if APR_HAS_FCNTL_SERIALIZE
  +    fcntl_setup();
  +#endif
  +#if APR_HAS_FLOCK_SERIALIZE
  +    flock_setup();
  +#endif
  +}
  
  
  
  1.24      +46 -5     apr/locks/unix/intraproc.c
  
  Index: intraproc.c
  ===================================================================
  RCS file: /home/cvs/apr/locks/unix/intraproc.c,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- intraproc.c	2001/06/05 16:46:52	1.23
  +++ intraproc.c	2001/06/25 18:53:35	1.24
  @@ -73,7 +73,7 @@
       return stat;
   }    
   
  -apr_status_t apr_unix_create_intra_lock(apr_lock_t *new)
  +static apr_status_t intra_create(apr_lock_t *new, const char *fname)
   {
       apr_status_t stat;
       pthread_mutexattr_t mattr;
  @@ -113,7 +113,7 @@
       return APR_SUCCESS;
   }
   
  -apr_status_t apr_unix_lock_intra(apr_lock_t *lock)
  +static apr_status_t intra_acquire(apr_lock_t *lock)
   {
       apr_status_t stat;
   
  @@ -126,7 +126,7 @@
       return stat;
   }
   
  -apr_status_t apr_unix_unlock_intra(apr_lock_t *lock)
  +static apr_status_t intra_release(apr_lock_t *lock)
   {
       apr_status_t status;
   
  @@ -139,7 +139,7 @@
       return status;
   }
   
  -apr_status_t apr_unix_destroy_intra_lock(apr_lock_t *lock)
  +static apr_status_t intra_destroy(apr_lock_t *lock)
   {
       apr_status_t stat;
       if ((stat = lock_intra_cleanup(lock)) == APR_SUCCESS) {
  @@ -148,5 +148,46 @@
       }
       return stat;
   }
  -#endif
  +
  +#endif /* APR_USE_PTHREAD_SERIALIZE */
  +
  +const apr_unix_lock_methods_t apr_unix_intra_methods =
  +{
  +    intra_create,
  +    intra_acquire,
  +    intra_release,
  +    intra_destroy,
  +    NULL /* no child init */
  +};
  +
  +#if APR_HAS_RWLOCK_SERIALIZE
  +static apr_status_t rwlock_create(apr_lock_t *new, const char *fname)
  +{
  +    /* XXX check retcode */
  +    pthread_rwlock_init(&new->rwlock, NULL);
  +    return APR_SUCCESS;
  +}
  +
  +static apr_status_t rwlock_release(apr_lock_t *lock)
  +{
  +    /* XXX PTHREAD_SETS_ERRNO crap? */
  +    return pthread_rwlock_unlock(&lock->rwlock);
  +}
  +
  +static apr_status_t rwlock_destroy(apr_lock_t *lock)
  +{
  +    /* XXX PTHREAD_SETS_ERRNO crap? */
  +    return pthread_rwlock_destroy(&lock->rwlock);
  +}
  +
  +const apr_unix_lock_methods_t apr_unix_rwlock_methods =
  +{
  +    rwlock_create,
  +    NULL, /* no standard acquire method; app better not call :) */
  +    rwlock_release,
  +    rwlock_destroy,
  +    NULL /* no child init method */
  +};
   #endif
  +
  +#endif /* APR_HAS_THREADS */
  
  
  
  1.54      +120 -127  apr/locks/unix/locks.c
  
  Index: locks.c
  ===================================================================
  RCS file: /home/cvs/apr/locks/unix/locks.c,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- locks.c	2001/06/14 18:51:58	1.53
  +++ locks.c	2001/06/25 18:53:36	1.54
  @@ -56,53 +56,134 @@
   #include "apr_strings.h"
   #include "apr_portable.h"
   
  +#if !APR_PROCESS_LOCK_IS_GLOBAL && APR_HAS_THREADS
  +static apr_status_t lockall_create(apr_lock_t *new, const char *fname)
  +{
  +    apr_status_t rv;
  +
  +    if ((rv = new->inter_meth->create(new, fname)) != APR_SUCCESS) {
  +        return rv;
  +    }
  +    if ((rv = new->intra_meth->create(new, fname)) != APR_SUCCESS) {
  +        return rv;
  +    }
  +    return APR_SUCCESS;
  +}
  +
  +static apr_status_t lockall_acquire(apr_lock_t *lock)
  +{
  +    apr_status_t rv;
  +
  +    if ((rv = lock->intra_meth->acquire(lock)) != APR_SUCCESS) {
  +        return rv;
  +    }
  +    if ((rv = lock->inter_meth->acquire(lock)) != APR_SUCCESS) {
  +        return rv;
  +    }
  +    return APR_SUCCESS;
  +}
  +
  +static apr_status_t lockall_release(apr_lock_t *lock)
  +{
  +    apr_status_t rv;
  +
  +    if ((rv = lock->intra_meth->release(lock)) != APR_SUCCESS) {
  +        return rv;
  +    }
  +    if ((rv = lock->inter_meth->release(lock)) != APR_SUCCESS) {
  +        return rv;
  +    }
  +    return APR_SUCCESS;
  +}
  +
  +static apr_status_t lockall_destroy(apr_lock_t *lock)
  +{
  +    apr_status_t rv;
  +
  +    if ((rv = lock->intra_meth->destroy(lock)) != APR_SUCCESS) {
  +        return rv;
  +    }
  +    if ((rv = lock->inter_meth->destroy(lock)) != APR_SUCCESS) {
  +        return rv;
  +    }
  +    return APR_SUCCESS;
  +}
  +
  +static apr_status_t lockall_child_init(apr_lock_t **lock, apr_pool_t *pool,
  +                                       const char *fname)
  +{
  +    /* no child init for intra lock */
  +    return (*lock)->inter_meth->child_init(lock, pool, fname);
  +}
  +
  +static const struct apr_unix_lock_methods_t lockall_methods =
  +{
  +    lockall_create,
  +    lockall_acquire,
  +    lockall_release,
  +    lockall_destroy,
  +    lockall_child_init
  +};
  +#endif
  +
   static apr_status_t create_lock(apr_lock_t *new, const char *fname)
   {
       apr_status_t stat;
   
  -    switch (new->type)
  -    {
  -    case APR_MUTEX:
  -#if (APR_USE_FCNTL_SERIALIZE) || (APR_USE_FLOCK_SERIALIZE)
  -    /* file-based serialization primitives */
       if (new->scope != APR_INTRAPROCESS) {
  -        if (fname != NULL) {
  -            new->fname = apr_pstrdup(new->pool, fname);
  -        }
  -    }
  +#if APR_USE_FLOCK_SERIALIZE
  +        new->inter_meth = &apr_unix_flock_methods;
  +#elif APR_USE_SYSVSEM_SERIALIZE
  +        new->inter_meth = &apr_unix_sysv_methods;
  +#elif APR_USE_FCNTL_SERIALIZE
  +        new->inter_meth = &apr_unix_fcntl_methods;
  +#elif APR_USE_PROC_PTHREAD_SERIALIZE
  +        new->inter_method = &apr_unix_proc_pthread_methods;
  +#else
  +        return APR_ENOTIMPL;
   #endif
  +    }
   
  -#if APR_PROCESS_LOCK_IS_GLOBAL /* don't need intra lock for APR_LOCKALL */
  -    if (new->scope == APR_INTRAPROCESS) {
  -#else
       if (new->scope != APR_CROSS_PROCESS) {
  -#endif
   #if APR_HAS_THREADS
  -        if ((stat = apr_unix_create_intra_lock(new)) != APR_SUCCESS) {
  -            return stat;
  -        }
  +        if (new->type == APR_READWRITE) {
  +#if APR_HAS_RWLOCK_SERIALIZE
  +            new->intra_meth = &apr_unix_rwlock_methods;
   #else
  -        if (new->scope != APR_LOCKALL) {
  -            return APR_ENOTIMPL;
  -        }
  +            return APR_ENOTIMPL; /* 'cause we don't have rwlocks */
   #endif
  -    }
  -    if (new->scope != APR_INTRAPROCESS) {
  -        if ((stat = apr_unix_create_inter_lock(new)) != APR_SUCCESS) {
  -            return stat;
           }
  +        else {
  +            new->intra_meth = &apr_unix_intra_methods;
  +        }
  +#else
  +        return APR_ENOTIMPL; /* 'cause we don't have threads */
  +#endif
       }
  -    break;
  -    case APR_READWRITE:
  -#ifdef HAVE_PTHREAD_RWLOCK_INIT
  -    if (new->scope != APR_INTRAPROCESS)
  -        return APR_ENOTIMPL;
  -    pthread_rwlock_init(&new->rwlock, NULL);
  -    break;
  +
  +    switch (new->scope) {
  +    case APR_LOCKALL:
  +#if APR_PROCESS_LOCK_IS_GLOBAL || !APR_HAS_THREADS
  +        /* XXX but how do we know that this particular mechanism has this
  +         * property?  for now we assume all mechanisms on this system have
  +         * the property
  +         */
  +        new->meth = new->inter_meth;
   #else
  -    return APR_ENOTIMPL;
  +        new->meth = &lockall_methods;
   #endif
  +        break;
  +    case APR_CROSS_PROCESS:
  +        new->meth = new->inter_meth;
  +        break;
  +    case APR_INTRAPROCESS:
  +        new->meth = new->intra_meth;
       }
  +
  +    if ((stat = new->meth->create(new, fname)) != APR_SUCCESS) {
  +        return stat;
  +    }
  +
       return APR_SUCCESS;
   }
   
  @@ -137,30 +218,8 @@
       }
   #endif
   
  -    switch (lock->type)
  -    {
  -    case APR_MUTEX:
  -#if APR_PROCESS_LOCK_IS_GLOBAL /* don't need intra lock for APR_LOCKALL */
  -    if (lock->scope == APR_INTRAPROCESS) {
  -#else
  -    if (lock->scope != APR_CROSS_PROCESS) {
  -#endif
  -#if APR_HAS_THREADS
  -        if ((stat = apr_unix_lock_intra(lock)) != APR_SUCCESS) {
  -            return stat;
  -        }
  -#else
  -        /* must be APR_LOCKALL */
  -#endif
  -    }
  -    if (lock->scope != APR_INTRAPROCESS) {
  -        if ((stat = apr_unix_lock_inter(lock)) != APR_SUCCESS) {
  -            return stat;
  -        }
  -    }
  -    break;
  -    case APR_READWRITE:
  -        return APR_ENOTIMPL;
  +    if ((stat = lock->meth->acquire(lock)) != APR_SUCCESS) {
  +        return stat;
       }
   
   #if APR_HAS_THREADS
  @@ -211,36 +270,8 @@
       }
   #endif
   
  -    switch (lock->type)
  -    {
  -    case APR_MUTEX:
  -#if APR_PROCESS_LOCK_IS_GLOBAL /* don't need intra lock for APR_LOCKALL */
  -    if (lock->scope == APR_INTRAPROCESS) {
  -#else
  -    if (lock->scope != APR_CROSS_PROCESS) {
  -#endif
  -#if APR_HAS_THREADS
  -        if ((stat = apr_unix_unlock_intra(lock)) != APR_SUCCESS) {
  -            return stat;
  -        }
  -#else
  -        /* must be APR_LOCKALL */
  -#endif
  -    }
  -    if (lock->scope != APR_INTRAPROCESS) {
  -        if ((stat = apr_unix_unlock_inter(lock)) != APR_SUCCESS) {
  -            return stat;
  -        }
  -    }
  -    break;
  -    case APR_READWRITE:
  -#ifdef HAVE_PTHREAD_RWLOCK_INIT
  -        if ((stat = pthread_rwlock_unlock(&lock->rwlock)) != 0)
  -            return stat;
  -        break;
  -#else
  -        return APR_ENOTIMPL;
  -#endif
  +    if ((stat = lock->meth->release(lock)) != APR_SUCCESS) {
  +        return stat;
       }
   
   #if APR_HAS_THREADS
  @@ -253,53 +284,14 @@
   
   apr_status_t apr_lock_destroy(apr_lock_t *lock)
   {
  -    apr_status_t stat;
  -
  -    switch (lock->type)
  -    {
  -    case APR_MUTEX:
  -#if APR_PROCESS_LOCK_IS_GLOBAL /* don't need intra lock for APR_LOCKALL */
  -    if (lock->scope == APR_INTRAPROCESS) {
  -#else
  -    if (lock->scope != APR_CROSS_PROCESS) {
  -#endif
  -#if APR_HAS_THREADS
  -        if ((stat = apr_unix_destroy_intra_lock(lock)) != APR_SUCCESS) {
  -            return stat;
  -        }
  -#else
  -        if (lock->scope != APR_LOCKALL) {
  -            return APR_ENOTIMPL;
  -        }
  -#endif
  -    }
  -    if (lock->scope != APR_INTRAPROCESS) {
  -        if ((stat = apr_unix_destroy_inter_lock(lock)) != APR_SUCCESS) {
  -            return stat;
  -        }
  -    }
  -    break;
  -    case APR_READWRITE:
  -#ifdef HAVE_PTHREAD_RWLOCK_INIT
  -    if ((stat = pthread_rwlock_destroy(&lock->rwlock)) != 0)
  -        return stat;
  -    break;
  -#else
  -    return APR_ENOTIMPL;
  -#endif
  -    }
  -    return APR_SUCCESS;
  +    return lock->meth->destroy(lock);
   }
   
   apr_status_t apr_lock_child_init(apr_lock_t **lock, const char *fname, 
                                  apr_pool_t *cont)
   {
  -    apr_status_t stat;
  -    if ((*lock)->scope != APR_INTRAPROCESS) {
  -        if ((stat = apr_unix_child_init_lock(lock, cont, fname)) != APR_SUCCESS) {
  -            return stat;
  -        }
  -    }
  +    if ((*lock)->scope != APR_INTRAPROCESS)
  +        return (*lock)->meth->child_init(lock, cont, fname);
       return APR_SUCCESS;
   }
   
  @@ -336,6 +328,7 @@
           (*lock) = (apr_lock_t *)apr_pcalloc(pool, sizeof(apr_lock_t));
           (*lock)->pool = pool;
       }
  +    /* XXX handle setting of handle for PROC_PTHREAD_SERIALIZE here */
       (*lock)->interproc = thelock->crossproc;
   #if APR_HAS_THREADS
   #if (APR_USE_PTHREAD_SERIALIZE)
  
  
  

Mime
View raw message