#ifndef INSPECTOR_HPP #define INSPECTOR_HPP #include #include class ScopedMutex { public: ScopedMutex(pthread_mutex_t & p_mutex); ~ScopedMutex(); private: ScopedMutex(const ScopedMutex &); ScopedMutex & operator=(const ScopedMutex &); pthread_mutex_t & m_mutex; }; int register_exec_count_ts(const char * p_exec_count_location, int & p_exec_count); void reset_exec_count_ts(const char * p_exec_count_location = 0); pthread_mutex_t & get_mutex(); int register_exec_count(const char * p_exec_count_location, int & p_exec_count); void reset_exec_count(const char * p_exec_count_location = 0); std::ostream & print(std::ostream & p_ostream, const char * p_location, int p_exec_count, bool p_condition_value); #define STRINGIFY(x) #x #define TOSTRING(x) STRINGIFY(x) #define LOCATION __FILE__ ":" TOSTRING(__LINE__) ":" #define PRINT(p_exec_count, p_condition_value) print(std::cout, LOCATION, (p_exec_count), (p_condition_value)) #define EXPRESSION(p_condition) \ ( \ { \ static int exec_count = 0; \ bool condition = (p_condition); \ { \ ScopedMutex scoped_mutex(get_mutex()); \ { \ static int tmp = register_exec_count(LOCATION, exec_count); \ tmp = tmp; \ } \ PRINT(++exec_count, condition) << #p_condition << std::endl; \ } \ condition; \ } \ ) #endif