summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraaron <aaron@13f79535-47bb-0310-9956-ffa450edef68>2001-10-12 01:05:03 +0000
committeraaron <aaron@13f79535-47bb-0310-9956-ffa450edef68>2001-10-12 01:05:03 +0000
commit28b14d8e765a69bf0f1d60bb61b53f4536fada88 (patch)
tree57dae238d62ffcbbaaa03fa956290e884bff7648
parent7312e1d78d71b5d2be69214f6e7581ae8815705e (diff)
downloadlibapr-28b14d8e765a69bf0f1d60bb61b53f4536fada88.tar.gz
Adds apr_thread_cond_timedwait() interface to new lock API.
Implements it for UNIX, stubs elsewhere. git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@62419 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--include/apr_thread_cond.h24
-rw-r--r--locks/beos/thread_cond.c6
-rw-r--r--locks/netware/thread_cond.c6
-rw-r--r--locks/os2/thread_cond.c6
-rw-r--r--locks/unix/thread_cond.c25
-rw-r--r--locks/win32/thread_cond.c6
6 files changed, 71 insertions, 2 deletions
diff --git a/include/apr_thread_cond.h b/include/apr_thread_cond.h
index 65b6f8deb..ea438babb 100644
--- a/include/apr_thread_cond.h
+++ b/include/apr_thread_cond.h
@@ -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 @@ typedef struct apr_thread_cond_t apr_thread_cond_t;
*/
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_create(apr_thread_cond_t **cond,
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 @@ APR_DECLARE(apr_status_t) apr_thread_cond_wait(apr_thread_cond_t *cond,
* @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
diff --git a/locks/beos/thread_cond.c b/locks/beos/thread_cond.c
index 0d1de6cd7..30a4a25c4 100644
--- a/locks/beos/thread_cond.c
+++ b/locks/beos/thread_cond.c
@@ -74,6 +74,12 @@ APR_DECLARE(apr_status_t) apr_thread_cond_wait(apr_thread_cond_t *cond,
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;
diff --git a/locks/netware/thread_cond.c b/locks/netware/thread_cond.c
index a57935bea..d5562311e 100644
--- a/locks/netware/thread_cond.c
+++ b/locks/netware/thread_cond.c
@@ -100,6 +100,12 @@ APR_DECLARE(apr_status_t) apr_thread_cond_wait(apr_thread_cond_t *cond,
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);
diff --git a/locks/os2/thread_cond.c b/locks/os2/thread_cond.c
index 94d91e941..308005646 100644
--- a/locks/os2/thread_cond.c
+++ b/locks/os2/thread_cond.c
@@ -73,6 +73,12 @@ APR_DECLARE(apr_status_t) apr_thread_cond_wait(apr_thread_cond_t *cond,
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;
diff --git a/locks/unix/thread_cond.c b/locks/unix/thread_cond.c
index 3c7ad6fa7..0a107569a 100644
--- a/locks/unix/thread_cond.c
+++ b/locks/unix/thread_cond.c
@@ -124,6 +124,31 @@ APR_DECLARE(apr_status_t) apr_thread_cond_wait(apr_thread_cond_t *cond,
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;
diff --git a/locks/win32/thread_cond.c b/locks/win32/thread_cond.c
index 032c28da0..3fa0eeead 100644
--- a/locks/win32/thread_cond.c
+++ b/locks/win32/thread_cond.c
@@ -113,6 +113,12 @@ APR_DECLARE(apr_status_t) apr_thread_cond_wait(apr_thread_cond_t *cond,
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;