apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Justin Erenkrantz <jerenkra...@ebuilt.com>
Subject Re: [PATCH] First-cut of APR_READWRITE locks...
Date Sat, 28 Apr 2001 21:44:36 GMT
On Sat, Apr 28, 2001 at 04:50:46PM -0400, Cliff Woolley wrote:
> > @@ -626,7 +626,7 @@
> >      dnl BSD 4.4 originated 'q'.  Solaris is more popular and
> >      dnl doesn't support 'q'.  Solaris wins.  Exceptions can
> >      dnl go to the OS-dependent section.
> > -    int64_t_fmt='#define APR_INT64_T_FMT "lld"'
> > +    int64_t_fmt='#define APR_INT64_T_FMT "qd"'
> >      int64_value="long long"
> >      long_value="long long"
> >  elif test "$ac_cv_sizeof_long_double" = "8"; then
> 
> Remind me why this change is necessary?  What about the comment above that
> that gives a good reason not to use qd?

Ryan claims this is bogus.  Any of the APR_XXX_T_FMT strings can ONLY 
be used apr_*printf NOT printf.  We should probably remove the comment
comment (since it doesn't matter). 

Well, actually if that is the case, why do we even HAVE APR_XXX_T_FMT
in the first place - if they all have the same format strings and can
only be used with APR?

> This should just be "return APR_ENOTIMPL;".  Only use APR_OS2_STATUS to
> convert from an os-style error to an APR-style error code.

Thanks.  

I fixed the OS2 thing and removed the APR_XXX_T_FMT thing because that
is completely unrelated.  -- justin

Index: configure.in
===================================================================
RCS file: /home/cvspublic/apr/configure.in,v
retrieving revision 1.294
diff -u -r1.294 configure.in
--- configure.in	2001/04/27 18:36:03	1.294
+++ configure.in	2001/04/28 21:40:58
@@ -259,7 +259,7 @@
     if test "$pthreadh" = "1"; then
         APR_CHECK_PTHREAD_GETSPECIFIC_TWO_ARGS
         APR_CHECK_PTHREAD_ATTR_GETDETACHSTATE_ONE_ARG
-        AC_CHECK_FUNCS(pthread_key_delete)
+        AC_CHECK_FUNCS(pthread_key_delete pthread_rwlock_init)
     fi
 fi
 
Index: include/apr_lock.h
===================================================================
RCS file: /home/cvspublic/apr/include/apr_lock.h,v
retrieving revision 1.23
diff -u -r1.23 apr_lock.h
--- include/apr_lock.h	2001/02/16 04:15:46	1.23
+++ include/apr_lock.h	2001/04/28 21:40:59
@@ -71,6 +71,8 @@
 
 typedef enum {APR_MUTEX, APR_READWRITE} apr_locktype_e;
 
+typedef enum {APR_READER, APR_WRITER} apr_readerwriter_e;
+
 typedef struct apr_lock_t           apr_lock_t;
 
 /*   Function definitions */
@@ -110,6 +112,15 @@
  * @deffunc apr_status_t apr_lock_acquire(apr_lock_t *lock)
  */
 APR_DECLARE(apr_status_t) apr_lock_acquire(apr_lock_t *lock);
+
+/**
+ * Lock a region with either a reader or writer lock.
+ * @param lock The lock to set.
+ * @param type The type of lock to acquire.
+ * @deffunc apr_status_t apr_lock_acquire_rw(apr_lock_t *lock, apr_readerwriter_e type)
+ */
+APR_DECLARE(apr_status_t) apr_lock_acquire_rw(apr_lock_t *lock,
+                                              apr_readerwriter_e type);
 
 /**
  * Unlock a protected region.
Index: include/arch/unix/locks.h
===================================================================
RCS file: /home/cvspublic/apr/include/arch/unix/locks.h,v
retrieving revision 1.26
diff -u -r1.26 locks.h
--- include/arch/unix/locks.h	2001/02/25 20:39:32	1.26
+++ include/arch/unix/locks.h	2001/04/28 21:40:59
@@ -130,9 +130,12 @@
 #if APR_USE_PTHREAD_SERIALIZE
     pthread_mutex_t *intraproc;
 #endif
+#ifdef HAVE_PTHREAD_RWLOCK_INIT
+    pthread_rwlock_t rwlock;
 #endif
+#endif
     /* At some point, we should do a scope for both inter and intra process
-     *  locking here.  Something like pthread_mutex with PTHREAD_PROCESS_SHARED
+     * locking here.  Something like pthread_mutex with PTHREAD_PROCESS_SHARED
      */    
 };
 
@@ -149,8 +152,8 @@
 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);
+apr_status_t apr_unix_child_init_lock(struct apr_lock_t **lock, 
+                                      apr_pool_t *cont, const char *fname);
 
 #endif  /* LOCKS_H */
 
