memoryio / memoryio-macosx

Life logging app for macosx. Takes a picture with built in isight whenever you wake computer from sleep
8 stars 4 forks source link

Image ratelimiting / debouncing #20

Closed zgiles closed 8 years ago

zgiles commented 11 years ago

Adding a blocking function to prevent multiple callbacks at the same time (or close together) from causing either a) a function to throw an exception because an object is busy doing something already, b) getting into code where it looked like something was available but isn't now, or c) multiple pictures within a few seconds.

This blocking is simple and works by creating a synchronization group which controls a BOOL so that only one call can edit the BOOL at the same time. It also sets a timer in another thread to reset the BOOL after some time (10seconds for now) so that we have up to 10s of unlimited bad calls against the function before another one wins.

The logs state when a thread tried and won or lost.

An earlier commit to make the 2.0f delay standard across the board helped here. Everything including the menubar call go through to ensure nothing fights with each other.

zgiles commented 11 years ago

Curious if this is going to get merged in..

jacobrosenthal commented 11 years ago

We don't need this until we process adding other triggers for photos in #21

As such I'm still actively evaluating this. Does it help with our existing bug #24 for some reason I can't fathom? Is this the best way to do blocking?

jacobrosenthal commented 8 years ago

I think switching to nscontrol queues finally licked this. https://github.com/memoryio/memoryio-macosx/commit/1979edcdebce907b9cd1c7ca72d187ec22ea2bd0