forked from frc971/971-Robot-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
die.h
48 lines (39 loc) · 1.78 KB
/
die.h
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
#ifndef AOS_DIE_H_
#define AOS_DIE_H_
#include <cstdarg>
#include "aos/libc/aos_strerror.h"
#include "aos/macros.h"
namespace aos {
// Terminates the task/process and logs a message (without using the logging
// framework). Designed for use in code that can't use the logging framework
// (code that can should LOG(FATAL), which calls this).
void Die(const char *format, ...) __attribute__((noreturn))
__attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 1, 2)));
void VDie(const char *format, va_list args) __attribute__((noreturn))
__attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 1, 0)));
// The same as Die except appends " because of %d (%s)" (formatted with errno
// and aos_strerror(errno)) to the message.
#define PDie(format, args...) \
do { \
const int error = errno; \
::aos::Die(format " because of %d (%s)", ##args, error, \
aos_strerror(error)); \
} while (false)
// The same as Die except appends " because of %d (%s)" (formatted with error
// and aos_strerror(error)) to the message.
// PCHECK is to PDie as PRCHECK is to PRDie
//
// Example:
// const int ret = pthread_mutex_lock(whatever);
// if (ret != 0) PRDie(ret, "pthread_mutex_lock(%p) failed", whatever);
#define PRDie(error, format, args...) \
do { \
::aos::Die(format " because of %d (%s)", ##args, error, \
aos_strerror(error)); \
} while (false)
// Turns on (or off) "test mode", where (V)Die doesn't write out files and
// doesn't print to stdout.
// Test mode defaults to false.
void SetDieTestMode(bool test_mode);
} // namespace aos
#endif // AOS_DIE_H_