NickelHook icon indicating copy to clipboard operation
NickelHook copied to clipboard

Improved failsafe API

Open pgaskin opened this issue 3 years ago • 2 comments

The failsafe works perfectly fine right now, but there's room for improvement. It would also be nice to be able to use the failsafe at times other than just startup.

I'm thinking of having an API like:

  • nh_failsafe_t *nh_failsafe_create(const char *fn, const char *fn_temp) - creates a new failsafe for the specified file
  • nh_failsafe_t *nh_failsafe_global() - returns or creates the global instance
  • nh_failsafe_claim_t nh_failsafe_claim(nh_failsafe_t*, int timeout) - creates a claim with an optional timeout, activates the failsafe if it isn't active, and extends the it to remain active while the claim exists
  • void nh_failsafe_release(nh_failsafe_t*, nh_failsafe_claim_t, int delay) - releases a claim after an optional delay
  • void nh_failsafe_trigger(nh_failsafe_t*) - triggers the failsafe (works even when there aren't any claims)
  • void nh_failsafe_uninstall(nh_failsafe_t*) - deletes the temporary file
  • NH_FAILSAFE(failsafe, timeout, delay) - macro to create a claim and use the GCC cleanup attribute to release it when it goes out of scope

pgaskin avatar Jan 07 '21 22:01 pgaskin