Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CFRunLoopObserver vs. nested CFRunLoops

I`ve got a Cocoa UI app that needs to update its main window as fast as the rest of its UI event loop permits, so I implemented the main updater function via a CFRunLoopObserver. I also have an application-modal alert box and a context menu.

So, my problem is that when I have both an alert and a context menu on the screen, the updater gets stuck, presumably due to excess number of nested run loops above the one it has been attached to back at the start. Surprisingly, I can alleviate the issue by duplicating the observer, and it keeps running — one instance only, randomly chosen from the two existing when the «blocking» nested loop starts. When it ends (a menu item gets chosen, an alert exceeds its timeout or is dismissed manually — whatever), things get back to normal, and the blocked observer regains the ability to run.

Now the question: is there a way to have a single observer that gets executed no matter how deep the run loop stack is?

like image 666
hidefromkgb Avatar asked Feb 25 '17 19:02

hidefromkgb


1 Answers

Sidestepping the runloop issue, have you looked at CVDisplayLink?

You set one up using CVDisplayLinkCreateWithActiveCGDisplays(), and then attach a callback using CVDisplayLinkSetOutputCallback(). It'll ask for data at the refresh rate of the display, so you'll be getting the callback as fast as you need.

like image 172
Amy Worrall Avatar answered Oct 28 '22 09:10

Amy Worrall