You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by JF B <jf...@yahoo.com> on 2002/05/15 23:40:33 UTC
[PATCH] WIN32 implementations of apr_thread_cond_timedwait + apr_thread_cond_wait
--- apr/locks/win32/thread_cond.c Wed Mar 13 15:39:22 2002
+++ apr_new/locks/win32/thread_cond.c Wed May 8 18:25:52 2002
@@ -85,28 +85,33 @@
{
DWORD rv;
- while (1) {
- WaitForSingleObject(cond->mutex, INFINITE);
- cond->num_waiting++;
- ReleaseMutex(cond->mutex);
+ WaitForSingleObject(cond->mutex, INFINITE);
+ cond->num_waiting++;
+ ReleaseMutex(cond->mutex);
- apr_thread_mutex_unlock(mutex);
+ apr_thread_mutex_unlock(mutex);
+ while (1) {
rv = WaitForSingleObject(cond->event, INFINITE);
- cond->num_waiting--;
if (rv == WAIT_FAILED) {
+ apr_thread_mutex_lock(mutex);
return apr_get_os_error();
}
+ WaitForSingleObject(cond->mutex, INFINITE);
+ cond->num_waiting--;
if (cond->signal_all) {
if (cond->num_waiting == 0) {
ResetEvent(cond->event);
}
+ ReleaseMutex(cond->mutex);
break;
}
if (cond->signalled) {
cond->signalled = 0;
ResetEvent(cond->event);
+ ReleaseMutex(cond->mutex);
break;
}
+ cond->num_waiting++;
ReleaseMutex(cond->mutex);
}
apr_thread_mutex_lock(mutex);
@@ -115,8 +120,52 @@
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_interval_time_t timeout)
+{
+ DWORD rv;
+ DWORD time_left = (DWORD)(timeout / 1000);
+ apr_time_t time_begin;
+
+ WaitForSingleObject(cond->mutex, INFINITE);
+ cond->num_waiting++;
+ ReleaseMutex(cond->mutex);
+
+ apr_thread_mutex_unlock(mutex);
+ time_begin = apr_time_now();
+ while (1) {
+ rv = WaitForSingleObject(cond->event, time_left);
+ if (rv == WAIT_FAILED) {
+ apr_thread_mutex_lock(mutex);
+ return apr_get_os_error();
+ }
+ if (rv == WAIT_TIMEOUT) {
+ apr_thread_mutex_lock(mutex);
+ return APR_TIMEUP;
+ }
+ time_left -= (DWORD)((apr_time_now() - time_begin) / 1000);
+ if (time_left < 0) {
+ time_left = 0;
+ }
+ WaitForSingleObject(cond->mutex, INFINITE);
+ cond->num_waiting--;
+ if (cond->signal_all) {
+ if (cond->num_waiting == 0) {
+ ResetEvent(cond->event);
+ }
+ ReleaseMutex(cond->mutex);
+ break;
+ }
+ if (cond->signalled) {
+ cond->signalled = 0;
+ ResetEvent(cond->event);
+ ReleaseMutex(cond->mutex);
+ break;
+ }
+ cond->num_waiting++;
+ ReleaseMutex(cond->mutex);
+ }
+ apr_thread_mutex_lock(mutex);
+ return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_cond_signal(apr_thread_cond_t *cond)
---------------------------------
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
Re: [PATCH] WIN32 implementations of apr_thread_cond_timedwait + apr_thread_cond_wait
Posted by Aaron Bannert <aa...@clove.org>.
On Wed, May 15, 2002 at 02:40:33PM -0700, JF B wrote:
> --- apr/locks/win32/thread_cond.c Wed Mar 13 15:39:22 2002
> +++ apr_new/locks/win32/thread_cond.c Wed May 8 18:25:52 2002
...
Cool! Could you explain why you thought apr_thread_cond_wait() needed
to be altered? I'll try to give this an eyeball review later today.
-aaron
Re: [PATCH] WIN32 implementations of apr_thread_cond_timedwait
+ apr_thread_cond_wait
Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
At 04:40 PM 5/15/2002, JF B wrote:
>--- apr/locks/win32/thread_cond.c Wed Mar 13 15:39:22 2002
>+++ apr_new/locks/win32/thread_cond.c Wed May 8 18:25:52 2002
>@@ -85,28 +85,33 @@
> {
>[...]
> apr_thread_mutex_lock(mutex);
>@@ -115,8 +120,52 @@
>
> APR_DECLARE(apr_status_t) apr_thread_cond_timedwait(apr_thread_cond_t *cond,
> &n<http://rd.yahoo.com/welcome/*http://launch.yahoo.com>LAUNCH -
> Your Yahoo! Music Experience
Outch. Seems the end of that patch was corrupt or truncated. Please
repost, this
time with an explanation of the bug or race you fixed, and any potential
new race
conditions.