Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,8 @@ endif()
unset(_hpx_tracing_backends)
unset(_hpx_tracing_backends_count)

hpx_add_config_cond_define(HPX_HAVE_TRACING 0)

if(HPX_WITH_NETWORKING)
hpx_add_config_define(HPX_HAVE_NETWORKING)

Expand Down
1 change: 1 addition & 0 deletions cmake/HPX_SetupAllocator.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ if(NOT TARGET hpx_dependencies_allocator)
endif()

hpx_add_config_define(HPX_HAVE_ITTNOTIFY 1)
hpx_add_config_define(HPX_HAVE_TRACING 1)
hpx_add_config_define(HPX_HAVE_THREAD_DESCRIPTION)
endif()

Expand Down
1 change: 1 addition & 0 deletions cmake/HPX_SetupApex.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,6 @@ if(HPX_WITH_APEX AND NOT TARGET APEX::apex)
)
target_link_libraries(APEX::apex INTERFACE ITTNotify::ittnotify)
hpx_add_config_define(HPX_HAVE_ITTNOTIFY 1)
hpx_add_config_define(HPX_HAVE_TRACING 1)
endif()
endif()
1 change: 1 addition & 0 deletions libs/core/concurrency/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ add_hpx_module(
hpx_itt_notify
hpx_lock_registration
hpx_thread_support
hpx_tracing
hpx_type_support
hpx_version
${additional_dependencies}
Expand Down
44 changes: 10 additions & 34 deletions libs/core/concurrency/include/hpx/concurrency/spinlock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
#include <hpx/modules/itt_notify.hpp>
#include <hpx/modules/lock_registration.hpp>
#include <hpx/modules/thread_support.hpp>
#if defined(HPX_HAVE_MODULE_TRACY)
#include <hpx/modules/tracy.hpp>
#endif
#include <hpx/modules/tracing.hpp>

#include <string>
#include <utility>
Expand All @@ -32,76 +30,56 @@ namespace hpx::util {

private:
hpx::util::detail::spinlock m;
#if defined(HPX_HAVE_MODULE_TRACY)
hpx::tracy::lock_data context_;
#endif
HPX_NO_UNIQUE_ADDRESS hpx::tracing::lock_context context_;

public:
spinlock() noexcept
: context_("hpx::spinlock")
{
HPX_ITT_SYNC_CREATE(this, "util::spinlock", nullptr);
#if defined(HPX_HAVE_MODULE_TRACY)
context_ = hpx::tracy::create("hpx::spinlock");
#endif
}

explicit spinlock(char const* desc) noexcept
: context_("util::spinlock#", desc)
{
HPX_ITT_SYNC_CREATE(this, "util::spinlock", desc);
#if defined(HPX_HAVE_MODULE_TRACY)
context_ =
hpx::tracy::create(std::string("util::spinlock#") + desc);
#endif
}

~spinlock()
{
HPX_ITT_SYNC_DESTROY(this);
#if defined(HPX_HAVE_MODULE_TRACY)
hpx::tracy::destroy(context_);
#endif
}

void lock() noexcept(
noexcept(util::register_lock(std::declval<spinlock*>())))
{
HPX_ITT_SYNC_PREPARE(this);
#if defined(HPX_HAVE_MODULE_TRACY)
bool const run_after = hpx::tracy::lock_prepare(context_);
#endif
bool const run_after = context_.before_lock();
m.lock();

HPX_ITT_SYNC_ACQUIRED(this);
#if defined(HPX_HAVE_MODULE_TRACY)
if (run_after)
hpx::tracy::lock_acquired(context_);
#endif
context_.after_lock();
util::register_lock(this);
}

bool try_lock() noexcept(
noexcept(util::register_lock(std::declval<spinlock*>())))
{
HPX_ITT_SYNC_PREPARE(this);
#if defined(HPX_HAVE_MODULE_TRACY)
bool const run_after = hpx::tracy::lock_prepare(context_);
#endif
bool const run_after = context_.before_lock();

if (m.try_lock())
{
HPX_ITT_SYNC_ACQUIRED(this);
#if defined(HPX_HAVE_MODULE_TRACY)
if (run_after)
hpx::tracy::lock_acquired(context_, true);
#endif
context_.after_try_lock(true);
util::register_lock(this);
return true;
}
HPX_ITT_SYNC_CANCEL(this);
#if defined(HPX_HAVE_MODULE_TRACY)
if (run_after)
hpx::tracy::lock_acquired(context_, false);
#endif
context_.after_try_lock(false);
return false;
}

Expand All @@ -113,9 +91,7 @@ namespace hpx::util {
m.unlock();

HPX_ITT_SYNC_RELEASED(this);
#if defined(HPX_HAVE_MODULE_TRACY)
hpx::tracy::lock_released(context_);
#endif
context_.after_unlock();
util::unregister_lock(this);
}
};
Expand Down
1 change: 1 addition & 0 deletions libs/core/synchronization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ add_hpx_module(
hpx_thread_support
hpx_timing
hpx_topology
hpx_tracing
hpx_type_support
${additional_dependencies}
CMAKE_SUBDIRS examples tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
#include <hpx/modules/errors.hpp>
#include <hpx/modules/threading_base.hpp>
#include <hpx/modules/timing.hpp>
#include <hpx/modules/tracing.hpp>
#include <hpx/synchronization/detail/condition_variable.hpp>
#include <hpx/synchronization/spinlock.hpp>
#if defined(HPX_HAVE_MODULE_TRACY)
#include <hpx/modules/tracy.hpp>
#endif

namespace hpx::threads {

Expand Down Expand Up @@ -89,7 +87,8 @@ namespace hpx {
///
/// \param description description of the \a mutex.
///
#if HPX_HAVE_ITTNOTIFY != 0 || defined(HPX_HAVE_MODULE_TRACY)
#if defined(HPX_HAVE_MODULE_TRACY) || \
(defined(HPX_HAVE_ITTNOTIFY) && HPX_HAVE_ITTNOTIFY != 0)
HPX_CORE_EXPORT mutex(char const* const description = "");
#else
HPX_HOST_DEVICE_CONSTEXPR mutex(char const* const = "") noexcept
Expand Down Expand Up @@ -245,9 +244,7 @@ namespace hpx {
mutable mutex_type mtx_;
threads::thread_id_type owner_id_;
hpx::lcos::local::detail::condition_variable cond_;
#if defined(HPX_HAVE_MODULE_TRACY)
hpx::tracy::lock_data context_;
#endif
HPX_NO_UNIQUE_ADDRESS hpx::tracing::lock_context context_;
/// \endcond NOPROTECTED
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
#include <hpx/modules/execution_base.hpp>
#include <hpx/modules/itt_notify.hpp>
#include <hpx/modules/lock_registration.hpp>
#if defined(HPX_HAVE_MODULE_TRACY)
#include <hpx/modules/tracy.hpp>
#endif
#include <hpx/modules/tracing.hpp>

#include <atomic>
#include <cstddef>
Expand All @@ -50,37 +48,28 @@ namespace hpx {

private:
std::atomic<bool> v_;
#if defined(HPX_HAVE_MODULE_TRACY)
hpx::tracy::lock_data context_;
#endif
HPX_NO_UNIQUE_ADDRESS hpx::tracing::lock_context context_;

public:
#if HPX_HAVE_ITTNOTIFY != 0 || defined(HPX_HAVE_MODULE_TRACY)
#if defined(HPX_HAVE_MODULE_TRACY) || \
(defined(HPX_HAVE_ITTNOTIFY) && HPX_HAVE_ITTNOTIFY != 0)
spinlock() noexcept
: v_(false)
, context_("hpx::spinlock")
{
HPX_ITT_SYNC_CREATE(this, "hpx::spinlock", nullptr);
#if defined(HPX_HAVE_MODULE_TRACY)
context_ = hpx::tracy::create("hpx::spinlock");
#endif
}

explicit spinlock(char const* const desc) noexcept
: v_(false)
, context_("hpx::spinlock#", desc)
{
HPX_ITT_SYNC_CREATE(this, "hpx::spinlock", desc);
#if defined(HPX_HAVE_MODULE_TRACY)
context_ =
hpx::tracy::create(std::string("hpx::spinlock#") + desc);
#endif
}

~spinlock()
{
HPX_ITT_SYNC_DESTROY(this);
#if defined(HPX_HAVE_MODULE_TRACY)
hpx::tracy::destroy(context_);
#endif
}
#else
constexpr spinlock() noexcept
Expand All @@ -99,9 +88,7 @@ namespace hpx {
void lock()
{
HPX_ITT_SYNC_PREPARE(this);
#if defined(HPX_HAVE_MODULE_TRACY)
bool const run_after = hpx::tracy::lock_prepare(context_);
#endif
bool const run_after = context_.before_lock();

// Checking for the value in is_locked() ensures that
// acquire_lock is only called when is_locked computes to false.
Expand Down Expand Up @@ -132,37 +119,29 @@ namespace hpx {
}

HPX_ITT_SYNC_ACQUIRED(this);
#if defined(HPX_HAVE_MODULE_TRACY)
if (run_after)
hpx::tracy::lock_acquired(context_);
#endif
context_.after_lock();
util::register_lock(this);
}

bool try_lock() noexcept(
noexcept(util::register_lock(std::declval<spinlock*>())))
{
HPX_ITT_SYNC_PREPARE(this);
#if defined(HPX_HAVE_MODULE_TRACY)
bool const run_after = hpx::tracy::lock_prepare(context_);
#endif
bool const run_after = context_.before_lock();

if (acquire_lock())
{
HPX_ITT_SYNC_ACQUIRED(this);
#if defined(HPX_HAVE_MODULE_TRACY)
if (run_after)
hpx::tracy::lock_acquired(context_, true);
#endif
context_.after_try_lock(true);
util::register_lock(this);
return true;
}

HPX_ITT_SYNC_CANCEL(this);
#if defined(HPX_HAVE_MODULE_TRACY)
if (run_after)
hpx::tracy::lock_acquired(context_, false);
#endif
context_.after_try_lock(false);
return false;
}

Expand All @@ -174,9 +153,7 @@ namespace hpx {
relinquish_lock();

HPX_ITT_SYNC_RELEASED(this);
#if defined(HPX_HAVE_MODULE_TRACY)
hpx::tracy::lock_released(context_);
#endif
context_.after_unlock();
util::unregister_lock(this);
}

Expand Down
Loading
Loading