You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by "MATHIHALLI,MADHUSUDAN (HP-Cupertino,ex1)" <ma...@hp.com> on 2003/10/23 23:24:07 UTC

[PATCH] Global apr_thread_rwlock

Hi,
	I was wondering if there's any interest in having a option to make
the apr_thread_rwlock to support GLOBAL rwlocks. Currently,
apr_thread_rwlock exhibits the default pthread behaviour - to be process
specific. Since the pthread library gives an option to make it global, can
we add it to APR too ?

-Madhu

--- thread_rwlock.c     Thu Oct 23 14:17:44 2003
+++ thread_rwlock.c.g   Thu Oct 23 14:21:12 2003
@@ -99,6 +99,53 @@
     return APR_SUCCESS;
 }

+APR_DECLARE(apr_status_t) apr_thread_rwlock_create_ex(apr_thread_rwlock_t
**rwl
ock,
+                                                      unsigned int flags,
+                                                      apr_pool_t *pool)
+{
+    apr_thread_rwlock_t *new_rwlock;
+    pthread_rwlockattr_t rwattr;
+    apr_status_t stat;
+
+    new_rwlock = apr_palloc(pool, sizeof(apr_thread_rwlock_t));
+    new_rwlock->pool = pool;
+
+    if ((rv = pthread_rwlockattr_init(&rwattr))) {
+#ifdef PTHREAD_SETS_ERRNO
+        stat = errno;
+#endif
+        return stat;
+    }
+
+    if ((rv = pthread_rwlockattr_setpshared(&rwattr,
PTHREAD_PROCESS_SHARED)))
{
+#ifdef PTHREAD_SETS_ERRNO
+        stat = errno;
+#endif
+        return stat;
+    }
+
+    if ((stat = pthread_rwlock_init(&new_rwlock->rwlock, &rwattr))) {
+#ifdef PTHREAD_SETS_ERRNO
+        stat = errno;
+#endif
+        return stat;
+    }
+
+    if ((rv = pthread_rwlockattr_destroy(&rwattr))) {
+#ifdef PTHREAD_SETS_ERRNO
+        stat = errno;
+#endif
+        return stat;
+    }
+
+    apr_pool_cleanup_register(new_rwlock->pool,
+                              (void *)new_rwlock, thread_rwlock_cleanup,
+                              apr_pool_cleanup_null);
+
+    *rwlock = new_rwlock;
+    return APR_SUCCESS;
+}
+
 APR_DECLARE(apr_status_t) apr_thread_rwlock_rdlock(apr_thread_rwlock_t
*rwlock)
 {
     apr_status_t stat;

Re: [PATCH] Global apr_thread_rwlock

Posted by Aaron Bannert <aa...@clove.org>.
On Thu, Oct 23, 2003 at 05:24:07PM -0400, MATHIHALLI,MADHUSUDAN (HP-Cupertino,ex1) wrote:
> Hi,
> 	I was wondering if there's any interest in having a option to make
> the apr_thread_rwlock to support GLOBAL rwlocks. Currently,
> apr_thread_rwlock exhibits the default pthread behaviour - to be process
> specific. Since the pthread library gives an option to make it global, can
> we add it to APR too ?

Since the apr_thread_* routines are for syncing between threads, this
shouldn't be called apr_thread_rwlock. Naming it apr_global_rwlock_t
is probably more appropriate.

Also, for the Windows gurus -- is this concept portable? Do we need to
make the interface more general to make sure it will work on Windows
and other platforms, or will it work as it is?

-aaron