Skip to content

Commit

Permalink
Avoid leaking memory when doing lock detection
Browse files Browse the repository at this point in the history
  • Loading branch information
sithhell committed Dec 18, 2015
1 parent 9877c5c commit 3d7c9c8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
8 changes: 7 additions & 1 deletion hpx/config.hpp
Expand Up @@ -426,7 +426,13 @@
// This limits how deep the internal recursion of future continuations will go
// before a new operation is re-spawned.
#if !defined(HPX_CONTINUATION_MAX_RECURSION_DEPTH)
#if defined(HPX_DEBUG)
#if defined(__has_feature)
# if __has_feature(address_sanitizer)
// if we build under AddressSanitizer we set the max recursion depth to 1 to not
// run into stack overflows.
#define HPX_CONTINUATION_MAX_RECURSION_DEPTH 1
# endif
#elif defined(HPX_DEBUG)
#define HPX_CONTINUATION_MAX_RECURSION_DEPTH 14
#else
#define HPX_CONTINUATION_MAX_RECURSION_DEPTH 20
Expand Down
4 changes: 4 additions & 0 deletions hpx/util/register_locks.hpp
Expand Up @@ -40,6 +40,7 @@ namespace hpx { namespace util
HPX_API_EXPORT void reset_ignored(void const* lock);
HPX_API_EXPORT void ignore_all_locks();
HPX_API_EXPORT void reset_ignored_all();
HPX_API_EXPORT void reset_held_lock_data();

///////////////////////////////////////////////////////////////////////////
struct ignore_all_while_checking
Expand Down Expand Up @@ -188,6 +189,9 @@ namespace hpx { namespace util
inline void reset_ignored_all()
{
}
inline void reset_held_lock_data()
{
}
#endif
}}

Expand Down
3 changes: 2 additions & 1 deletion src/runtime.cpp
Expand Up @@ -509,7 +509,7 @@ namespace hpx
boost::atomic<int> runtime::instance_number_counter_(-1);

///////////////////////////////////////////////////////////////////////////
util::thread_specific_ptr<runtime *, runtime::tls_tag> runtime::runtime_;
util::thread_specific_ptr<runtime*, runtime::tls_tag> runtime::runtime_;
util::thread_specific_ptr<std::string, runtime::tls_tag> runtime::thread_name_;
util::thread_specific_ptr<boost::uint64_t, runtime::tls_tag> runtime::uptime_;

Expand All @@ -534,6 +534,7 @@ namespace hpx
threads::coroutine_type::impl_type::reset_self();
runtime::uptime_.reset();
runtime::runtime_.reset();
util::reset_held_lock_data();
}

std::string runtime::get_thread_name()
Expand Down
14 changes: 14 additions & 0 deletions src/util/register_locks.cpp
Expand Up @@ -135,6 +135,11 @@ namespace hpx { namespace util

m->ignore_all_locks_ = enable;
}

static void reset_held_lock_data()
{
held_locks_.reset();
}
};

hpx::util::thread_specific_ptr<
Expand Down Expand Up @@ -359,6 +364,11 @@ namespace hpx { namespace util
{
detail::register_locks::set_ignore_all_locks(false);
}

void reset_held_lock_data()
{
detail::register_locks::reset_held_lock_data();
}
#else

bool register_lock(void const*, util::register_lock_data*)
Expand Down Expand Up @@ -394,6 +404,10 @@ namespace hpx { namespace util
void reset_ignored_all()
{
}

void reset_held_lock_data()
{
}
#endif
}}

Expand Down

0 comments on commit 3d7c9c8

Please sign in to comment.