Mercurial > dwindows
diff mac/dw.m @ 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 | 58b5374355ab |
children | f86f556ff29d |
line wrap: on
line diff
--- 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;