You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by je...@apache.org on 2001/07/19 02:11:57 UTC
cvs commit: apr/locks/win32 locks.c
jerenkrantz 01/07/18 17:11:57
Modified: . CHANGES
include apr_errno.h apr_lock.h
include/arch/unix locks.h
locks/beos locks.c
locks/os2 locks.c
locks/unix crossproc.c intraproc.c locks.c
locks/win32 locks.c
Log:
Add tryacquire function to the apr_lock_* stable.
(tryacquire will not block but return APR_EBUSY if the lock is held.)
Currently, I only implemented this on Unix for intraprocess locks
(as this is the only one I need right now). Other lock types on Unix
may well be able to support them (definitely interprocess pthread
mutex!).
All others platforms should return APR_ENOTIMPL for now until their
respective gurus add it (if they need it).
I wasn't sure if we could rely on EBUSY on all platforms, so I added
the APR_EBUSY constant.
Revision Changes Path
1.121 +4 -0 apr/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/apr/CHANGES,v
retrieving revision 1.120
retrieving revision 1.121
diff -u -r1.120 -r1.121
--- CHANGES 2001/07/16 16:11:03 1.120
+++ CHANGES 2001/07/19 00:11:56 1.121
@@ -1,5 +1,9 @@
Changes with APR b1
+ *) Added apr_lock_tryacquire. It will attempt to acquire the lock, but
+ will not block if it can not acquire the lock. Returns APR_EBUSY if
+ acquistion can not happen. [Justin Erenkrantz]
+
*) Added an inherit flag to apr_socket_create and other socket creation
functions. This allows APR programs to specify that a socket should
be passed to any child processes that are created. The inherit flag
1.75 +3 -0 apr/include/apr_errno.h
Index: apr_errno.h
===================================================================
RCS file: /home/cvs/apr/include/apr_errno.h,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -r1.74 -r1.75
--- apr_errno.h 2001/06/28 05:38:38 1.74
+++ apr_errno.h 2001/07/19 00:11:56 1.75
@@ -211,6 +211,7 @@
* APR_ERELATIVE The given path was relative.
* APR_EINCOMPLETE The given path was neither relative nor absolute.
* APR_EABOVEROOT The given path was above the root path.
+ * APR_EBUSY The given lock was busy.
* </PRE>
*
* @param status The APR_status code to check.
@@ -298,6 +299,7 @@
#define APR_EINIT (APR_OS_START_STATUS + 22)
#define APR_ENOTIMPL (APR_OS_START_STATUS + 23)
#define APR_EMISMATCH (APR_OS_START_STATUS + 24)
+#define APR_EBUSY (APR_OS_START_STATUS + 25)
/* APR STATUS VALUE TESTS */
#define APR_STATUS_IS_INCHILD(s) ((s) == APR_INCHILD)
@@ -324,6 +326,7 @@
#define APR_STATUS_IS_EINIT(s) ((s) == APR_EINIT)
#define APR_STATUS_IS_ENOTIMPL(s) ((s) == APR_ENOTIMPL)
#define APR_STATUS_IS_EMISMATCH(s) ((s) == APR_EMISMATCH)
+#define APR_STATUS_IS_EBUSY(s) ((s) == APR_EBUSY)
/* APR CANONICAL ERROR VALUES */
#ifdef EACCES
1.29 +8 -0 apr/include/apr_lock.h
Index: apr_lock.h
===================================================================
RCS file: /home/cvs/apr/include/apr_lock.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- apr_lock.h 2001/06/26 02:05:00 1.28
+++ apr_lock.h 2001/07/19 00:11:56 1.29
@@ -114,6 +114,14 @@
APR_DECLARE(apr_status_t) apr_lock_acquire(apr_lock_t *lock);
/**
+ * Tries to lock a protected region.
+ * If it fails, returns APR_EBUSY. Otherwise, it returns APR_SUCCESS.
+ * @param lock The lock to set.
+ * @deffunc apr_status_t apr_lock_tryacquire(apr_lock_t *lock)
+ */
+APR_DECLARE(apr_status_t) apr_lock_tryacquire(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.
1.36 +1 -0 apr/include/arch/unix/locks.h
Index: locks.h
===================================================================
RCS file: /home/cvs/apr/include/arch/unix/locks.h,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- locks.h 2001/07/01 05:49:44 1.35
+++ locks.h 2001/07/19 00:11:56 1.36
@@ -104,6 +104,7 @@
unsigned int flags;
apr_status_t (*create)(apr_lock_t *, const char *);
apr_status_t (*acquire)(apr_lock_t *);
+ apr_status_t (*tryacquire)(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 *);
1.33 +5 -0 apr/locks/beos/locks.c
Index: locks.c
===================================================================
RCS file: /home/cvs/apr/locks/beos/locks.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- locks.c 2001/06/17 19:54:41 1.32
+++ locks.c 2001/07/19 00:11:57 1.33
@@ -328,6 +328,11 @@
return APR_SUCCESS;
}
+apr_status_t apr_lock_tryacquire(apr_lock_t *lock)
+{
+ return APR_ENOTIMPL;
+}
+
apr_status_t apr_lock_acquire_rw(apr_lock_t *lock, apr_readerwriter_e e)
{
switch (lock->type)
1.33 +5 -0 apr/locks/os2/locks.c
Index: locks.c
===================================================================
RCS file: /home/cvs/apr/locks/os2/locks.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- locks.c 2001/06/06 03:18:43 1.32
+++ locks.c 2001/07/19 00:11:57 1.33
@@ -157,6 +157,11 @@
return APR_OS2_STATUS(rc);
}
+apr_status_t apr_lock_tryacquire(apr_lock_t *lock)
+{
+ return APR_ENOTIMPL;
+}
+
apr_status_t apr_lock_acquire_rw(apr_lock_t *lock, apr_readerwriter_e e)
{
switch (lock->type) {
1.51 +4 -0 apr/locks/unix/crossproc.c
Index: crossproc.c
===================================================================
RCS file: /home/cvs/apr/locks/unix/crossproc.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -r1.50 -r1.51
--- crossproc.c 2001/07/13 06:19:01 1.50
+++ crossproc.c 2001/07/19 00:11:57 1.51
@@ -158,6 +158,7 @@
#endif
sysv_create,
sysv_acquire,
+ NULL, /* no tryacquire */
NULL, /* no rw lock */
NULL, /* no rw lock */
sysv_release,
@@ -324,6 +325,7 @@
APR_PROCESS_LOCK_MECH_IS_GLOBAL,
proc_pthread_create,
proc_pthread_acquire,
+ NULL, /* no tryacquire */
NULL, /* no rw lock */
NULL, /* no rw lock */
proc_pthread_release,
@@ -440,6 +442,7 @@
#endif
fcntl_create,
fcntl_acquire,
+ NULL, /* no tryacquire */
NULL, /* no rw lock */
NULL, /* no rw lock */
fcntl_release,
@@ -555,6 +558,7 @@
#endif
flock_create,
flock_acquire,
+ NULL, /* no tryacquire */
NULL, /* no rw lock */
NULL, /* no rw lock */
flock_release,
1.27 +18 -0 apr/locks/unix/intraproc.c
Index: intraproc.c
===================================================================
RCS file: /home/cvs/apr/locks/unix/intraproc.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- intraproc.c 2001/07/01 06:09:49 1.26
+++ intraproc.c 2001/07/19 00:11:57 1.27
@@ -126,6 +126,22 @@
return stat;
}
+static apr_status_t intra_tryacquire(apr_lock_t *lock)
+{
+ apr_status_t stat;
+
+ stat = pthread_mutex_trylock(lock->intraproc);
+#ifdef PTHREAD_SETS_ERRNO
+ if (stat) {
+ stat = errno;
+ }
+#endif
+ /* Normalize the return code. */
+ if (stat == EBUSY)
+ stat = APR_EBUSY;
+ return stat;
+}
+
static apr_status_t intra_release(apr_lock_t *lock)
{
apr_status_t status;
@@ -156,6 +172,7 @@
0,
intra_create,
intra_acquire,
+ intra_tryacquire,
NULL, /* no read lock concept */
NULL, /* no write lock concept */
intra_release,
@@ -200,6 +217,7 @@
0,
rwlock_create,
NULL, /* no standard acquire method; app better not call :) */
+ NULL, /* no standard tryacquire method; app better not call :) */
rwlock_acquire_read,
rwlock_acquire_write,
rwlock_release,
1.61 +24 -0 apr/locks/unix/locks.c
Index: locks.c
===================================================================
RCS file: /home/cvs/apr/locks/unix/locks.c,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -r1.60 -r1.61
--- locks.c 2001/07/02 20:31:44 1.60
+++ locks.c 2001/07/19 00:11:57 1.61
@@ -120,6 +120,7 @@
0,
lockall_create,
lockall_acquire,
+ NULL, /* no tryacquire concept */
NULL, /* no read lock concept */
NULL, /* no write lock concept */
lockall_release,
@@ -271,6 +272,29 @@
#endif
if ((stat = lock->meth->acquire(lock)) != APR_SUCCESS) {
+ return stat;
+ }
+
+#if APR_HAS_THREADS
+ lock->owner = apr_os_thread_current();
+ lock->owner_ref = 1;
+#endif
+
+ return APR_SUCCESS;
+}
+
+apr_status_t apr_lock_tryacquire(apr_lock_t *lock)
+{
+ apr_status_t stat;
+
+#if APR_HAS_THREADS
+ if (apr_os_thread_equal(lock->owner, apr_os_thread_current())) {
+ lock->owner_ref++;
+ return APR_SUCCESS;
+ }
+#endif
+
+ if ((stat = lock->meth->tryacquire(lock)) != APR_SUCCESS) {
return stat;
}
1.45 +5 -0 apr/locks/win32/locks.c
Index: locks.c
===================================================================
RCS file: /home/cvs/apr/locks/win32/locks.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- locks.c 2001/06/13 14:41:26 1.44
+++ locks.c 2001/07/19 00:11:57 1.45
@@ -169,6 +169,11 @@
return apr_get_os_error();
}
+APR_DECLARE(apr_status_t) apr_lock_tryacquire(apr_lock_t *lock)
+{
+ return APR_ENOTIMPL;
+}
+
APR_DECLARE(apr_status_t) apr_lock_acquire_rw(apr_lock_t *lock,
apr_readerwriter_e e)
{