trawick 01/06/29 10:53:38
Modified: include/arch/unix locks.h
locks/unix crossproc.c intraproc.c locks.c
Log:
slight cleanups to the Unix lock implementation...
1) apr_unix_lock_mech_t has a new flags field to indicate whether
or not the particular mechanism is global (i.e., whether or not
we need to add an additional intraprocess mutex to block out
other threads in our process)
this will help fixing our knowledge of whether or not a particular
mechanism is global on a particular platform
a proc_pthread lock is always global, so this change brings a slight
performance improvement as we realize we don't need the intraprocess
mutex too
2) apr_unix_lock_mech_t has new acquire_read and acquire_write fields;
for now, this cleans up apr_lock_acquire_rw() and also makes it easy
to add interprocess rw lock... ones based on flock() should take
just a few lines of code to implement (but watch the complications
for the lock create path since we need to sometimes use an
intraprocess rw lock too :( )
Revision Changes Path
1.34 +6 -0 apr/include/arch/unix/locks.h
Index: locks.h
===================================================================
RCS file: /home/cvs/apr/include/arch/unix/locks.h,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- locks.h 2001/06/26 15:07:31 1.33
+++ locks.h 2001/06/29 17:53:27 1.34
@@ -101,13 +101,19 @@
/* End System Headers */
struct apr_unix_lock_methods_t {
+ unsigned int flags;
apr_status_t (*create)(apr_lock_t *, const char *);
apr_status_t (*acquire)(apr_lock_t *);
+ apr_status_t (*acquire_read)(apr_lock_t *);
+ apr_status_t (*acquire_write)(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;
+
+/* bit values for flags field in apr_unix_lock_methods_t */
+#define APR_PROCESS_LOCK_MECH_IS_GLOBAL 1
#if APR_HAS_SYSVSEM_SERIALIZE
extern const apr_unix_lock_methods_t apr_unix_sysv_methods;
1.49 +24 -0 apr/locks/unix/crossproc.c
Index: crossproc.c
===================================================================
RCS file: /home/cvs/apr/locks/unix/crossproc.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- crossproc.c 2001/06/26 17:15:51 1.48
+++ crossproc.c 2001/06/29 17:53:32 1.49
@@ -151,8 +151,15 @@
const apr_unix_lock_methods_t apr_unix_sysv_methods =
{
+#if APR_PROCESS_LOCK_IS_GLOBAL || !APR_HAS_THREADS
+ APR_PROCESS_LOCK_MECH_IS_GLOBAL,
+#else
+ 0,
+#endif
sysv_create,
sysv_acquire,
+ NULL, /* no rw lock */
+ NULL, /* no rw lock */
sysv_release,
sysv_destroy,
sysv_child_init
@@ -285,8 +292,11 @@
const apr_unix_lock_methods_t apr_unix_proc_pthread_methods =
{
+ APR_PROCESS_LOCK_MECH_IS_GLOBAL,
proc_pthread_create,
proc_pthread_acquire,
+ NULL, /* no rw lock */
+ NULL, /* no rw lock */
proc_pthread_release,
proc_pthread_destroy,
proc_pthread_child_init
@@ -394,8 +404,15 @@
const apr_unix_lock_methods_t apr_unix_fcntl_methods =
{
+#if APR_PROCESS_LOCK_IS_GLOBAL || !APR_HAS_THREADS
+ APR_PROCESS_LOCK_MECH_IS_GLOBAL,
+#else
+ 0,
+#endif
fcntl_create,
fcntl_acquire,
+ NULL, /* no rw lock */
+ NULL, /* no rw lock */
fcntl_release,
fcntl_destroy,
fcntl_child_init
@@ -502,8 +519,15 @@
const apr_unix_lock_methods_t apr_unix_flock_methods =
{
+#if APR_PROCESS_LOCK_IS_GLOBAL || !APR_HAS_THREADS
+ APR_PROCESS_LOCK_MECH_IS_GLOBAL,
+#else
+ 0,
+#endif
flock_create,
flock_acquire,
+ NULL, /* no rw lock */
+ NULL, /* no rw lock */
flock_release,
flock_destroy,
flock_child_init
1.25 +18 -0 apr/locks/unix/intraproc.c
Index: intraproc.c
===================================================================
RCS file: /home/cvs/apr/locks/unix/intraproc.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- intraproc.c 2001/06/25 18:53:35 1.24
+++ intraproc.c 2001/06/29 17:53:33 1.25
@@ -153,8 +153,11 @@
const apr_unix_lock_methods_t apr_unix_intra_methods =
{
+ 0,
intra_create,
intra_acquire,
+ NULL, /* no read lock concept */
+ NULL, /* no write lock concept */
intra_release,
intra_destroy,
NULL /* no child init */
@@ -168,6 +171,18 @@
return APR_SUCCESS;
}
+static apr_status_t rwlock_acquire_read(apr_lock_t *lock)
+{
+ /* XXX PTHREAD_SETS_ERRNO crap? */
+ return pthread_rwlock_rdlock(&lock->rwlock);
+}
+
+static apr_status_t rwlock_acquire_write(apr_lock_t *lock)
+{
+ /* XXX PTHREAD_SETS_ERRNO crap? */
+ return pthread_rwlock_wrlock(&lock->rwlock);
+}
+
static apr_status_t rwlock_release(apr_lock_t *lock)
{
/* XXX PTHREAD_SETS_ERRNO crap? */
@@ -182,8 +197,11 @@
const apr_unix_lock_methods_t apr_unix_rwlock_methods =
{
+ 0,
rwlock_create,
NULL, /* no standard acquire method; app better not call :) */
+ rwlock_acquire_read,
+ rwlock_acquire_write,
rwlock_release,
rwlock_destroy,
NULL /* no child init method */
1.57 +15 -33 apr/locks/unix/locks.c
Index: locks.c
===================================================================
RCS file: /home/cvs/apr/locks/unix/locks.c,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -r1.56 -r1.57
--- locks.c 2001/06/26 02:05:05 1.56
+++ locks.c 2001/06/29 17:53:35 1.57
@@ -56,7 +56,6 @@
#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;
@@ -118,13 +117,15 @@
static const struct apr_unix_lock_methods_t lockall_methods =
{
+ 0,
lockall_create,
lockall_acquire,
+ NULL, /* no read lock concept */
+ NULL, /* no write lock concept */
lockall_release,
lockall_destroy,
lockall_child_init
};
-#endif
static apr_status_t choose_method(apr_lock_t *new, apr_lockmech_e_np mech)
{
@@ -207,15 +208,12 @@
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
- new->meth = &lockall_methods;
-#endif
+ if (new->inter_meth->flags & APR_PROCESS_LOCK_MECH_IS_GLOBAL) {
+ new->meth = new->inter_meth;
+ }
+ else {
+ new->meth = &lockall_methods;
+ }
break;
case APR_CROSS_PROCESS:
new->meth = new->inter_meth;
@@ -283,30 +281,14 @@
apr_status_t apr_lock_acquire_rw(apr_lock_t *lock, apr_readerwriter_e e)
{
- apr_status_t stat = APR_SUCCESS;
-
- switch (lock->type)
+ switch (e)
{
- 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
+ case APR_READER:
+ return lock->meth->acquire_read(lock);
+ case APR_WRITER:
+ return lock->meth->acquire_write(lock);
}
-
- return stat;
+ return APR_ENOTIMPL;
}
apr_status_t apr_lock_release(apr_lock_t *lock)