Index: locks/beos/locks.c
===================================================================
RCS file: /home/cvspublic/apr/locks/beos/locks.c,v
retrieving revision 1.26
diff -u -r1.26 locks.c
--- locks/beos/locks.c	2001/02/16 04:15:53	1.26
+++ locks/beos/locks.c	2001/04/28 21:40:59
@@ -103,6 +103,11 @@
     return APR_SUCCESS;
 }
 
+apr_status_t apr_lock_acquire_rw(apr_lock_t *lock, apr_readerwriter_e e)
+{
+    return APR_ENOTIMPL;
+}
+
 apr_status_t apr_lock_release(apr_lock_t *lock)
 {
     apr_status_t stat;
Index: locks/os2/locks.c
===================================================================
RCS file: /home/cvspublic/apr/locks/os2/locks.c,v
retrieving revision 1.27
diff -u -r1.27 locks.c
--- locks/os2/locks.c	2001/03/19 12:43:25	1.27
+++ locks/os2/locks.c	2001/04/28 21:41:00
@@ -142,7 +142,10 @@
     return APR_OS2_STATUS(rc);
 }
 
-
+apr_status_t apr_lock_acquire_rw(apr_lock_t *lock, apr_readerwriter_e e)
+{
+    return APR_ENOTIMPL;
+}
 
 apr_status_t apr_lock_release(apr_lock_t *lock)
 {
Index: locks/unix/locks.c
===================================================================
RCS file: /home/cvspublic/apr/locks/unix/locks.c,v
retrieving revision 1.46
diff -u -r1.46 locks.c
--- locks/unix/locks.c	2001/02/16 04:15:55	1.46
+++ locks/unix/locks.c	2001/04/28 21:41:00
@@ -68,6 +68,9 @@
     new->cntxt = cont;
     new->type  = type;
     new->scope = scope;
+    switch (new->type)
+    {
+    case APR_MUTEX:
 #if (APR_USE_FCNTL_SERIALIZE) || (APR_USE_FLOCK_SERIALIZE)
     /* file-based serialization primitives */
     if (scope != APR_INTRAPROCESS) {
@@ -97,6 +100,16 @@
             return stat;
         }
     }
+    break;
+    case APR_READWRITE:
+#ifdef HAVE_PTHREAD_RWLOCK_INIT
+    pthread_rwlock_init(&new->rwlock, NULL);
+    break;
+#else
+    return APR_ENOTIMPL;
+#endif
+    }
+
     *lock = new;
     return APR_SUCCESS;
 }
@@ -104,6 +117,10 @@
 apr_status_t apr_lock_acquire(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
@@ -122,13 +139,49 @@
             return stat;
         }
     }
+    break;
+    case APR_READWRITE:
+        return apr_lock_acquire_rw(lock, APR_READER);
+    }
+
     return APR_SUCCESS;
 }
 
+apr_status_t apr_lock_acquire_rw(apr_lock_t *lock, apr_readerwriter_e e)
+{
+    apr_status_t stat = APR_SUCCESS;
+
+    switch (lock->type)
+    {
+    case APR_MUTEX:
+        return APR_ENOTIMPL;
+    case APR_READWRITE:
+#ifdef HAVE_PTHREAD_RWLOCK_INIT
+        switch (e)
+        {
+        case APR_READER:
+            stat = pthread_rwlock_rdlock(&lock->rwlock);
+            break;
+        case APR_WRITER:
+            stat = pthread_rwlock_wrlock(&lock->rwlock);
+            break;
+        }
+        break;
+#else
+        return APR_ENOTIMPL;
+#endif
+    }
+
+    return stat;
+}
+
 apr_status_t apr_lock_release(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
@@ -147,12 +200,27 @@
             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
+    }
+    
     return APR_SUCCESS;
 }
 
 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
@@ -172,6 +240,16 @@
         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;
 }
Index: locks/win32/locks.c
===================================================================
RCS file: /home/cvspublic/apr/locks/win32/locks.c,v
retrieving revision 1.36
diff -u -r1.36 locks.c
--- locks/win32/locks.c	2001/02/16 04:15:56	1.36
+++ locks/win32/locks.c	2001/04/28 21:41:00
@@ -131,6 +131,12 @@
     return apr_get_os_error();
 }
 
+APR_DECLARE(apr_status_t) apr_lock_acquire_rw(apr_lock_t *lock,
+                                              apr_readerwriter_e e)
+{
+    return APR_ENOTIMPL;
+}
+
 APR_DECLARE(apr_status_t) apr_lock_release(apr_lock_t *lock)
 {
     if (lock->scope == APR_INTRAPROCESS) {


Mime
View raw message