Mercurial > dwindows
comparison gtk/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 |
---|---|
8598 * eve: The handle to the event returned by dw_event_new(). | 8598 * eve: The handle to the event returned by dw_event_new(). |
8599 */ | 8599 */ |
8600 int dw_event_wait(HEV eve, unsigned long timeout) | 8600 int dw_event_wait(HEV eve, unsigned long timeout) |
8601 { | 8601 { |
8602 int rc; | 8602 int rc; |
8603 struct timeval now; | |
8604 struct timespec timeo; | |
8605 | 8603 |
8606 if(!eve) | 8604 if(!eve) |
8607 return DW_ERROR_NON_INIT; | 8605 return DW_ERROR_NON_INIT; |
8608 | 8606 |
8609 if(eve->posted) | 8607 if(eve->posted) |
8610 return DW_ERROR_GENERAL; | 8608 return DW_ERROR_GENERAL; |
8611 | 8609 |
8612 pthread_mutex_lock (&(eve->mutex)); | 8610 pthread_mutex_lock (&(eve->mutex)); |
8613 gettimeofday(&now, 0); | 8611 if(time != -1) |
8614 timeo.tv_sec = now.tv_sec + (timeout / 1000); | 8612 { |
8615 timeo.tv_nsec = now.tv_usec * 1000; | 8613 struct timeval now; |
8616 rc = pthread_cond_timedwait (&(eve->event), &(eve->mutex), &timeo); | 8614 struct timespec timeo; |
8615 | |
8616 gettimeofday(&now, 0); | |
8617 timeo.tv_sec = now.tv_sec + (timeout / 1000); | |
8618 timeo.tv_nsec = now.tv_usec * 1000; | |
8619 rc = pthread_cond_timedwait(&(eve->event), &(eve->mutex), &timeo); | |
8620 } | |
8621 else | |
8622 rc = pthread_cond_wait(&(eve->event), &(eve->mutex)); | |
8623 | |
8617 pthread_mutex_unlock (&(eve->mutex)); | 8624 pthread_mutex_unlock (&(eve->mutex)); |
8618 if(!rc) | 8625 if(!rc) |
8619 return DW_ERROR_NONE; | 8626 return DW_ERROR_NONE; |
8620 if(rc == ETIMEDOUT) | 8627 if(rc == ETIMEDOUT) |
8621 return DW_ERROR_TIMEOUT; | 8628 return DW_ERROR_TIMEOUT; |
8916 * or -1 if indefinite. | 8923 * or -1 if indefinite. |
8917 */ | 8924 */ |
8918 int dw_named_event_wait(HEV eve, unsigned long timeout) | 8925 int dw_named_event_wait(HEV eve, unsigned long timeout) |
8919 { | 8926 { |
8920 fd_set rd; | 8927 fd_set rd; |
8921 struct timeval tv, *useme; | 8928 struct timeval tv, *useme = NULL; |
8922 int retval = 0; | 8929 int retval = 0; |
8923 char tmp; | 8930 char tmp; |
8924 | 8931 |
8925 if(GPOINTER_TO_INT(eve) < 0) | 8932 if(GPOINTER_TO_INT(eve) < 0) |
8926 return DW_ERROR_NON_INIT; | 8933 return DW_ERROR_NON_INIT; |
8927 | 8934 |
8928 /* Set the timout or infinite */ | 8935 /* Set the timout or infinite */ |
8929 if(timeout == -1) | 8936 if(timeout != -1) |
8930 useme = NULL; | |
8931 else | |
8932 { | 8937 { |
8933 tv.tv_sec = timeout / 1000; | 8938 tv.tv_sec = timeout / 1000; |
8934 tv.tv_usec = timeout % 1000; | 8939 tv.tv_usec = timeout % 1000; |
8935 | 8940 |
8936 useme = &tv; | 8941 useme = &tv; |