Skip to content

Commit

Permalink
fix(libsinsp): disable thread pool on webassembly
Browse files Browse the repository at this point in the history
Signed-off-by: Gianmatteo Palmieri <[email protected]>
  • Loading branch information
mrgian committed Jul 19, 2024
1 parent 5b15202 commit ace2bc4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
10 changes: 10 additions & 0 deletions userspace/libsinsp/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,11 @@ std::vector<metrics_v2> sinsp_plugin::get_metrics() const

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 static_cast<thread_pool::routine_id_t>(nullptr);
}

auto f = [this, routine_fn, routine_state]() -> bool {
return static_cast<bool>(routine_fn(m_state, routine_state));
};
Expand All @@ -833,6 +838,11 @@ thread_pool::routine_id_t sinsp_plugin::subscribe_routine(ss_plugin_routine_fn_t

void sinsp_plugin::unsubscribe_routine(thread_pool::routine_id_t routine_id)
{
if(!m_thread_pool || !routine_id)
{
return;
}

m_thread_pool->unsubscribe(routine_id);
}

Expand Down
2 changes: 2 additions & 0 deletions userspace/libsinsp/sinsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ sinsp::sinsp(bool static_container, const std::string &static_id, const std::str
m_table_registry = std::make_shared<libsinsp::state::table_registry>();
m_table_registry->add_table(m_thread_manager.get());

#if !defined(__EMSCRIPTEN__)
m_thread_pool = std::make_shared<bs_thread_pool>();
#endif
}

sinsp::~sinsp()
Expand Down
4 changes: 4 additions & 0 deletions userspace/libsinsp/test/plugins.ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,8 @@ TEST_F(sinsp_with_test_input, plugin_metrics)

#endif

#if !defined(__EMSCRIPTEN__)

TEST_F(sinsp_with_test_input, plugin_routines)
{
auto p = register_plugin(&m_inspector, get_plugin_api_sample_routines);
Expand Down Expand Up @@ -957,3 +959,5 @@ TEST_F(sinsp_with_test_input, plugin_routines)
routines_num = m_inspector.m_thread_pool->routines_num();
ASSERT_EQ(routines_num, 0);
}

#endif
4 changes: 3 additions & 1 deletion userspace/libsinsp/test/thread_pool.ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ limitations under the License.
#include <gtest/gtest.h>
#include <sinsp_with_test_input.h>

#if !defined(__EMSCRIPTEN__)
TEST_F(sinsp_with_test_input, thread_pool)
{
open_inspector();
Expand Down Expand Up @@ -69,4 +70,5 @@ TEST_F(sinsp_with_test_input, thread_pool)
ASSERT_EQ(tp->routines_num(), 1);
m_inspector.close();
ASSERT_EQ(tp->routines_num(), 0);
}
}
#endif
2 changes: 1 addition & 1 deletion userspace/plugin/plugin_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ typedef struct
// - f: the function executed by the routine on each iteration
// - i: the routine's state
//
// Return value: A routine handle that can be used to later unsubscribe the routine.
// Return value: A routine handle that can be used to later unsubscribe the routine. Returns null in case of failure.
ss_plugin_routine_t* (*subscribe)(ss_plugin_owner_t* o, ss_plugin_routine_fn_t f, ss_plugin_routine_state_t* i);

//
Expand Down

0 comments on commit ace2bc4

Please sign in to comment.