diff --git a/lib/base/exception.cpp b/lib/base/exception.cpp index 5d7f901b7..51320f5a3 100644 --- a/lib/base/exception.cpp +++ b/lib/base/exception.cpp @@ -406,3 +406,34 @@ Dictionary::Ptr ValidationError::GetDebugHint() const return m_DebugHint; } +std::string icinga::to_string(const StackTraceErrorInfo&) +{ + return ""; +} + +#ifdef _WIN32 +std::string icinga::to_string(const errinfo_win32_error& e) +{ + return "[errinfo_win32_error] = " + Utility::FormatErrorNumber(e.value()) + "\n"; +} +#endif /* _WIN32 */ + +std::string icinga::to_string(const errinfo_getaddrinfo_error& e) +{ + String msg; + +#ifdef _WIN32 + msg = gai_strerrorA(e.value()); +#else /* _WIN32 */ + msg = gai_strerror(e.value()); +#endif /* _WIN32 */ + + return "[errinfo_getaddrinfo_error] = " + String(msg) + "\n"; +} + +std::string icinga::to_string(const ContextTraceErrorInfo& e) +{ + std::ostringstream msgbuf; + msgbuf << "[Context] = " << e.value(); + return msgbuf.str(); +} diff --git a/lib/base/exception.hpp b/lib/base/exception.hpp index df41d4523..e4f53e50b 100644 --- a/lib/base/exception.hpp +++ b/lib/base/exception.hpp @@ -106,19 +106,11 @@ void RethrowUncaughtException(); typedef boost::error_info StackTraceErrorInfo; -inline std::string to_string(const StackTraceErrorInfo&) -{ - return ""; -} +std::string to_string(const StackTraceErrorInfo&); typedef boost::error_info ContextTraceErrorInfo; -inline std::string to_string(const ContextTraceErrorInfo& e) -{ - std::ostringstream msgbuf; - msgbuf << "[Context] = " << e.value(); - return msgbuf.str(); -} +std::string to_string(const ContextTraceErrorInfo& e); String DiagnosticInformation(const std::exception& ex, bool verbose = true, StackTrace *stack = nullptr, ContextTrace *context = nullptr); String DiagnosticInformation(const boost::exception_ptr& eptr, bool verbose = true); @@ -139,27 +131,13 @@ class win32_error : virtual public std::exception, virtual public boost::excepti struct errinfo_win32_error_; typedef boost::error_info errinfo_win32_error; -inline std::string to_string(const errinfo_win32_error& e) -{ - return "[errinfo_win32_error] = " + Utility::FormatErrorNumber(e.value()) + "\n"; -} +std::string to_string(const errinfo_win32_error& e); #endif /* _WIN32 */ struct errinfo_getaddrinfo_error_; typedef boost::error_info errinfo_getaddrinfo_error; -inline std::string to_string(const errinfo_getaddrinfo_error& e) -{ - String msg; - -#ifdef _WIN32 - msg = gai_strerrorA(e.value()); -#else /* _WIN32 */ - msg = gai_strerror(e.value()); -#endif /* _WIN32 */ - - return "[errinfo_getaddrinfo_error] = " + String(msg) + "\n"; -} +std::string to_string(const errinfo_getaddrinfo_error& e); struct errinfo_message_; typedef boost::error_info errinfo_message; diff --git a/lib/base/object.cpp b/lib/base/object.cpp index add244396..51a850d37 100644 --- a/lib/base/object.cpp +++ b/lib/base/object.cpp @@ -252,3 +252,35 @@ INITIALIZE_ONCE([]() { }); #endif /* I2_LEAK_DEBUG */ +void icinga::intrusive_ptr_add_ref(Object *object) +{ +#ifdef I2_LEAK_DEBUG + if (object->m_References == 0) + TypeAddObject(object); +#endif /* I2_LEAK_DEBUG */ + +#ifdef _WIN32 + InterlockedIncrement(&object->m_References); +#else /* _WIN32 */ + __sync_add_and_fetch(&object->m_References, 1); +#endif /* _WIN32 */ +} + +void icinga::intrusive_ptr_release(Object *object) +{ + uintptr_t refs; + +#ifdef _WIN32 + refs = InterlockedDecrement(&object->m_References); +#else /* _WIN32 */ + refs = __sync_sub_and_fetch(&object->m_References, 1); +#endif /* _WIN32 */ + + if (unlikely(refs == 0)) { +#ifdef I2_LEAK_DEBUG + TypeRemoveObject(object); +#endif /* I2_LEAK_DEBUG */ + + delete object; + } +} diff --git a/lib/base/object.hpp b/lib/base/object.hpp index 40eae3431..d6d9bc79f 100644 --- a/lib/base/object.hpp +++ b/lib/base/object.hpp @@ -164,38 +164,8 @@ Value GetPrototypeField(const Value& context, const String& field, bool not_foun void TypeAddObject(Object *object); void TypeRemoveObject(Object *object); -inline void intrusive_ptr_add_ref(Object *object) -{ -#ifdef I2_LEAK_DEBUG - if (object->m_References == 0) - TypeAddObject(object); -#endif /* I2_LEAK_DEBUG */ - -#ifdef _WIN32 - InterlockedIncrement(&object->m_References); -#else /* _WIN32 */ - __sync_add_and_fetch(&object->m_References, 1); -#endif /* _WIN32 */ -} - -inline void intrusive_ptr_release(Object *object) -{ - uintptr_t refs; - -#ifdef _WIN32 - refs = InterlockedDecrement(&object->m_References); -#else /* _WIN32 */ - refs = __sync_sub_and_fetch(&object->m_References, 1); -#endif /* _WIN32 */ - - if (unlikely(refs == 0)) { -#ifdef I2_LEAK_DEBUG - TypeRemoveObject(object); -#endif /* I2_LEAK_DEBUG */ - - delete object; - } -} +void intrusive_ptr_add_ref(Object *object); +void intrusive_ptr_release(Object *object); template class ObjectImpl diff --git a/lib/base/tlsutility.cpp b/lib/base/tlsutility.cpp index 4adf04f33..3955ceca4 100644 --- a/lib/base/tlsutility.cpp +++ b/lib/base/tlsutility.cpp @@ -782,4 +782,19 @@ bool VerifyCertificate(const std::shared_ptr& caCertificate, const std::sh return rc == 1; } +std::string to_string(const errinfo_openssl_error& e) +{ + std::ostringstream tmp; + int code = e.value(); + char errbuf[120]; + + const char *message = ERR_error_string(code, errbuf); + + if (!message) + message = "Unknown error."; + + tmp << code << ", \"" << message << "\""; + return "[errinfo_openssl_error]" + tmp.str() + "\n"; +} + } diff --git a/lib/base/tlsutility.hpp b/lib/base/tlsutility.hpp index 18ffa7f26..7928c56d1 100644 --- a/lib/base/tlsutility.hpp +++ b/lib/base/tlsutility.hpp @@ -61,20 +61,7 @@ class openssl_error : virtual public std::exception, virtual public boost::excep struct errinfo_openssl_error_; typedef boost::error_info errinfo_openssl_error; -inline std::string to_string(const errinfo_openssl_error& e) -{ - std::ostringstream tmp; - int code = e.value(); - char errbuf[120]; - - const char *message = ERR_error_string(code, errbuf); - - if (!message) - message = "Unknown error."; - - tmp << code << ", \"" << message << "\""; - return "[errinfo_openssl_error]" + tmp.str() + "\n"; -} +std::string to_string(const errinfo_openssl_error& e); } diff --git a/lib/base/workqueue.cpp b/lib/base/workqueue.cpp index f8247bb7e..a18c9818b 100644 --- a/lib/base/workqueue.cpp +++ b/lib/base/workqueue.cpp @@ -299,3 +299,18 @@ size_t WorkQueue::GetTaskCount(RingBuffer::SizeType span) boost::mutex::scoped_lock lock(m_StatsMutex); return m_TaskStats.UpdateAndGetValues(Utility::GetTime(), span); } + +bool icinga::operator<(const Task& a, const Task& b) +{ + if (a.Priority < b.Priority) + return true; + + if (a.Priority == b.Priority) { + if (a.ID > b.ID) + return true; + else + return false; + } + + return false; +} diff --git a/lib/base/workqueue.hpp b/lib/base/workqueue.hpp index 955651b4a..14d0dd5fb 100644 --- a/lib/base/workqueue.hpp +++ b/lib/base/workqueue.hpp @@ -54,20 +54,7 @@ struct Task int ID{-1}; }; -inline bool operator<(const Task& a, const Task& b) -{ - if (a.Priority < b.Priority) - return true; - - if (a.Priority == b.Priority) { - if (a.ID > b.ID) - return true; - else - return false; - } - - return false; -} +bool operator<(const Task& a, const Task& b); /** * A workqueue.