NIST Biometric Evaluation Framework
Software components for biometric technology evaluations
be_time_watchdog.h
Go to the documentation of this file.
1/******************************************************************************
2 * This software was developed at the National Institute of Standards and
3 * Technology (NIST) by employees of the Federal Government in the course
4 * of their official duties. Pursuant to title 17 Section 105 of the
5 * United States Code, this software is not subject to copyright protection
6 * and is in the public domain. NIST assumes no responsibility whatsoever for
7 * its use by other parties, and makes no guarantees, expressed or implied,
8 * about its quality, reliability, or any other characteristic.
9 ******************************************************************************/
10#ifndef __BE_TIME_WATCHDOG_H__
11#define __BE_TIME_WATCHDOG_H__
12
13#include <csetjmp>
14#include <csignal>
15
16#include <be_time.h>
17#include <be_error_exception.h>
18
25#define BEGIN_WATCHDOG_BLOCK(_watchdog, _blockname) do { \
26 if (!(_watchdog)->isEnabled()) \
27 break; \
28 (_watchdog)->clearExpired(); \
29 (_watchdog)->clearCanSigJump(); \
30 if (sigsetjmp( \
31 BiometricEvaluation::Time::Watchdog::_sigJumpBuf, 1) != 0) \
32 { \
33 (_watchdog)->setExpired(); \
34 goto _blockname ## _end; \
35 } \
36 (_watchdog)->setCanSigJump(); \
37 (_watchdog)->start(); \
38} while (0)
39
40#define END_WATCHDOG_BLOCK(_watchdog, _blockname) do { \
41 if (!(_watchdog)->isEnabled()) \
42 break; \
43 _blockname ## _end: \
44 (_watchdog)->clearCanSigJump(); \
45 (_watchdog)->stop(); \
46} while (0);
47
48#define ABORT_WATCHDOG(_watchdog) do { \
49 if (!(_watchdog)->isEnabled()) \
50 break; \
51 (_watchdog)->clearCanSigJump(); \
52 (_watchdog)->stop(); \
53} while (0);
54
55namespace BiometricEvaluation {
56
57 namespace Time {
58
118 class Watchdog {
119 public:
120
122 static const uint8_t PROCESSTIME = 0;
124 static const uint8_t REALTIME = 1;
125
141 Watchdog(const uint8_t type);
142
150 uint64_t
152 const
153 noexcept;
154
166 void setInterval(uint64_t interval);
167
175 void start();
176
183 void stop();
184
189 bool expired();
190
196
202
207
212
224 const bool enabled);
225
227 bool isEnabled() const;
228
229 /*
230 * Flag indicating can jump after handling a signal,
231 * and the jump buffer used by the signal handler.
232 */
233 static bool _canSigJump;
234 static sigjmp_buf _sigJumpBuf;
235
236 protected:
237
238 private:
239 /*
240 * Definition of the signal handler, a class method
241 * that will handle all signals managed by this object,
242 * conditionally jumping to a jump block. This jump
243 * capability allows applications to bypass code that
244 * is "hung". Applications should use the
245 * BEGIN_WATCHDOG_BLOCK()/END_WATCHDOG_BLOCK() macro
246 * pair to take advantage of this capability.
247 */
248 static void sighandler(int signo);
249
251 bool _enabled{true};
252
253 /*
254 * Current timer interval.
255 */
256 uint64_t _interval;
257
258 /*
259 * The type of timer.
260 */
261 uint8_t _type;
262
263 /*
264 * Flag indicated that the timer expired.
265 */
266 bool _expired;
267
268 /*
269 * Utility function to map the Watchdog type of alarm
270 * to the system signal number and which system timer.
271 */
272 void internalMapWatchdogType(int *signo, int *which);
273 };
274 /*
275 * Declaration of the signal handler, a function with C linkage
276 * that will handle the alarm signals sent when a system timer
277 * expires.
278 */
279 extern "C" {
280 void WatchdogSignalHandler(int signo, siginfo_t *info,
281 void *uap);
282 }
283 }
284}
285#endif /* __BE_TIME_WATCHDOG_H__ */
A Watchdog object can be used by applications to limit the amount of processing time taken by a block...
void start()
Start a watchdog timer.
bool isEnabled() const
Check the enabled status of the timer.
static const uint8_t REALTIME
A Watchdog based on real (wall clock) time.
void clearCanSigJump()
Clears the flag for the Watchdog object to indicate that the signal jump block is no longer valid.
void stop()
Stop a watchdog timer.
void setCanSigJump()
Indicate that the signal handler can jump into the application code after handling the signal.
Watchdog(const uint8_t type)
Construct a new Watchdog object.
void setEnabled(const bool enabled)
Enable or disable the timer.
bool expired()
Indicate whether the watchdog timer expired.
static const uint8_t PROCESSTIME
A Watchdog based on process time.
uint64_t getInterval() const noexcept
Obtain the timer interval.
void setInterval(uint64_t interval)
Set the interval for the timer, but don't start the timer.
void setExpired()
Set a flag to indicate the timer expired.
void clearExpired()
Clear the flag indicating the timer expired.
void WatchdogSignalHandler(int signo, siginfo_t *info, void *uap)
This software was developed at the National Institute of Standards and Technology (NIST) by employees...