You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by aa...@apache.org on 2001/10/12 03:05:03 UTC
cvs commit: apr/locks/win32 thread_cond.c
aaron 01/10/11 18:05:03
Modified: include apr_thread_cond.h
locks/beos thread_cond.c
locks/netware thread_cond.c
locks/os2 thread_cond.c
locks/unix thread_cond.c
locks/win32 thread_cond.c
Log:
Adds apr_thread_cond_timedwait() interface to new lock API.
Implements it for UNIX, stubs elsewhere.
Revision Changes Path
1.4 +22 -2 apr/include/apr_thread_cond.h
Index: apr_thread_cond.h
===================================================================
RCS file: /home/cvs/apr/include/apr_thread_cond.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- apr_thread_cond.h 2001/09/29 05:05:41 1.3
+++ apr_thread_cond.h 2001/10/12 01:05:02 1.4
@@ -58,6 +58,7 @@
#include "apr.h"
#include "apr_pools.h"
#include "apr_errno.h"
+#include "apr_time.h"
#include "apr_thread_mutex.h"
#ifdef __cplusplus
@@ -90,6 +91,7 @@
*/
APR_DECLARE(apr_status_t) apr_thread_cond_create(apr_thread_cond_t **cond,
apr_pool_t *pool);
+
/**
* Put the active calling thread to sleep until signaled to wake up. Each
* condition variable must be associated with a mutex, and that mutex must
@@ -105,8 +107,25 @@
APR_DECLARE(apr_status_t) apr_thread_cond_wait(apr_thread_cond_t *cond,
apr_thread_mutex_t *mutex);
-/* XXX: Should we add apr_thread_cond_timedwait()? Can it be done on all
- * platforms? -aaron */
+/**
+ * Put the active calling thread to sleep until signaled to wake up or
+ * the timeout is reached. Each condition variable must be associated
+ * with a mutex, and that mutex must be locked before calling this
+ * function, or the behavior will be undefined. As the calling thread
+ * is put to sleep, the given mutex will be simultaneously released;
+ * and as this thread wakes up the lock is again simultaneously acquired.
+ * @param cond the condition variable on which to block.
+ * @param mutex the mutex that must be locked upon entering this function,
+ * is released while the thread is asleep, and is again acquired before
+ * returning from this function.
+ * @param timeout The amount of time in microseconds to wait. This is
+ * a maximum, not a minimum. If the condition is signaled, we
+ * will wake up before this time, otherwise the error APR_TIMEUP
+ * is returned.
+ */
+APR_DECLARE(apr_status_t) apr_thread_cond_timedwait(apr_thread_cond_t *cond,
+ apr_thread_mutex_t *mutex,
+ apr_interval_time_t timeout);
/**
* Signals a singla thread, if one exists, that is blocking on the given
@@ -116,6 +135,7 @@
* @param cond the condition variable on which to produce the signal.
*/
APR_DECLARE(apr_status_t) apr_thread_cond_signal(apr_thread_cond_t *cond);
+
/**
* Signals all threads blocking on the given condition variable.
* Each thread that was signaled is then schedule to wake up and acquire
1.3 +6 -0 apr/locks/beos/thread_cond.c
Index: thread_cond.c
===================================================================
RCS file: /home/cvs/apr/locks/beos/thread_cond.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- thread_cond.c 2001/09/29 05:05:41 1.2
+++ thread_cond.c 2001/10/12 01:05:02 1.3
@@ -74,6 +74,12 @@
return APR_ENOTIMPL;
}
+APR_DECLARE(apr_status_t) apr_thread_cond_timedwait(apr_thread_cond_t *cond,
+ apr_thread_mutex_t *mutex,
+ apr_interval_time_t timeout){
+ return APR_ENOTIMPL;
+}
+
APR_DECLARE(apr_status_t) apr_thread_cond_signal(apr_thread_cond_t *cond)
{
return APR_ENOTIMPL;
1.4 +6 -0 apr/locks/netware/thread_cond.c
Index: thread_cond.c
===================================================================
RCS file: /home/cvs/apr/locks/netware/thread_cond.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- thread_cond.c 2001/10/04 21:01:05 1.3
+++ thread_cond.c 2001/10/12 01:05:02 1.4
@@ -100,6 +100,12 @@
return APR_SUCCESS;
}
+APR_DECLARE(apr_status_t) apr_thread_cond_timedwait(apr_thread_cond_t *cond,
+ apr_thread_mutex_t *mutex,
+ apr_interval_time_t timeout){
+ return APR_ENOTIMPL;
+}
+
APR_DECLARE(apr_status_t) apr_thread_cond_signal(apr_thread_cond_t *cond)
{
NXCondSignal(cond->cond);
1.3 +6 -0 apr/locks/os2/thread_cond.c
Index: thread_cond.c
===================================================================
RCS file: /home/cvs/apr/locks/os2/thread_cond.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- thread_cond.c 2001/09/29 05:05:41 1.2
+++ thread_cond.c 2001/10/12 01:05:02 1.3
@@ -73,6 +73,12 @@
return APR_ENOTIMPL;
}
+APR_DECLARE(apr_status_t) apr_thread_cond_timedwait(apr_thread_cond_t *cond,
+ apr_thread_mutex_t *mutex,
+ apr_interval_time_t timeout){
+ return APR_ENOTIMPL;
+}
+
APR_DECLARE(apr_status_t) apr_thread_cond_signal(apr_thread_cond_t *cond)
{
return APR_ENOTIMPL;
1.4 +25 -0 apr/locks/unix/thread_cond.c
Index: thread_cond.c
===================================================================
RCS file: /home/cvs/apr/locks/unix/thread_cond.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- thread_cond.c 2001/09/29 05:05:41 1.3
+++ thread_cond.c 2001/10/12 01:05:02 1.4
@@ -124,6 +124,31 @@
return stat;
}
+APR_DECLARE(apr_status_t) apr_thread_cond_timedwait(apr_thread_cond_t *cond,
+ apr_thread_mutex_t *mutex,
+ apr_interval_time_t timeout)
+{
+ apr_status_t stat;
+ apr_time_t then;
+ struct timespec abstime;
+
+ then = apr_time_now() + timeout;
+ abstime.tv_sec = then / APR_USEC_PER_SEC;
+ abstime.tv_nsec = (then % APR_USEC_PER_SEC) * 1000; /* nanoseconds */
+
+ stat = pthread_cond_timedwait(cond->cond, &mutex->mutex, &abstime);
+#ifdef PTHREAD_SETS_ERRNO
+ if (stat) {
+ stat = errno;
+ }
+#endif
+ if (ETIMEDOUT == stat) {
+ return APR_TIMEUP;
+ }
+ return stat;
+}
+
+
APR_DECLARE(apr_status_t) apr_thread_cond_signal(apr_thread_cond_t *cond)
{
apr_status_t stat;
1.5 +6 -0 apr/locks/win32/thread_cond.c
Index: thread_cond.c
===================================================================
RCS file: /home/cvs/apr/locks/win32/thread_cond.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- thread_cond.c 2001/09/29 05:05:41 1.4
+++ thread_cond.c 2001/10/12 01:05:03 1.5
@@ -113,6 +113,12 @@
return APR_SUCCESS;
}
+APR_DECLARE(apr_status_t) apr_thread_cond_timedwait(apr_thread_cond_t *cond,
+ apr_thread_mutex_t *mutex,
+ apr_interval_time_t timeout){
+ return APR_ENOTIMPL;
+}
+
APR_DECLARE(apr_status_t) apr_thread_cond_signal(apr_thread_cond_t *cond)
{
DWORD rv;