#define static_assert(cond, msg) _Static_assert(cond, msg)
#endif
+#ifdef NDEBUG
+#define ASSERT_EQ(expression, value) (void)expression
+#define ASSERT_NE(expression, value) (void)expression
+#else
+#define ASSERT_EQ(expression, value) assert(expression == value)
+#define ASSERT_NE(expression, value) assert(expression != value)
+#endif
+
#define container_of(ptr, type, member) \
((type *)((uintptr_t)(ptr) - (uintptr_t)offsetof(type, member)))
#ifdef HAVE_CLOCK_GETTIME
static inline void usbi_get_monotonic_time(struct timespec *tp)
{
- int r = clock_gettime(CLOCK_MONOTONIC, tp);
- assert(r == 0);
+ ASSERT_EQ(clock_gettime(CLOCK_MONOTONIC, tp), 0);
}
static inline void usbi_get_real_time(struct timespec *tp)
{
- int r = clock_gettime(CLOCK_REALTIME, tp);
- assert(r == 0);
+ ASSERT_EQ(clock_gettime(CLOCK_REALTIME, tp), 0);
}
#else
/* If the platform doesn't provide the clock_gettime() function, the backend
#include <pthread.h>
-#define PTHREAD_CHECK(expr) \
- do { \
- int pthread_result = (expr); \
- assert(pthread_result == 0); \
- } while (0)
+#define PTHREAD_CHECK(expression) ASSERT_EQ(expression, 0)
#define USBI_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
typedef pthread_mutex_t usbi_mutex_static_t;
#ifndef LIBUSB_THREADS_WINDOWS_H
#define LIBUSB_THREADS_WINDOWS_H
-#define WINAPI_CHECK(expr) \
- do { \
- BOOL winapi_result = (expr); \
- assert(winapi_result != 0); \
- } while (0)
+#define WINAPI_CHECK(expression) ASSERT_NE(expression, 0)
#define USBI_MUTEX_INITIALIZER 0L
typedef LONG usbi_mutex_static_t;