mirror of https://github.com/pvnis/srsRAN_4G.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
3.1 KiB
C
89 lines
3.1 KiB
C
4 years ago
|
/**
|
||
|
*
|
||
|
* \section COPYRIGHT
|
||
|
*
|
||
|
* Copyright 2013-2021 Software Radio Systems Limited
|
||
|
*
|
||
|
* By using this file, you agree to the terms and conditions set
|
||
|
* forth in the LICENSE file which can be found at the top level of
|
||
|
* the distribution.
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
#ifndef SRSRAN_ASSERT_H
|
||
|
#define SRSRAN_ASSERT_H
|
||
|
|
||
3 years ago
|
#ifdef __cplusplus
|
||
4 years ago
|
#include "srsran/srslog/srslog.h"
|
||
4 years ago
|
#include <cstdio>
|
||
3 years ago
|
#include <stdarg.h>
|
||
4 years ago
|
|
||
|
#define srsran_unlikely(expr) __builtin_expect(!!(expr), 0)
|
||
|
|
||
3 years ago
|
/**
|
||
|
* Command to terminate srsRAN application with an error message, ensuring first that the log is flushed
|
||
|
*/
|
||
|
[[gnu::noinline, noreturn]] inline bool srsran_terminate(const char* fmt, ...)
|
||
|
{
|
||
|
va_list args;
|
||
|
va_start(args, fmt);
|
||
|
srslog::flush();
|
||
|
vfprintf(stderr, fmt, args);
|
||
|
va_end(args);
|
||
|
std::abort();
|
||
|
}
|
||
|
|
||
|
#define srsran_assertion_failure(fmt, ...) \
|
||
|
srsran_terminate("%s:%d: Assertion Failure: " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__)
|
||
4 years ago
|
|
||
4 years ago
|
/**
|
||
3 years ago
|
* Macro that asserts condition is true. If false, it logs the remaining macro args, flushes the log,
|
||
|
* prints the backtrace (if it was activated) and closes the application.
|
||
4 years ago
|
*/
|
||
3 years ago
|
#define srsran_always_assert(condition, fmt, ...) (void)((condition) || srsran_assertion_failure(fmt, ##__VA_ARGS__))
|
||
4 years ago
|
|
||
3 years ago
|
#define SRSRAN_IS_DEFINED(x) SRSRAN_IS_DEFINED2(x)
|
||
|
#define SRSRAN_IS_DEFINED2(x) (#x[0] == 0 || (#x[0] >= '1' && #x[0] <= '9'))
|
||
4 years ago
|
|
||
4 years ago
|
/**
|
||
3 years ago
|
* Same as "srsran_always_assert" but it is only active when "enable_check" flag is defined
|
||
4 years ago
|
*/
|
||
3 years ago
|
#define srsran_assert_ifdef(enable_check, condition, fmt, ...) \
|
||
|
(void)((not SRSRAN_IS_DEFINED(enable_check)) || (srsran_always_assert(condition, fmt, ##__VA_ARGS__), 0))
|
||
|
|
||
|
/**
|
||
|
* Specialization of "srsran_assert_ifdef" for the ASSERTS_ENABLED flag
|
||
|
*/
|
||
|
#define srsran_assert(condition, fmt, ...) srsran_assert_ifdef(ASSERTS_ENABLED, condition, fmt, ##__VA_ARGS__)
|
||
|
|
||
|
#ifdef STOP_ON_WARNING
|
||
|
|
||
4 years ago
|
#define srsran_expect(condition, fmt, ...) srsran_assert(condition, fmt, ##__VA_ARGS__)
|
||
4 years ago
|
|
||
3 years ago
|
#else
|
||
4 years ago
|
|
||
4 years ago
|
#define srsran_expect(condition, fmt, ...) \
|
||
4 years ago
|
do { \
|
||
|
if (srsran_unlikely(not(condition))) { \
|
||
|
srslog::fetch_basic_logger("ALL").warning("%s:%d: " fmt, __FILE__, __LINE__, ##__VA_ARGS__); \
|
||
|
} \
|
||
|
} while (0)
|
||
|
|
||
3 years ago
|
#endif
|
||
|
|
||
|
#else // __ifcplusplus
|
||
4 years ago
|
|
||
3 years ago
|
#include <cassert>
|
||
4 years ago
|
|
||
3 years ago
|
#ifdef ASSERTS_ENABLED
|
||
|
#define srsran_assert(condition, fmt, ...) (void)((condition) || (__assert(#condition, __FILE__, __FLAG__), 0))
|
||
|
#else
|
||
4 years ago
|
#define srsran_assert(condition, fmt, ...) \
|
||
4 years ago
|
do { \
|
||
|
} while (0)
|
||
|
#endif
|
||
|
|
||
3 years ago
|
#endif // __ifcplusplus
|
||
|
|
||
4 years ago
|
#endif // SRSRAN_ASSERT_H
|