Files
graphene/Pal/test/Select.c
Dmitrii Kuvaiskii 40c08ff75a [LibOS, Pal/{Linux,Linux-SGX}] Remove DkObjectsWaitAny()
Now Graphene supports an improved version of DkObjectsWaitAny() with
correct polling semantics -- DkObjectsWaitEvents(). This makes
DkObjectsWaitAny() obsolete. This commit removes DkObjectsWaitAny()
and replaces it with:
- DkSynchronizationObjectWait() to wait on a single synchronization
  object like mutex or event.
- DkStreamsWaitEvents() to wait on stream-like objects (this is the
  renamed DkObjectsWaitEvents()).

The corresponding tests are fixed to use the new PAL interfaces.
Also, IPC helper and Async helper threads are significantly refactored
to make better use of DkStreamsWaitEvents().
2020-01-14 20:31:40 -08:00

51 lines
1.2 KiB
C

#include "pal.h"
#include "pal_debug.h"
PAL_HANDLE wakeup;
int thread_func(void* args) {
pal_printf("Enter thread\n");
DkThreadDelayExecution(3000000);
pal_printf("Thread sets event\n");
char byte = 0;
DkStreamWrite(wakeup, 0, 1, &byte, NULL);
pal_printf("Leave thread\n");
return 0;
}
int main(int argc, char** argv) {
pal_printf("Enter main thread\n");
PAL_HANDLE handles[3];
handles[0] = DkStreamOpen("pipe:", PAL_ACCESS_RDWR, 0, 0, 0);
handles[1] = DkStreamOpen("pipe:", PAL_ACCESS_RDWR, 0, 0, 0);
handles[2] = DkStreamOpen("pipe:", PAL_ACCESS_RDWR, 0, 0, 0);
wakeup = handles[2];
PAL_HANDLE thd = DkThreadCreate(&thread_func, NULL);
if (!thd) {
pal_printf("DkThreadCreate failed\n");
return -1;
}
pal_printf("Waiting on event\n");
PAL_FLG events[3] = {PAL_WAIT_READ, PAL_WAIT_READ, PAL_WAIT_READ};
PAL_FLG revents[3] = {0, 0, 0};
PAL_BOL polled = DkStreamsWaitEvents(3, handles, events, revents, NO_TIMEOUT);
if (!polled) {
pal_printf("DkStreamsWaitEvents did not return any events\n");
return -1;
}
if (revents[2])
pal_printf("Event was called\n");
pal_printf("Leave main thread\n");
return 0;
}