Remove unsafe cancellation code from events
This commit is contained in:
parent
ac52faa6c2
commit
8b6ca3d89b
2 changed files with 2 additions and 17 deletions
|
|
@ -239,7 +239,6 @@ int PltCreateEvent(PLT_EVENT* event) {
|
||||||
pthread_mutex_init(&event->mutex, NULL);
|
pthread_mutex_init(&event->mutex, NULL);
|
||||||
pthread_cond_init(&event->cond, NULL);
|
pthread_cond_init(&event->cond, NULL);
|
||||||
event->signalled = 0;
|
event->signalled = 0;
|
||||||
event->cancelled = 0;
|
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
@ -248,12 +247,6 @@ void PltCloseEvent(PLT_EVENT* event) {
|
||||||
#if defined(LC_WINDOWS)
|
#if defined(LC_WINDOWS)
|
||||||
CloseHandle(*event);
|
CloseHandle(*event);
|
||||||
#else
|
#else
|
||||||
// Wake up anyone going to wait on this event.
|
|
||||||
// There's an inherent race condition in this technique
|
|
||||||
// but it shouldn't be too problematic for our purposes.
|
|
||||||
event->cancelled = 1;
|
|
||||||
pthread_cond_broadcast(&event->cond);
|
|
||||||
|
|
||||||
pthread_mutex_destroy(&event->mutex);
|
pthread_mutex_destroy(&event->mutex);
|
||||||
pthread_cond_destroy(&event->cond);
|
pthread_cond_destroy(&event->cond);
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -295,20 +288,13 @@ int PltWaitForEvent(PLT_EVENT* event) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (event->cancelled) {
|
|
||||||
return PLT_WAIT_INTERRUPTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_mutex_lock(&event->mutex);
|
pthread_mutex_lock(&event->mutex);
|
||||||
while (!event->signalled && !event->cancelled) {
|
while (!event->signalled) {
|
||||||
pthread_cond_wait(&event->cond, &event->mutex);
|
pthread_cond_wait(&event->cond, &event->mutex);
|
||||||
}
|
}
|
||||||
ret = event->cancelled ? PLT_WAIT_INTERRUPTED : PLT_WAIT_SUCCESS;
|
|
||||||
pthread_mutex_unlock(&event->mutex);
|
pthread_mutex_unlock(&event->mutex);
|
||||||
|
|
||||||
return ret;
|
return PLT_WAIT_SUCCESS;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ typedef struct _PLT_EVENT {
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
pthread_cond_t cond;
|
pthread_cond_t cond;
|
||||||
int signalled;
|
int signalled;
|
||||||
int cancelled;
|
|
||||||
} PLT_EVENT;
|
} PLT_EVENT;
|
||||||
#else
|
#else
|
||||||
#error Unsupported platform
|
#error Unsupported platform
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue