Skip to content

Instantly share code, notes, and snippets.

@antirez
Created July 4, 2012 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antirez/3047823 to your computer and use it in GitHub Desktop.
Save antirez/3047823 to your computer and use it in GitHub Desktop.
/* This function checks if we need to enter the TITL mode.
*
* The TILT mode is entered if we detect that between two invocations of the
* timer interrupt, a negative amount of time, or too much time has passed.
* Note that we expect that more or less just 100 milliseconds will pass
* if everything is fine. However we'll see a negative number of a
* difference bigger than SENTINEL_TILT_TRIGGER milliseconds if one of the
* following happens:
*
* 1) The Sentiel process for some time is blocked, for every kind of
* random reason: the load is huge, the computer was freezed for some time
* in I/O or alike, the process was stopped by a signal. Everything.
* 2) The system clock was altered significantly.
*
* Under both this conditions we'll see everything as timed out and failing
* without good reasons. Instead we enter the TILT mode and wait
* for SENTIENL_TILT_PERIOD to elapse before starting to act again.
*
* During TILT time we still collect information, we just do not act. */
void sentinelCheckTiltCondition(void) {
mstime_t now = mstime();
mstime_t delta = now - sentinel.previous_time;
if (delta < 0 || delta > SENTINEL_TILT_TRIGGER) {
sentiel.tilt = 1;
sentiel.tilt_start_time = mstime();
}
sentinel.previous_time = mstime();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment