NvSciSyncAttrList unreconciledList[2] = {NULL};
NvSciSyncAttrList reconciledList = NULL;
NvSciSyncAttrList newConflictList = NULL;
NvSciSyncAttrList signalerAttrList = NULL;
NvSciSyncModule module = NULL;
NvSciSyncObj syncObj = NULL;
NvSciSyncAttrList importedUnreconciledAttrList = NULL;
NvSciSyncFence syncFence = NvSciSyncFenceInitializer;
NvSciIpcEndpoint ipcEndpoint = 0;
NvSciSyncFenceIpcExportDescriptor fenceDesc;
void* waiterAttrListDesc;
size_t waiterAttrListSize;
void* objAndListDesc;
size_t objAndListSize;
NvSciSyncAttrKeyValuePair keyValue[2] = {0};
bool cpuSignaler = true;
NvSciSyncAccessPerm cpuPerm;
/* Initialize NvSciIpc */
err = NvSciIpcInit();
if (err != NvSciError_Success) {
goto fail;
}
err = NvSciIpcOpenEndpoint("example", &ipcEndpoint);
if (err != NvSciError_Success) {
goto fail;
}
/* Signaler Setup/Init phase */
/* Initialize the NvSciSync module */
err = NvSciSyncModuleOpen(&module);
if (err != NvSciError_Success) {
goto fail;
}
/* create local attribute list */
err = NvSciSyncAttrListCreate(module, &signalerAttrList);
if (err != NvSciError_Success) {
goto fail;
}
err = largs->fillSignalerAttrList(signalerAttrList);
if (err != NvSciError_Success) {
goto fail;
}
cpuSignaler = true;
keyValue[0].attrKey = NvSciSyncAttrKey_NeedCpuAccess;
keyValue[0].value = (void*) &cpuSignaler;
keyValue[0].len = sizeof(cpuSignaler);
cpuPerm = NvSciSyncAccessPerm_SignalOnly;
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;
}
/* receive waiterAttrListSize; */
/* receive waiterAttrListDesc */
err = NvSciSyncAttrListIpcImportUnreconciled(
module, ipcEndpoint,
waiterAttrListDesc, waiterAttrListSize,
&importedUnreconciledAttrList);
if (err != NvSciError_Success) {
goto fail;
}
unreconciledList[0] = signalerAttrList;
unreconciledList[1] = importedUnreconciledAttrList;
/* Reconcile Signaler and Waiter NvSciSyncAttrList */
err = NvSciSyncAttrListReconcile(
unreconciledList, 2, &reconciledList,
&newConflictList);
if (err != NvSciError_Success) {
goto fail;
}
/* Create NvSciSync object and get the syncObj */
err = NvSciSyncObjAlloc(reconciledList, &syncObj);
if (err != NvSciError_Success) {
goto fail;
}
/* Export attr list and obj and signal waiter*/
err = NvSciSyncIpcExportAttrListAndObj(
syncObj,
NvSciSyncAccessPerm_WaitOnly, ipcEndpoint,
&objAndListDesc, &objAndListSize);
/* send objAndListSize */
/* send objAndListDesc */
/* signaler's streaming phase */
err = NvSciSyncObjGenerateFence(syncObj, &syncFence);
if (err != NvSciError_Success) {
return err;
}
err = NvSciSyncIpcExportFence(&syncFence, ipcEndpoint, &fenceDesc);
if (err != NvSciError_Success) {
goto fail;
}
NvSciSyncFenceClear(&syncFence);
/* do job that the waiter is supposed to wait on */
NvSciSyncObjSignal(syncObj);
/* cleanup */
fail:
/* Free descriptors */
free(objAndListDesc);
free(waiterAttrListDesc);
/* Free NvSciSyncObj */
NvSciSyncObjFree(syncObj);
/* Free Attribute list objects */
NvSciSyncAttrListFree(reconciledList);
NvSciSyncAttrListFree(newConflictList);
NvSciSyncAttrListFree(signalerAttrList);
NvSciSyncAttrListFree(importedUnreconciledAttrList);
/* Deinitialize the NvSciSync module */
NvSciSyncModuleClose(module);
/* Deinitialize NvSciIpc */
NvSciIpcCloseEndpoint(ipcEndpoint);
NvSciIpcDeinit();