Waiting for Multiple Events for Read/Write
In this scenario, multiple endpoints are opened, and multiple event notifiers are created
A connection must be established between two endpoint processes before reading the data.
This can be done by calling NvSciIpcGetEventSafe()
.
The event handling mechanism is similar to waiting for a single event, but it can wait for multiple events.
Check the newEventArray
boolean array returned by
WaitForMultipleEvents()
or
WaitForMultipleEventsExt()
to determine which event is
notified.
WaitForMultipeEventsExt()
has the same functionality as
WaitForMultipeEvents()
and extends to be used in case no notifier
array is available but events want to be serviced with the event handler when the event
arrives.
WaitForEvent() is an event-blocking call. It must be called from a single thread only.
To process the write event in a loop, add WRITE event check routine and
NvSciIpcWriteSafe()
.
Following is a list of supported events:
- Multiple native events
- Multiple local events
- Multiple native and local events
Wait for multiple events for read/write
#define NUM_OF_EVENTNOTIFIER 2
NvSciEventLoopService *eventLoopService;
NvSciIpcEndpoint ipcEndpointArray[NUM_OF_EVENTNOTIFIER];
NvSciEventNotifier *eventNotifierArray[NUM_OF_EVENTNOTIFIER];
bool newEventArray[NUM_OF_EVENTNOTIFIER];
struct NvSciIpcEndpointInfo infoArray; /* Assuming two endpoints have the same info */
int64_t timeout;
uint32_t event = 0;
void *buf;
int32_t buf_size, bytes, inx;
int retval;
NvSciError err;
bool gotEvent;
timeout = NV_SCI_EVENT_INFINITE_WAIT;
buf = malloc(info.frame_size);
if (buf == NULL) {
goto fail;
}
buf_size = info.frame_size;
for (inx = 0; inx < NUM_OF_EVENTNOTIFIER; inx++) {
newEventArray[inx] = true;
}
while (1) {
gotEvent = false;
for (inx = 0; inx < NUM_OF_EVENTNOTIFIER; inx++) {
if (newEventArray[inx]) {
err = NvSciIpcGetEventSafe(ipcEndpointArray[inx], &event);
if (err != NvSciError_Success) {
goto fail;
}
if (event & NV_SCI_IPC_EVENT_READ)) {
/* Assuming buf contains pointer to area where frame is read.
* buf_size contains the size of data. It should be less than
* Endpoint frame size.
*/
err = NvSciIpcReadSafe(ipcEndpointArray[inx], buf, buf_size, &bytes);
if(err != NvSciError_Success) {
printf("error in reading endpoint\n");
goto fail;
}
gotEvent = true;
}
}
}
if (gotEvent) {
continue;
}
err = eventLoopService->WaitForMultipleEvents(eventNotifierArray,
NUM_OF_EVENTNOTIFIER, timeout, newEventArray);
if(err != NvSciError_Success) {
printf("error in waiting event\n");
goto fail;
}
}