This file is indexed.

/usr/include/ola/util/Watchdog.h is in libola-dev 0.10.3.nojsmin-2+deb9u1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 *
 * Watchdog.h
 * Copyright (C) 2015 Simon Newton
 */

#ifndef INCLUDE_OLA_UTIL_WATCHDOG_H_
#define INCLUDE_OLA_UTIL_WATCHDOG_H_

#include <ola/Callback.h>
#include <ola/thread/Mutex.h>
#include <memory>

namespace ola {

/**
 * @brief Detects if an operation stalls.
 *
 * The Watchdog can be used to detect when a operation has stalled. When
 * enabled, the Clock() method should be called at regular intervals. While the
 * operation is making forward progress, it should kick the watchdog by
 * calling Kick().
 *
 * If Kick() isn't called for the specified number of clock cycles, the reset
 * callback will be triggered.
 *
 * Once a watchdog has fired, it must be Disabled() and Enabled() again to
 * reset it.
 *
 * This class is thread safe.
 * See also https://en.wikipedia.org/wiki/Watchdog_timer
 *
 * @examplepara
 *
 * One way (not recommended) of using this would be:
 *
 * ~~~~~~~~~~~~~~~~~~~~~
 * // Call periodically
 * void WatchdogThread() {
 *   while (true) {
 *     watchdog->Clock();
 *     sleep(1);
 *   }
 * }
 *
 * void WorkerThread() {
 *   watchdog->Enable();
 *   // Start operation.
 *   while (true) {
 *     DoWorkSlice();
 *     watchdog->Kick();
 *   }
 *   watchdog->Disable();
 * }
 * ~~~~~~~~~~~~~~~~~~~~~
 */
class Watchdog {
 public:
  /**
   * @brief Create a new Watchdog.
   * @param cycle_limit The number of cycles allowed before the reset callback
   *   is run.
   * @param reset_callback the callback to run when the cycle limit is reached.
   */
  Watchdog(unsigned int cycle_limit, Callback0<void> *reset_callback);

  /**
   * @brief Enable the watchdog.
   */
  void Enable();

  /**
   * @brief Disable the watchdog.
   */
  void Disable();

  /**
   * @brief Kick the watchdog to avoid a reset.
   *
   * This should be called regularly while the watchdog is enabled.
   */
  void Kick();

  /**
   * @brief Check if the process has stalled due to a lack of Kick() calls.
   *
   * This should be called regularly. If it's been more than the specified
   * number of clock cycles since a kick, the callback is run.
   */
  void Clock();

 private:
  const unsigned int m_limit;
  std::auto_ptr<Callback0<void> > m_callback;
  ola::thread::Mutex m_mu;
  bool m_enabled;  // GUARDED_BY(m_mu);
  unsigned int m_count;  // GUARDED_BY(m_mu);
  bool m_fired;  // GUARDED_BY(m_mu);
};
}  // namespace ola
#endif  // INCLUDE_OLA_UTIL_WATCHDOG_H_