NvSciSyncFence Cpu operations#

Signaler#

NvSciError result = NvSciError_Success;

NvSciSyncFence sharedFence = NvSciSyncFenceInitializer;
// Always initialize with the Initializer
NvSciSyncFence localFence = NvSciSyncFenceInitializer;

// Generate a new fence for the signaler
result = NvSciSyncObjGenerateFence(syncObj, &localFence);
if (result != NvSciError_Success) {
    goto fail;
}

// Duplicate fence before sharing
result = NvSciSyncFenceDup(&localFence, sharedFence);
if (result != NvSciError_Success) {
    goto fail;
}

// Create more duplicates if necessary

// Communicate the fence to the waiter.
// ex. via NvSciIpc

// After sharing the fence with the waiter, the local copy is no longer necessary, so dispose of it
// This call cleans references to sync object and is needed for proper freeing
NvSciSyncFenceClear(&localFence);

// Do something else, like some CPU job
// ...

// Signal the sync object
result = NvSciSyncObjSignal(syncObj);
if (result != NvSciError_Success) {
    goto fail;
}

Waiter#

NvSciError result = NvSciError_Success;

// Receive the sharedFence from the signaler
// ex. via NvSciIpc
NvSciSyncFence sharedFence;

// Wait context for the fence
// ex. as obtained from NvSciSyncCpuWaitContextAlloc
NvSciSyncCpuWaitContext waitContext;

// Wait on the fence to expire
result = NvSciSyncFenceWait(
    sharedFence, waitContext, NV_WAIT_INFINITE);
if (result != NvSciError_Success) {
    return result;
}

// Clean up the fence
NvSciSyncFenceClear(sharedFence);