Skip to content

Commit

Permalink
chore(sinsp): rename thread_pool to sinsp_thread_pool to avoid sy…
Browse files Browse the repository at this point in the history
…mbol conflicts

Signed-off-by: Gianmatteo Palmieri <mail@gian.im>
  • Loading branch information
mrgian committed Sep 13, 2024
1 parent acc2d4e commit 894b33c
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 40 deletions.
2 changes: 1 addition & 1 deletion userspace/libsinsp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions userspace/libsinsp/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static void plugin_log_fn(ss_plugin_owner_t* o,
std::shared_ptr<sinsp_plugin> sinsp_plugin::create(
const plugin_api* api,
const std::shared_ptr<libsinsp::state::table_registry>& treg,
const std::shared_ptr<thread_pool>& tpool,
const std::shared_ptr<sinsp_thread_pool>& tpool,
std::string& errstr) {
char loadererr[PLUGIN_MAX_ERRLEN];
auto handle = plugin_load_api(api, loadererr);
Expand All @@ -109,7 +109,7 @@ std::shared_ptr<sinsp_plugin> sinsp_plugin::create(
std::shared_ptr<sinsp_plugin> sinsp_plugin::create(
const std::string& filepath,
const std::shared_ptr<libsinsp::state::table_registry>& treg,
const std::shared_ptr<thread_pool>& tpool,
const std::shared_ptr<sinsp_thread_pool>& tpool,
std::string& errstr) {
char loadererr[PLUGIN_MAX_ERRLEN];
auto handle = plugin_load(filepath.c_str(), loadererr);
Expand Down Expand Up @@ -742,11 +742,11 @@ std::vector<metrics_v2> 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(

Check warning on line 745 in userspace/libsinsp/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

userspace/libsinsp/plugin.cpp#L745

Added line #L745 was not covered by tests
ss_plugin_routine_fn_t routine_fn,
ss_plugin_routine_state_t* routine_state) {
if(!m_thread_pool) {
return reinterpret_cast<thread_pool::routine_id_t>(nullptr);
return reinterpret_cast<sinsp_thread_pool::routine_id_t>(nullptr);
}

auto f = [this, routine_fn, routine_state]() -> bool {
Expand All @@ -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) {

Check warning on line 759 in userspace/libsinsp/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

userspace/libsinsp/plugin.cpp#L759

Added line #L759 was not covered by tests
if(!m_thread_pool || !routine_id) {
return false;
}
Expand All @@ -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<sinsp_plugin*>(o);
auto id = reinterpret_cast<thread_pool::routine_id_t>(r);
auto id = reinterpret_cast<sinsp_thread_pool::routine_id_t>(r);

Check warning on line 778 in userspace/libsinsp/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

userspace/libsinsp/plugin.cpp#L778

Added line #L778 was not covered by tests

return t->unsubscribe_routine(id) ? SS_PLUGIN_SUCCESS : SS_PLUGIN_FAILURE;
}
Expand Down
18 changes: 9 additions & 9 deletions userspace/libsinsp/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ limitations under the License.
#include <plugin/plugin_loader.h>

#if defined(ENABLE_THREAD_POOL) && !defined(__EMSCRIPTEN__)
#include <libsinsp/thread_pool_bs.h>
#include <libsinsp/sinsp_thread_pool_bs.h>
#else
#include <libsinsp/thread_pool.h>
#include <libsinsp/sinsp_thread_pool.h>
#endif

/**
Expand Down Expand Up @@ -62,7 +62,7 @@ class sinsp_plugin {
static std::shared_ptr<sinsp_plugin> create(
const std::string& path,
const std::shared_ptr<libsinsp::state::table_registry>& treg,
const std::shared_ptr<thread_pool>& tpool,
const std::shared_ptr<sinsp_thread_pool>& tpool,
std::string& errstr);

/**
Expand All @@ -72,7 +72,7 @@ class sinsp_plugin {
static std::shared_ptr<sinsp_plugin> create(
const plugin_api* api,
const std::shared_ptr<libsinsp::state::table_registry>& treg,
const std::shared_ptr<thread_pool>& tpool,
const std::shared_ptr<sinsp_thread_pool>& tpool,
std::string& errstr);

/**
Expand Down Expand Up @@ -100,7 +100,7 @@ class sinsp_plugin {

sinsp_plugin(plugin_handle_t* handle,
const std::shared_ptr<libsinsp::state::table_registry>& treg,
const std::shared_ptr<thread_pool>& tpool):
const std::shared_ptr<sinsp_thread_pool>& tpool):
m_caps(CAP_NONE),
m_name(),
m_description(),
Expand Down Expand Up @@ -158,9 +158,9 @@ class sinsp_plugin {
std::vector<metrics_v2> 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; }
Expand Down Expand Up @@ -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<thread_pool> m_thread_pool;
std::shared_ptr<sinsp_thread_pool> m_thread_pool;

friend struct sinsp_table_wrapper;
};
6 changes: 3 additions & 3 deletions userspace/libsinsp/sinsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<thread_pool_bs>();
m_thread_pool = std::make_shared<sinsp_thread_pool_bs>();
#else
m_thread_pool = nullptr;
#endif
Expand Down Expand Up @@ -1903,11 +1903,11 @@ void sinsp::set_track_connection_status(bool enabled) {
m_parser->set_track_connection_status(enabled);
}

std::shared_ptr<thread_pool> sinsp::get_thread_pool() {
std::shared_ptr<sinsp_thread_pool> sinsp::get_thread_pool() {

Check warning on line 1906 in userspace/libsinsp/sinsp.cpp

View check run for this annotation

Codecov / codecov/patch

userspace/libsinsp/sinsp.cpp#L1906

Added line #L1906 was not covered by tests
return m_thread_pool;
}

bool sinsp::set_thread_pool(std::shared_ptr<thread_pool> tpool) {
bool sinsp::set_thread_pool(std::shared_ptr<sinsp_thread_pool> tpool) {

Check warning on line 1910 in userspace/libsinsp/sinsp.cpp

View check run for this annotation

Codecov / codecov/patch

userspace/libsinsp/sinsp.cpp#L1910

Added line #L1910 was not covered by tests
if(!m_thread_pool) {
m_thread_pool = tpool;
return true;
Expand Down
6 changes: 3 additions & 3 deletions userspace/libsinsp/sinsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<thread_pool> get_thread_pool();
bool set_thread_pool(std::shared_ptr<thread_pool> tpool);
std::shared_ptr<sinsp_thread_pool> get_thread_pool();
bool set_thread_pool(std::shared_ptr<sinsp_thread_pool> tpool);

/**
* \brief Get a new timestamp.
Expand Down Expand Up @@ -1066,7 +1066,7 @@ class SINSP_PUBLIC sinsp : public capture_stats_source {

int32_t m_quantization_interval = -1;

std::shared_ptr<thread_pool> m_thread_pool;
std::shared_ptr<sinsp_thread_pool> m_thread_pool;

public:
std::unique_ptr<sinsp_thread_manager> m_thread_manager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
#pragma once

#include <list>
#include <cstdint>
#include <cstddef>
#include <functional>
#include <memory>

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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ limitations under the License.
*/

#include <thread_pool_bs.h>
#include <sinsp_thread_pool_bs.h>

#include <BS_thread_pool.hpp>

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<BS::thread_pool>{}(__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<BS::thread_pool, default_bs_tp_deleter>(new BS::thread_pool());
} else {
Expand All @@ -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<bool()>& func) {
sinsp_thread_pool_bs::routine_id_t sinsp_thread_pool_bs::subscribe(
const std::function<bool()>& func) {
m_routines.push_back(std::make_shared<std::function<bool()>>(func));
auto& new_routine = m_routines.back();
run_routine(new_routine);

return reinterpret_cast<thread_pool_bs::routine_id_t>(new_routine.get());
return reinterpret_cast<sinsp_thread_pool_bs::routine_id_t>(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<std::function<bool()>>& v) {
if(v.get() == reinterpret_cast<std::function<bool()>*>(id)) {
Expand All @@ -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<std::function<bool()>> routine) {
void sinsp_thread_pool_bs::run_routine(std::shared_ptr<std::function<bool()>> routine) {
m_pool->detach_task([this, routine] {
if(routine.use_count() <= 1) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,23 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
#pragma once

#include <libsinsp/thread_pool.h>
#include <libsinsp/sinsp_thread_pool.h>

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<bool()>& func);
sinsp_thread_pool::routine_id_t subscribe(const std::function<bool()>& func);

bool unsubscribe(thread_pool::routine_id_t id);
bool unsubscribe(sinsp_thread_pool::routine_id_t id);

void purge();

Expand Down

0 comments on commit 894b33c

Please sign in to comment.