NvSciSyncAttrKeyValuePair keyValue[2] = {0};
NvSciSyncModule module = NULL;
NvSciSyncAttrList waiterAttrList = NULL;
void* waiterAttrListDesc;
size_t waiterAttrListSize;
NvSciSyncObj syncObj = NULL;
void* objAndListDesc = NULL;
size_t objAndListSize = 0U;
NvSciSyncCpuWaitContext waitContext = NULL;
NvSciSyncFenceIpcExportDescriptor fenceDesc;
NvSciIpcEndpoint ipcEndpoint = 0;
bool cpuWaiter = true;
NvSciSyncAttrKeyValuePair keyValue[2] = {0};
NvSciSyncAccessPerm cpuPerm = NvSciSyncAccessPerm_WaitOnly;
err = NvSciIpcInit();
if (err != NvSciError_Success) {
goto fail;
}
err = NvSciIpcOpenEndpoint("example", &ipcEndpoint);
if (err != NvSciError_Success) {
goto fail;
}
/* Waiter Setup/Init phase */
/* Initialize the NvSciSync module */
err = NvSciSyncModuleOpen(&module);
if (err != NvSciError_Success) {
goto fail;
}
err = NvSciSyncCpuWaitContextAlloc(module, &waitContext);
if (err != NvSciError_Success) {
goto fail;
}
/* Get waiter's NvSciSyncAttrList from NvSciSync for CPU waiter */
err = NvSciSyncAttrListCreate(module, &waiterAttrList);
if (err != NvSciError_Success) {
goto fail;
}
cpuWaiter = true;
keyValue[0].attrKey = NvSciSyncAttrKey_NeedCpuAccess;
keyValue[0].value = (void*) &cpuWaiter;
keyValue[0].len = sizeof(cpuWaiter);
cpuPerm = NvSciSyncAccessPerm_WaitOnly;
keyValue[1].attrKey = NvSciSyncAttrKey_RequiredPerm;
keyValue[1].value = (void*) &cpuPerm;
keyValue[1].len = sizeof(cpuPerm);
err = NvSciSyncAttrListSetAttrs(list, keyValue, 2);
if (err != NvSciError_Success) {
goto fail;
}
/* Export waiter's NvSciSyncAttrList */
err = NvSciSyncAttrListIpcExportUnreconciled(
&waiterAttrList, 1,
ipcEndpoint,
&waiterAttrListDesc, &waiterAttrListSize);
if (err != NvSciError_Success) {
goto fail;
}
/* send waiterAttrListSize */
/* send waiterAttrListDesc */
/* receive objAndListDesc */
err = NvSciSyncIpcImportAttrListAndObj(
module, ipcEndpoint,
objAndListDesc, objAndListSize,
&waiterAttrList, 1,
NvSciSyncAccessPerm_WaitOnly, 10000U, &syncObj);
if (err != NvSciError_Success) {
goto fail;
}
/* Waiter streaming phase */
/* receive fenceDesc */
err = NvSciSyncIpcImportFence(
syncObj,
&fenceDesc,
&syncFence);
if (err != NvSciError_Success) {
goto fail;
}
err = NvSciSyncFenceWait(
&syncFence,
waitContext, 30000U);
if (err != NvSciError_Success) {
goto fail;
}
NvSciSyncFenceClear(&syncFence);
/* cleanup */
fail:
free(waiterAttrListDesc);
free(objAndListDesc);
NvSciSyncAttrListFree(waiterAttrList);
NvSciSyncObjFree(syncObj);
NvSciSyncCpuWaitContextFree(waitContext);
/* Deinitialize the NvSciSync module */
NvSciSyncModuleClose(module);
/* Deinitialize NvSciIpc */
NvSciIpcCloseEndpoint(ipcEndpoint);
NvSciIpcDeinit();