Files
graphene/Pal/test/Event.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

50 lines
1003 B
C

#include "pal.h"
#include "pal_debug.h"
static PAL_HANDLE event1;
int count = 0;
int thread_func(void* args) {
DkThreadDelayExecution(1000);
pal_printf("In thread 1\n");
while (count < 100)
count++;
DkEventSet(event1);
DkThreadExit(/*clear_child_tid=*/NULL);
return 0; /* NOTREACHED */
}
int main(int argc, char** argv) {
pal_printf("Enter main thread\n");
PAL_HANDLE thd1;
event1 = DkNotificationEventCreate(0);
if (!event1) {
pal_printf("DkNotificationEventCreate failed\n");
return -1;
}
thd1 = DkThreadCreate(&thread_func, 0);
if (!thd1) {
pal_printf("DkThreadCreate failed\n");
return -1;
}
/* wait till thread thd1 is done */
DkSynchronizationObjectWait(event1, NO_TIMEOUT);
if (count != 100)
return -1;
/* this wait should return immediately */
DkSynchronizationObjectWait(event1, NO_TIMEOUT);
pal_printf("Success, leave main thread\n");
return 0;
}