From 894b33c0efa9bb9e2e7d45fd9088945c04339e8e Mon Sep 17 00:00:00 2001 From: Gianmatteo Palmieri Date: Fri, 13 Sep 2024 14:38:35 +0200 Subject: [PATCH] chore(sinsp): rename `thread_pool` to `sinsp_thread_pool` to avoid symbol conflicts Signed-off-by: Gianmatteo Palmieri --- userspace/libsinsp/CMakeLists.txt | 2 +- userspace/libsinsp/plugin.cpp | 12 ++++++------ userspace/libsinsp/plugin.h | 18 +++++++++--------- userspace/libsinsp/sinsp.cpp | 6 +++--- userspace/libsinsp/sinsp.h | 6 +++--- .../{thread_pool.h => sinsp_thread_pool.h} | 7 ++++--- ...d_pool_bs.cpp => sinsp_thread_pool_bs.cpp} | 19 ++++++++++--------- ...hread_pool_bs.h => sinsp_thread_pool_bs.h} | 13 +++++++------ 8 files changed, 43 insertions(+), 40 deletions(-) rename userspace/libsinsp/{thread_pool.h => sinsp_thread_pool.h} (93%) rename userspace/libsinsp/{thread_pool_bs.cpp => sinsp_thread_pool_bs.cpp} (70%) rename userspace/libsinsp/{thread_pool_bs.h => sinsp_thread_pool_bs.h} (74%) diff --git a/userspace/libsinsp/CMakeLists.txt b/userspace/libsinsp/CMakeLists.txt index f3abd43db1..be4ca47090 100644 --- a/userspace/libsinsp/CMakeLists.txt +++ b/userspace/libsinsp/CMakeLists.txt @@ -113,7 +113,7 @@ add_library( ) if(ENABLE_THREAD_POOL AND NOT EMSCRIPTEN) - target_sources(sinsp PRIVATE thread_pool_bs.cpp) + target_sources(sinsp PRIVATE sinsp_thread_pool_bs.cpp) endif() if(NOT WIN32 AND NOT APPLE) diff --git a/userspace/libsinsp/plugin.cpp b/userspace/libsinsp/plugin.cpp index 406e03e7d7..88a04479a2 100644 --- a/userspace/libsinsp/plugin.cpp +++ b/userspace/libsinsp/plugin.cpp @@ -88,7 +88,7 @@ static void plugin_log_fn(ss_plugin_owner_t* o, std::shared_ptr sinsp_plugin::create( const plugin_api* api, const std::shared_ptr& treg, - const std::shared_ptr& tpool, + const std::shared_ptr& tpool, std::string& errstr) { char loadererr[PLUGIN_MAX_ERRLEN]; auto handle = plugin_load_api(api, loadererr); @@ -109,7 +109,7 @@ std::shared_ptr sinsp_plugin::create( std::shared_ptr sinsp_plugin::create( const std::string& filepath, const std::shared_ptr& treg, - const std::shared_ptr& tpool, + const std::shared_ptr& tpool, std::string& errstr) { char loadererr[PLUGIN_MAX_ERRLEN]; auto handle = plugin_load(filepath.c_str(), loadererr); @@ -742,11 +742,11 @@ std::vector sinsp_plugin::get_metrics() const { return metrics; } -thread_pool::routine_id_t sinsp_plugin::subscribe_routine( +sinsp_thread_pool::routine_id_t sinsp_plugin::subscribe_routine( ss_plugin_routine_fn_t routine_fn, ss_plugin_routine_state_t* routine_state) { if(!m_thread_pool) { - return reinterpret_cast(nullptr); + return reinterpret_cast(nullptr); } auto f = [this, routine_fn, routine_state]() -> bool { @@ -756,7 +756,7 @@ thread_pool::routine_id_t sinsp_plugin::subscribe_routine( return m_thread_pool->subscribe(f); } -bool sinsp_plugin::unsubscribe_routine(thread_pool::routine_id_t routine_id) { +bool sinsp_plugin::unsubscribe_routine(sinsp_thread_pool::routine_id_t routine_id) { if(!m_thread_pool || !routine_id) { return false; } @@ -775,7 +775,7 @@ ss_plugin_routine_t* plugin_subscribe_routine(ss_plugin_owner_t* o, ss_plugin_rc plugin_unsubscribe_routine(ss_plugin_owner_t* o, ss_plugin_routine_t* r) { auto t = static_cast(o); - auto id = reinterpret_cast(r); + auto id = reinterpret_cast(r); return t->unsubscribe_routine(id) ? SS_PLUGIN_SUCCESS : SS_PLUGIN_FAILURE; } diff --git a/userspace/libsinsp/plugin.h b/userspace/libsinsp/plugin.h index 0ab97de21f..155860e096 100644 --- a/userspace/libsinsp/plugin.h +++ b/userspace/libsinsp/plugin.h @@ -32,9 +32,9 @@ limitations under the License. #include #if defined(ENABLE_THREAD_POOL) && !defined(__EMSCRIPTEN__) -#include +#include #else -#include +#include #endif /** @@ -62,7 +62,7 @@ class sinsp_plugin { static std::shared_ptr create( const std::string& path, const std::shared_ptr& treg, - const std::shared_ptr& tpool, + const std::shared_ptr& tpool, std::string& errstr); /** @@ -72,7 +72,7 @@ class sinsp_plugin { static std::shared_ptr create( const plugin_api* api, const std::shared_ptr& treg, - const std::shared_ptr& tpool, + const std::shared_ptr& tpool, std::string& errstr); /** @@ -100,7 +100,7 @@ class sinsp_plugin { sinsp_plugin(plugin_handle_t* handle, const std::shared_ptr& treg, - const std::shared_ptr& tpool): + const std::shared_ptr& tpool): m_caps(CAP_NONE), m_name(), m_description(), @@ -158,9 +158,9 @@ class sinsp_plugin { std::vector get_metrics() const; bool capture_open(); bool capture_close(); - thread_pool::routine_id_t subscribe_routine(ss_plugin_routine_fn_t routine_fn, - ss_plugin_routine_state_t* routine_state); - bool unsubscribe_routine(thread_pool::routine_id_t routine_id); + sinsp_thread_pool::routine_id_t subscribe_routine(ss_plugin_routine_fn_t routine_fn, + ss_plugin_routine_state_t* routine_state); + bool unsubscribe_routine(sinsp_thread_pool::routine_id_t routine_id); /** Event Sourcing **/ inline uint32_t id() const { return m_id; } @@ -441,7 +441,7 @@ class sinsp_plugin { ss_plugin_state_type key_type); static ss_plugin_rc table_api_add_table(ss_plugin_owner_t* o, const ss_plugin_table_input* in); - std::shared_ptr m_thread_pool; + std::shared_ptr m_thread_pool; friend struct sinsp_table_wrapper; }; diff --git a/userspace/libsinsp/sinsp.cpp b/userspace/libsinsp/sinsp.cpp index d5636cc97d..760b68622d 100644 --- a/userspace/libsinsp/sinsp.cpp +++ b/userspace/libsinsp/sinsp.cpp @@ -136,7 +136,7 @@ sinsp::sinsp(bool with_metrics): m_table_registry->add_table(m_thread_manager.get()); #if defined(ENABLE_THREAD_POOL) && !defined(__EMSCRIPTEN__) - m_thread_pool = std::make_shared(); + m_thread_pool = std::make_shared(); #else m_thread_pool = nullptr; #endif @@ -1903,11 +1903,11 @@ void sinsp::set_track_connection_status(bool enabled) { m_parser->set_track_connection_status(enabled); } -std::shared_ptr sinsp::get_thread_pool() { +std::shared_ptr sinsp::get_thread_pool() { return m_thread_pool; } -bool sinsp::set_thread_pool(std::shared_ptr tpool) { +bool sinsp::set_thread_pool(std::shared_ptr tpool) { if(!m_thread_pool) { m_thread_pool = tpool; return true; diff --git a/userspace/libsinsp/sinsp.h b/userspace/libsinsp/sinsp.h index 28f6edac70..28c16f40b1 100644 --- a/userspace/libsinsp/sinsp.h +++ b/userspace/libsinsp/sinsp.h @@ -927,8 +927,8 @@ class SINSP_PUBLIC sinsp : public capture_stats_source { bool get_track_connection_status() const; inline void set_track_connection_status(bool enabled); - std::shared_ptr get_thread_pool(); - bool set_thread_pool(std::shared_ptr tpool); + std::shared_ptr get_thread_pool(); + bool set_thread_pool(std::shared_ptr tpool); /** * \brief Get a new timestamp. @@ -1066,7 +1066,7 @@ class SINSP_PUBLIC sinsp : public capture_stats_source { int32_t m_quantization_interval = -1; - std::shared_ptr m_thread_pool; + std::shared_ptr m_thread_pool; public: std::unique_ptr m_thread_manager; diff --git a/userspace/libsinsp/thread_pool.h b/userspace/libsinsp/sinsp_thread_pool.h similarity index 93% rename from userspace/libsinsp/thread_pool.h rename to userspace/libsinsp/sinsp_thread_pool.h index bbfd2455fc..836ba67f1f 100644 --- a/userspace/libsinsp/thread_pool.h +++ b/userspace/libsinsp/sinsp_thread_pool.h @@ -15,6 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +#pragma once #include #include @@ -22,13 +23,13 @@ limitations under the License. #include #include -class thread_pool { +class sinsp_thread_pool { public: using routine_id_t = uintptr_t; - thread_pool() = default; + sinsp_thread_pool() = default; - virtual ~thread_pool() = default; + virtual ~sinsp_thread_pool() = default; /*! * \brief Subscribes a routine to the thread pool. diff --git a/userspace/libsinsp/thread_pool_bs.cpp b/userspace/libsinsp/sinsp_thread_pool_bs.cpp similarity index 70% rename from userspace/libsinsp/thread_pool_bs.cpp rename to userspace/libsinsp/sinsp_thread_pool_bs.cpp index a7ee88bb2f..40c295dac0 100644 --- a/userspace/libsinsp/thread_pool_bs.cpp +++ b/userspace/libsinsp/sinsp_thread_pool_bs.cpp @@ -16,15 +16,15 @@ limitations under the License. */ -#include +#include #include -void thread_pool_bs::default_bs_tp_deleter::operator()(BS::thread_pool* __ptr) const { +void sinsp_thread_pool_bs::default_bs_tp_deleter::operator()(BS::thread_pool* __ptr) const { std::default_delete{}(__ptr); } -thread_pool_bs::thread_pool_bs(size_t num_workers): m_pool(nullptr), m_routines() { +sinsp_thread_pool_bs::sinsp_thread_pool_bs(size_t num_workers): m_pool(nullptr), m_routines() { if(num_workers == 0) { m_pool = std::unique_ptr(new BS::thread_pool()); } else { @@ -33,15 +33,16 @@ thread_pool_bs::thread_pool_bs(size_t num_workers): m_pool(nullptr), m_routines( } } -thread_pool_bs::routine_id_t thread_pool_bs::subscribe(const std::function& func) { +sinsp_thread_pool_bs::routine_id_t sinsp_thread_pool_bs::subscribe( + const std::function& func) { m_routines.push_back(std::make_shared>(func)); auto& new_routine = m_routines.back(); run_routine(new_routine); - return reinterpret_cast(new_routine.get()); + return reinterpret_cast(new_routine.get()); } -bool thread_pool_bs::unsubscribe(thread_pool_bs::routine_id_t id) { +bool sinsp_thread_pool_bs::unsubscribe(sinsp_thread_pool_bs::routine_id_t id) { bool removed = false; m_routines.remove_if([id, &removed](const std::shared_ptr>& v) { if(v.get() == reinterpret_cast*>(id)) { @@ -55,18 +56,18 @@ bool thread_pool_bs::unsubscribe(thread_pool_bs::routine_id_t id) { return removed; } -void thread_pool_bs::purge() { +void sinsp_thread_pool_bs::purge() { m_routines.clear(); m_pool->purge(); m_pool->wait(); } -size_t thread_pool_bs::routines_num() { +size_t sinsp_thread_pool_bs::routines_num() { return m_routines.size(); } -void thread_pool_bs::run_routine(std::shared_ptr> routine) { +void sinsp_thread_pool_bs::run_routine(std::shared_ptr> routine) { m_pool->detach_task([this, routine] { if(routine.use_count() <= 1) { return; diff --git a/userspace/libsinsp/thread_pool_bs.h b/userspace/libsinsp/sinsp_thread_pool_bs.h similarity index 74% rename from userspace/libsinsp/thread_pool_bs.h rename to userspace/libsinsp/sinsp_thread_pool_bs.h index 065d0b5abf..2b0a20aab2 100644 --- a/userspace/libsinsp/thread_pool_bs.h +++ b/userspace/libsinsp/sinsp_thread_pool_bs.h @@ -15,22 +15,23 @@ See the License for the specific language governing permissions and limitations under the License. */ +#pragma once -#include +#include namespace BS { class thread_pool; }; -class thread_pool_bs : public thread_pool { +class sinsp_thread_pool_bs : public sinsp_thread_pool { public: - thread_pool_bs(size_t num_workers = 0); + sinsp_thread_pool_bs(size_t num_workers = 0); - virtual ~thread_pool_bs() { purge(); } + virtual ~sinsp_thread_pool_bs() { purge(); } - thread_pool::routine_id_t subscribe(const std::function& func); + sinsp_thread_pool::routine_id_t subscribe(const std::function& func); - bool unsubscribe(thread_pool::routine_id_t id); + bool unsubscribe(sinsp_thread_pool::routine_id_t id); void purge();