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 locks.c
Date Tue, 26 Jun 2001 02:05:07 GMT
trawick     01/06/25 19:05:06

  Modified:    .        configure.in
               include  apr.h.in apr.hw apr_lock.h
               locks/unix locks.c
  Log:
  Add apr_lock_create_np() (Unix only, for now) which allows the caller to
  specify the mechanism used for the interprocess lock (if any).
  
  Revision  Changes    Path
  1.317     +7 -0      apr/configure.in
  
  Index: configure.in
  ===================================================================
  RCS file: /home/cvs/apr/configure.in,v
  retrieving revision 1.316
  retrieving revision 1.317
  diff -u -r1.316 -r1.317
  --- configure.in	2001/06/26 00:22:06	1.316
  +++ configure.in	2001/06/26 02:04:55	1.317
  @@ -974,11 +974,18 @@
           ;;
   esac
   
  +if test "$flockser$sysvser$fcntlser$procpthreadser" = "0000"; then
  +  lockcreatenp="0"
  +else
  +  lockcreatenp="1"
  +fi
  +
   AC_SUBST(flockser)
   AC_SUBST(sysvser)
   AC_SUBST(fcntlser)
   AC_SUBST(procpthreadser)
   AC_SUBST(pthreadser)
  +AC_SUBST(lockcreatenp)
   
   AC_MSG_CHECKING(if interprocess lock affects threads)
   if test "x$apr_process_lock_is_global" = "xyes"; then
  
  
  
  1.84      +2 -0      apr/include/apr.h.in
  
  Index: apr.h.in
  ===================================================================
  RCS file: /home/cvs/apr/include/apr.h.in,v
  retrieving revision 1.83
  retrieving revision 1.84
  diff -u -r1.83 -r1.84
  --- apr.h.in	2001/06/09 11:33:07	1.83
  +++ apr.h.in	2001/06/26 02:04:58	1.84
  @@ -64,6 +64,8 @@
   #define APR_USE_PROC_PTHREAD_SERIALIZE    @procpthreadser@ 
   #define APR_USE_PTHREAD_SERIALIZE         @pthreadser@ 
   
  +#define APR_HAS_LOCK_CREATE_NP            @lockcreatenp@
  +
   #define APR_PROCESS_LOCK_IS_GLOBAL        @proclockglobal@
   
   #define APR_USES_ANONYMOUS_SHM            @anonymous_shm@
  
  
  
  1.69      +2 -0      apr/include/apr.hw
  
  Index: apr.hw
  ===================================================================
  RCS file: /home/cvs/apr/include/apr.hw,v
  retrieving revision 1.68
  retrieving revision 1.69
  diff -u -r1.68 -r1.69
  --- apr.hw	2001/06/06 16:05:05	1.68
  +++ apr.hw	2001/06/26 02:04:59	1.69
  @@ -157,6 +157,8 @@
   #define APR_USE_PROC_PTHREAD_SERIALIZE    0 
   #define APR_USE_PTHREAD_SERIALIZE         0 
   
  +#define APR_HAS_LOCK_CREATE_NP            0
  +
   #define APR_PROCESS_LOCK_IS_GLOBAL        0
   
   #define APR_USES_ANONYMOUS_SHM            0
  
  
  
  1.28      +48 -0     apr/include/apr_lock.h
  
  Index: apr_lock.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_lock.h,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- apr_lock.h	2001/06/06 18:11:02	1.27
  +++ apr_lock.h	2001/06/26 02:05:00	1.28
  @@ -178,6 +178,54 @@
                                              const char *key,
                                              apr_status_t (*cleanup)(void *));
   
  +#if APR_HAS_LOCK_CREATE_NP
  +
  +typedef enum {APR_LOCK_FCNTL, APR_LOCK_FLOCK, APR_LOCK_SYSVSEM, APR_LOCK_PROC_PTHREAD,
  +              APR_LOCK_DEFAULT} apr_lockmech_e_np;
  +
  +/**
  + * non-portable interface to apr_lock_create()
  + *
  + * Create a new instance of a lock structure.  This is like apr_lock_create()
  + * but has some non-portable parameters.  This should be used sparingly.
  + *
  + * @param lock The newly created lock structure.
  + * @param type The type of lock to create, one of:
  + * <PRE>
  + *            APR_MUTEX
  + *            APR_READWRITE
  + * </PRE>
  + * @param scope The scope of the lock to create, one of:
  + * <PRE>
  + *            APR_CROSS_PROCESS    lock processes from the protected area.
  + *            APR_INTRAPROCESS     lock threads from the protected area.
  + *            APR_LOCKALL          lock processes and threads from the
  + *                                 protected area.
  + * </PRE>
  + * @param mech The mechanism to use for the interprocess lock, if any; one of
  + * <PRE>
  + *            APR_LOCK_FCNTL
  + *            APR_LOCK_FLOCK
  + *            APR_LOCK_SYSVSEM
  + *            APR_LOCK_PROC_PTHREAD
  + *            APR_LOCK_DEFAULT     pick the default mechanism for the platform
  + * </PRE>
  + * @param fname A file name to use if the lock mechanism requires one.  This
  + *        argument should always be provided.  The lock code itself will
  + *        determine if it should be used.
  + * @param pool The pool to operate on.
  + * @tip APR_CROSS_PROCESS may lock both processes and threads, but it is
  + *      only guaranteed to lock processes.
  + * @deffunc apr_status_t apr_lock_create(apr_lock_t **lock, apr_locktype_e type, apr_lockscope_e
scope, const char *fname, apr_pool_t *pool)
  + */
  +APR_DECLARE(apr_status_t) apr_lock_create_np(apr_lock_t **lock,
  +                                             apr_locktype_e type,
  +                                             apr_lockscope_e scope,
  +                                             apr_lockmech_e_np mech,
  +                                             const char *fname,
  +                                             apr_pool_t *pool);
  +#endif /* APR_HAS_LOCK_CREATE_NP */
  +
   #ifdef __cplusplus
   }
   #endif
  
  
  
  1.56      +57 -8     apr/locks/unix/locks.c
  
  Index: locks.c
  ===================================================================
  RCS file: /home/cvs/apr/locks/unix/locks.c,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- locks.c	2001/06/25 20:23:16	1.55
  +++ locks.c	2001/06/26 02:05:05	1.56
  @@ -126,11 +126,38 @@
   };
   #endif
   
  -static apr_status_t create_lock(apr_lock_t *new, const char *fname)
  +static apr_status_t choose_method(apr_lock_t *new, apr_lockmech_e_np mech)
   {
  -    apr_status_t stat;
  -
  -    if (new->scope != APR_INTRAPROCESS) {
  +    switch (mech) {
  +    case APR_LOCK_FCNTL:
  +#if APR_HAS_FCNTL_SERIALIZE
  +        new->inter_meth = &apr_unix_fcntl_methods;
  +#else
  +        return APR_ENOTIMPL;
  +#endif
  +        break;
  +    case APR_LOCK_FLOCK:
  +#if APR_HAS_FLOCK_SERIALIZE
  +        new->inter_meth = &apr_unix_flock_methods;
  +#else
  +        return APR_ENOTIMPL;
  +#endif
  +        break;
  +    case APR_LOCK_SYSVSEM:
  +#if APR_HAS_SYSVSEM_SERIALIZE
  +        new->inter_meth = &apr_unix_sysv_methods;
  +#else
  +        return APR_ENOTIMPL;
  +#endif
  +        break;
  +    case APR_LOCK_PROC_PTHREAD:
  +#if APR_HAS_PROC_PTHREAD_SERIALIZE
  +        new->inter_meth = &apr_unix_proc_pthread_methods;
  +#else
  +        return APR_ENOTIMPL;
  +#endif
  +        break;
  +    case APR_LOCK_DEFAULT:
   #if APR_USE_FLOCK_SERIALIZE
           new->inter_meth = &apr_unix_flock_methods;
   #elif APR_USE_SYSVSEM_SERIALIZE
  @@ -142,8 +169,23 @@
   #else
           return APR_ENOTIMPL;
   #endif
  +        break;
  +    default:
  +        return APR_ENOTIMPL;
       }
  +    return APR_SUCCESS;
  +}
  +
  +static apr_status_t create_lock(apr_lock_t *new, apr_lockmech_e_np mech, const char *fname)
  +{
  +    apr_status_t stat;
   
  +    if (new->scope != APR_INTRAPROCESS) {
  +        if ((stat = choose_method(new, mech)) != APR_SUCCESS) {
  +            return stat;
  +        }
  +    }
  +
       if (new->scope != APR_CROSS_PROCESS) {
   #if APR_HAS_THREADS
           if (new->type == APR_READWRITE) {
  @@ -189,9 +231,9 @@
       return APR_SUCCESS;
   }
   
  -apr_status_t apr_lock_create(apr_lock_t **lock, apr_locktype_e type, 
  -                           apr_lockscope_e scope, const char *fname, 
  -                           apr_pool_t *pool)
  +apr_status_t apr_lock_create_np(apr_lock_t **lock, apr_locktype_e type, 
  +                                apr_lockscope_e scope, apr_lockmech_e_np mech,
  +                                const char *fname, apr_pool_t *pool)
   {
       apr_lock_t *new;
       apr_status_t stat;
  @@ -202,11 +244,18 @@
       new->type  = type;
       new->scope = scope;
   
  -    if ((stat = create_lock(new, fname)) != APR_SUCCESS)
  +    if ((stat = create_lock(new, mech, fname)) != APR_SUCCESS)
           return stat;
   
       *lock = new;
       return APR_SUCCESS;
  +}
  +
  +apr_status_t apr_lock_create(apr_lock_t **lock, apr_locktype_e type, 
  +                             apr_lockscope_e scope, const char *fname, 
  +                             apr_pool_t *pool)
  +{
  +    return apr_lock_create_np(lock, type, scope, APR_LOCK_DEFAULT, fname, pool);
   }
   
   apr_status_t apr_lock_acquire(apr_lock_t *lock)
  
  
  

Mime
View raw message