From 2b41a6717eedbeec830a82fea2b8ad8a034661a0 Mon Sep 17 00:00:00 2001 From: heck Date: Tue, 30 Mar 2021 02:41:42 +0200 Subject: [PATCH 1/2] pEpLog - includes in headers are to be avoided if possible --- src/pEpLog.cc | 6 +++++- src/pEpLog.hh | 17 +++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/pEpLog.cc b/src/pEpLog.cc index 753eb09..e8f84c0 100644 --- a/src/pEpLog.cc +++ b/src/pEpLog.cc @@ -7,6 +7,10 @@ #include #include +#ifdef ANDROID + #include +#endif + namespace pEp { namespace Adapter { @@ -14,7 +18,7 @@ namespace pEp { std::mutex mtx; - std::atomic_bool is_enabled{false}; + std::atomic_bool is_enabled{ false }; void set_enabled(bool enabled) { diff --git a/src/pEpLog.hh b/src/pEpLog.hh index 2d3fae9..3cb4b7b 100644 --- a/src/pEpLog.hh +++ b/src/pEpLog.hh @@ -6,10 +6,6 @@ #include #include -#ifdef ANDROID - #include -#endif - // pEpLog // ====== // a "to be kept ultra small and simple" logging unit. @@ -36,12 +32,13 @@ do { \ } while (0) #else - #define pEpLog(msg) \ - do { \ - std::stringstream msg_ss; \ - msg_ss << std::this_thread::get_id() << " - " << __FILE__ << "::" << __FUNCTION__ << " - " << msg; \ - pEp::Adapter::pEpLog::log(msg_ss.str()); \ - } while(0) + #define pEpLog(msg) \ + do { \ + std::stringstream msg_ss; \ + msg_ss << std::this_thread::get_id() << " - " << __FILE__ << "::" << __FUNCTION__ \ + << " - " << msg; \ + pEp::Adapter::pEpLog::log(msg_ss.str()); \ + } while (0) #endif // NDEBUG namespace pEp { From 0517b9be69232a0efba0b30503b74dce4eb347a1 Mon Sep 17 00:00:00 2001 From: heck Date: Tue, 30 Mar 2021 03:00:26 +0200 Subject: [PATCH 2/2] Add Adapter::inject_sync_shutdown() to be used if _adapter_manages_sync_thread --- src/Adapter.cc | 8 +++++++- src/Adapter.hh | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Adapter.cc b/src/Adapter.cc index 95e3655..23cd2fe 100644 --- a/src/Adapter.cc +++ b/src/Adapter.cc @@ -201,13 +201,19 @@ namespace pEp { return _session.get(); } + // public + void inject_sync_shutdown() { + pEpLog("called"); + _inject_sync_event(nullptr, nullptr); + } + // public void shutdown() { pEpLog("called"); if (_sync_thread.joinable()) { pEpLog("sync_is_running - injecting null event"); - _inject_sync_event(nullptr, nullptr); + inject_sync_shutdown(); _sync_thread.join(); } } diff --git a/src/Adapter.hh b/src/Adapter.hh index 7ab0dcd..41c88b7 100644 --- a/src/Adapter.hh +++ b/src/Adapter.hh @@ -77,6 +77,11 @@ namespace pEp { extern thread_local Session session; + // only injects a NULL event into sync_event_queue + // Use this if adapter_manages_sync_thread + // Inject first, then join your thread. + void inject_sync_shutdown(); + // injects a NULL event into sync_event_queue to denote sync thread to // shutdown, and joins & removes the sync thread void shutdown();