Topic locked

objc_sync_enter/exit AND DispatchSemaphore in native demo app?

July 27, 2021 - 9:09pm #1

We're working with iOS SDK 9.8.5 (native -- not Unity), and are trying to understand the sample app.

In VuforiaView.swift, there is this:

 

    @objc func renderFrameVuforia() {
        objc_sync_enter(self)
        if (mVuforiaStarted) {
            
            if (mConfigurationChanged) {
                mConfigurationChanged = false
                configureVuforia()
            }
            
            renderFrameVuforiaInternal()
        }
        objc_sync_exit(self)
    }

 

In the same source file, inside renderFrameVuforiaInternal, most of the rendering code is wrapped in a DispatchSemaphore, like this:

// Wait for exclusive access to the GPU
let _ = mCommandExecutingSemaphore.wait(timeout: DispatchTime.distantFuture)

... bunch of rendering code...

// Commit the rendering commands
// Command completed handler
commandBuffer?.addCompletedHandler { _ in self.mCommandExecutingSemaphore.signal()}

 

What is the point of having two types of synchronization here, and is it actually necessary?

We have objc_sync_enter and objc_sync_exit wrapping the whole thing, and then the mCommandExecutingSemaphore synchronizing the render code, but not releasing until the completion handler is fired -- i.e., when the frame has actually been rendered to the screen.

I don't know if any of this is actually "wrong", per se, but two types of synchronization seemed a bit odd, so I was hoping someone could shed some light here.

Thanks!

Topic locked