Mercurial > dwindows
changeset 1155:e6a2f57c0842
Added support for infinite wait for dw_event_wait() on Mac, Unix and Windows.
Return code cleanup for dw_event_* and dw_named_event_* on Windows.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 15 Sep 2011 03:13:50 +0000 |
parents | 052f01522c53 |
children | 03b6d9fdfac0 |
files | gtk/dw.c gtk3/dw.c mac/dw.m win/dw.c |
diffstat | 4 files changed, 87 insertions(+), 90 deletions(-) [+] |
line wrap: on
line diff
--- a/gtk/dw.c Tue Sep 13 16:58:37 2011 +0000 +++ b/gtk/dw.c Thu Sep 15 03:13:50 2011 +0000 @@ -8600,8 +8600,6 @@ int dw_event_wait(HEV eve, unsigned long timeout) { int rc; - struct timeval now; - struct timespec timeo; if(!eve) return DW_ERROR_NON_INIT; @@ -8610,10 +8608,19 @@ return DW_ERROR_GENERAL; pthread_mutex_lock (&(eve->mutex)); - gettimeofday(&now, 0); - timeo.tv_sec = now.tv_sec + (timeout / 1000); - timeo.tv_nsec = now.tv_usec * 1000; - rc = pthread_cond_timedwait (&(eve->event), &(eve->mutex), &timeo); + if(time != -1) + { + struct timeval now; + struct timespec timeo; + + gettimeofday(&now, 0); + timeo.tv_sec = now.tv_sec + (timeout / 1000); + timeo.tv_nsec = now.tv_usec * 1000; + rc = pthread_cond_timedwait(&(eve->event), &(eve->mutex), &timeo); + } + else + rc = pthread_cond_wait(&(eve->event), &(eve->mutex)); + pthread_mutex_unlock (&(eve->mutex)); if(!rc) return DW_ERROR_NONE; @@ -8918,7 +8925,7 @@ int dw_named_event_wait(HEV eve, unsigned long timeout) { fd_set rd; - struct timeval tv, *useme; + struct timeval tv, *useme = NULL; int retval = 0; char tmp; @@ -8926,9 +8933,7 @@ return DW_ERROR_NON_INIT; /* Set the timout or infinite */ - if(timeout == -1) - useme = NULL; - else + if(timeout != -1) { tv.tv_sec = timeout / 1000; tv.tv_usec = timeout % 1000;
--- a/gtk3/dw.c Tue Sep 13 16:58:37 2011 +0000 +++ b/gtk3/dw.c Thu Sep 15 03:13:50 2011 +0000 @@ -7478,8 +7478,6 @@ int dw_event_wait(HEV eve, unsigned long timeout) { int rc; - struct timeval now; - struct timespec timeo; if(!eve) return DW_ERROR_NON_INIT; @@ -7488,10 +7486,19 @@ return DW_ERROR_GENERAL; pthread_mutex_lock (&(eve->mutex)); - gettimeofday(&now, 0); - timeo.tv_sec = now.tv_sec + (timeout / 1000); - timeo.tv_nsec = now.tv_usec * 1000; - rc = pthread_cond_timedwait (&(eve->event), &(eve->mutex), &timeo); + if(time != -1) + { + struct timeval now; + struct timespec timeo; + + gettimeofday(&now, 0); + timeo.tv_sec = now.tv_sec + (timeout / 1000); + timeo.tv_nsec = now.tv_usec * 1000; + rc = pthread_cond_timedwait(&(eve->event), &(eve->mutex), &timeo); + } + else + rc = pthread_cond_wait(&(eve->event), &(eve->mutex)); + pthread_mutex_unlock (&(eve->mutex)); if(!rc) return DW_ERROR_NONE; @@ -7794,7 +7801,7 @@ int dw_named_event_wait(HEV eve, unsigned long timeout) { fd_set rd; - struct timeval tv, *useme; + struct timeval tv, *useme = NULL; int retval = 0; char tmp; @@ -7802,9 +7809,7 @@ return DW_ERROR_NON_INIT; /* Set the timout or infinite */ - if(timeout == -1) - useme = NULL; - else + if(timeout != -1) { tv.tv_sec = timeout / 1000; tv.tv_usec = timeout % 1000;
--- a/mac/dw.m Tue Sep 13 16:58:37 2011 +0000 +++ b/mac/dw.m Thu Sep 15 03:13:50 2011 +0000 @@ -8533,27 +8533,33 @@ */ int dw_event_wait(HEV eve, unsigned long timeout) { - int rc; - struct timeval now; - struct timespec timeo; - - if(!eve) - return DW_ERROR_NON_INIT; - - if(eve->posted) - return DW_ERROR_GENERAL; - - pthread_mutex_lock (&(eve->mutex)); - gettimeofday(&now, 0); - timeo.tv_sec = now.tv_sec + (timeout / 1000); - timeo.tv_nsec = now.tv_usec * 1000; - rc = pthread_cond_timedwait (&(eve->event), &(eve->mutex), &timeo); - pthread_mutex_unlock (&(eve->mutex)); - if(!rc) - return DW_ERROR_NONE; - if(rc == ETIMEDOUT) - return DW_ERROR_TIMEOUT; - return DW_ERROR_GENERAL; + int rc; + + if(!eve) + return DW_ERROR_NON_INIT; + + if(eve->posted) + return DW_ERROR_GENERAL; + + pthread_mutex_lock (&(eve->mutex)); + if(timeout != -1) + { + struct timeval now; + struct timespec timeo; + + gettimeofday(&now, 0); + timeo.tv_sec = now.tv_sec + (timeout / 1000); + timeo.tv_nsec = now.tv_usec * 1000; + rc = pthread_cond_timedwait(&(eve->event), &(eve->mutex), &timeo); + } + else + rc = pthread_cond_wait(&(eve->event), &(eve->mutex)); + pthread_mutex_unlock (&(eve->mutex)); + if(!rc) + return DW_ERROR_NONE; + if(rc == ETIMEDOUT) + return DW_ERROR_TIMEOUT; + return DW_ERROR_GENERAL; } /* @@ -8872,7 +8878,7 @@ int dw_named_event_wait(HEV eve, unsigned long timeout) { fd_set rd; - struct timeval tv, *useme; + struct timeval tv, *useme = NULL; int retval = 0; char tmp; @@ -8880,9 +8886,7 @@ return DW_ERROR_NON_INIT; /* Set the timout or infinite */ - if(timeout == -1) - useme = NULL; - else + if(timeout != -1) { tv.tv_sec = timeout / 1000; tv.tv_usec = (int)timeout % 1000;
--- a/win/dw.c Tue Sep 13 16:58:37 2011 +0000 +++ b/win/dw.c Thu Sep 15 03:13:50 2011 +0000 @@ -9229,7 +9229,9 @@ */ int API dw_event_reset(HEV eve) { - return ResetEvent(eve); + if(ResetEvent(eve)) + return DW_ERROR_NONE; + return DW_ERROR_GENERAL; } /* @@ -9240,7 +9242,9 @@ */ int API dw_event_post(HEV eve) { - return (SetEvent(eve) == 0); + if(SetEvent(eve)) + return DW_ERROR_NONE; + return DW_ERROR_GENERAL; } /* @@ -9253,13 +9257,13 @@ { int rc; - rc = WaitForSingleObject(eve, timeout); + rc = WaitForSingleObject(eve, timeout != -1 ? timeout : INFINITE); if(rc == WAIT_OBJECT_0) return DW_ERROR_NONE; if(rc == WAIT_TIMEOUT) return DW_ERROR_TIMEOUT; if(rc == WAIT_ABANDONED) - return DW_ERROR_NON_INIT; + return DW_ERROR_INTERRUPT; return DW_ERROR_GENERAL; } @@ -9270,9 +9274,9 @@ */ int API dw_event_close(HEV *eve) { - if(eve) - return (CloseHandle(*eve) == 0); - return DW_ERROR_NONE; + if(eve && CloseHandle(*eve)) + return DW_ERROR_NONE; + return DW_ERROR_GENERAL; } /* Create a named event semaphore which can be @@ -9311,13 +9315,9 @@ */ int API dw_named_event_reset(HEV eve) { - int rc; - - rc = ResetEvent(eve); - if(!rc) - return DW_ERROR_GENERAL; - - return DW_ERROR_NONE; + if(ResetEvent(eve)) + return DW_ERROR_NONE; + return DW_ERROR_GENERAL; } /* Sets the posted state of an event semaphore, any threads @@ -9328,13 +9328,9 @@ */ int API dw_named_event_post(HEV eve) { - int rc; - - rc = SetEvent(eve); - if(!rc) - return 1; - - return 0; + if(SetEvent(eve)) + DW_ERROR_NONE; + return DW_ERROR_GENERAL; } /* Waits on the specified semaphore until it becomes @@ -9349,23 +9345,14 @@ { int rc; - rc = WaitForSingleObject(eve, timeout); - switch (rc) - { - case WAIT_FAILED: - rc = DW_ERROR_TIMEOUT; - break; - - case WAIT_ABANDONED: - rc = DW_ERROR_INTERRUPT; - break; - - case WAIT_OBJECT_0: - rc = 0; - break; - } - - return rc; + rc = WaitForSingleObject(eve, timeout != -1 ? timeout : INFINITE); + if(rc == WAIT_OBJECT_0) + return DW_ERROR_NONE; + if(rc == WAIT_TIMEOUT) + return DW_ERROR_TIMEOUT; + if(rc == WAIT_ABANDONED) + return DW_ERROR_INTERRUPT; + return DW_ERROR_GENERAL; } /* Release this semaphore, if there are no more open @@ -9376,13 +9363,9 @@ */ int API dw_named_event_close(HEV eve) { - int rc; - - rc = CloseHandle(eve); - if(!rc) - return 1; - - return 0; + if(CloseHandle(eve)) + return DW_ERROR_NONE; + return DW_ERROR_GENERAL; } /*