@ -13,38 +13,54 @@
# ifndef SRSRAN_ASSERT_H
# define SRSRAN_ASSERT_H
# ifdef __cplusplus
# include "srsran/srslog/srslog.h"
# include <cstdio>
# include <stdarg.h>
# define srsran_unlikely(expr) __builtin_expect(!!(expr), 0)
# define srsran_terminate(fmt, ...) \
srslog : : flush ( ) ; \
std : : fprintf ( stderr , " %s:%d: " fmt " \n " , __FILE__ , __LINE__ , # # __VA_ARGS__ ) ; \
std : : abort ( )
# ifdef ASSERTS_ENABLED
/**
* 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__ )
/**
* Macro that asserts condition is true . If false , it logs the remaining parameters , prints the backtrace and closes
* the application
* 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 .
*/
# define srsran_assert(condition, fmt, ...) \
do { \
if ( srsran_unlikely ( not ( condition ) ) ) { \
srsran_terminate ( fmt , # # __VA_ARGS__ ) ; \
} \
} while ( 0 )
# define srsran_always_assert(condition, fmt, ...) (void)((condition) || srsran_assertion_failure(fmt, ##__VA_ARGS__))
# ifdef STOP_ON_WARNING
# define SRSRAN_IS_DEFINED(x) SRSRAN_IS_DEFINED2(x)
# define SRSRAN_IS_DEFINED2(x) (#x[0] == 0 || (#x[0] >= '1' && #x[0] <= '9'))
/**
* Macro that verifies if condition is true . If false , and STOP_ON_WARNING is true , it behaves like srsran_assert .
* If STOP_ON_WARNING is false , it logs a warning .
* Same as " srsran_always_assert " but it is only active when " enable_check " flag is defined
*/
# 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
# define srsran_expect(condition, fmt, ...) srsran_assert(condition, fmt, ##__VA_ARGS__)
# else // STOP_ON_WARNING
# else
# define srsran_expect(condition, fmt, ...) \
do { \
@ -53,16 +69,20 @@
} \
} while ( 0 )
# endif // STOP_ON_WARNING
# endif
# else // __ifcplusplus
# else // ASSERTS_ENABLED
# include <cassert>
# ifdef ASSERTS_ENABLED
# define srsran_assert(condition, fmt, ...) (void)((condition) || (__assert(#condition, __FILE__, __FLAG__), 0))
# else
# define srsran_assert(condition, fmt, ...) \
do { \
} while ( 0 )
# define srsran_expect(condition, fmt, ...) srsran_assert(condition, fmt, ##__VA_ARGS__)
# endif
# endif // __ifcplusplus
# endif // SRSRAN_ASSERT_H