Mercurial > dwindows
comparison gtk3/dw.c @ 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 | 03b6d9fdfac0 |
comparison
equal
deleted
inserted
replaced
1154:052f01522c53 | 1155:e6a2f57c0842 |
---|---|
7476 * eve: The handle to the event returned by dw_event_new(). | 7476 * eve: The handle to the event returned by dw_event_new(). |
7477 */ | 7477 */ |
7478 int dw_event_wait(HEV eve, unsigned long timeout) | 7478 int dw_event_wait(HEV eve, unsigned long timeout) |
7479 { | 7479 { |
7480 int rc; | 7480 int rc; |
7481 struct timeval now; | |
7482 struct timespec timeo; | |
7483 | 7481 |
7484 if(!eve) | 7482 if(!eve) |
7485 return DW_ERROR_NON_INIT; | 7483 return DW_ERROR_NON_INIT; |
7486 | 7484 |
7487 if(eve->posted) | 7485 if(eve->posted) |
7488 return DW_ERROR_GENERAL; | 7486 return DW_ERROR_GENERAL; |
7489 | 7487 |
7490 pthread_mutex_lock (&(eve->mutex)); | 7488 pthread_mutex_lock (&(eve->mutex)); |
7491 gettimeofday(&now, 0); | 7489 if(time != -1) |
7492 timeo.tv_sec = now.tv_sec + (timeout / 1000); | 7490 { |
7493 timeo.tv_nsec = now.tv_usec * 1000; | 7491 struct timeval now; |
7494 rc = pthread_cond_timedwait (&(eve->event), &(eve->mutex), &timeo); | 7492 struct timespec timeo; |
7493 | |
7494 gettimeofday(&now, 0); | |
7495 timeo.tv_sec = now.tv_sec + (timeout / 1000); | |
7496 timeo.tv_nsec = now.tv_usec * 1000; | |
7497 rc = pthread_cond_timedwait(&(eve->event), &(eve->mutex), &timeo); | |
7498 } | |
7499 else | |
7500 rc = pthread_cond_wait(&(eve->event), &(eve->mutex)); | |
7501 | |
7495 pthread_mutex_unlock (&(eve->mutex)); | 7502 pthread_mutex_unlock (&(eve->mutex)); |
7496 if(!rc) | 7503 if(!rc) |
7497 return DW_ERROR_NONE; | 7504 return DW_ERROR_NONE; |
7498 if(rc == ETIMEDOUT) | 7505 if(rc == ETIMEDOUT) |
7499 return DW_ERROR_TIMEOUT; | 7506 return DW_ERROR_TIMEOUT; |
7792 * or -1 if indefinite. | 7799 * or -1 if indefinite. |
7793 */ | 7800 */ |
7794 int dw_named_event_wait(HEV eve, unsigned long timeout) | 7801 int dw_named_event_wait(HEV eve, unsigned long timeout) |
7795 { | 7802 { |
7796 fd_set rd; | 7803 fd_set rd; |
7797 struct timeval tv, *useme; | 7804 struct timeval tv, *useme = NULL; |
7798 int retval = 0; | 7805 int retval = 0; |
7799 char tmp; | 7806 char tmp; |
7800 | 7807 |
7801 if(GPOINTER_TO_INT(eve) < 0) | 7808 if(GPOINTER_TO_INT(eve) < 0) |
7802 return DW_ERROR_NON_INIT; | 7809 return DW_ERROR_NON_INIT; |
7803 | 7810 |
7804 /* Set the timout or infinite */ | 7811 /* Set the timout or infinite */ |
7805 if(timeout == -1) | 7812 if(timeout != -1) |
7806 useme = NULL; | |
7807 else | |
7808 { | 7813 { |
7809 tv.tv_sec = timeout / 1000; | 7814 tv.tv_sec = timeout / 1000; |
7810 tv.tv_usec = timeout % 1000; | 7815 tv.tv_usec = timeout % 1000; |
7811 | 7816 |
7812 useme = &tv; | 7817 useme = &tv; |