mirror of
https://github.com/latentPrion/libspinscale.git
synced 2026-06-23 19:48:32 +00:00
CoQutex: Add instance name for debugging
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
#include <coroutine>
|
#include <coroutine>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#ifdef CONFIG_LIBSSCL_DEBUG_CO
|
#ifdef CONFIG_LIBSSCL_DEBUG_CO
|
||||||
@@ -28,6 +29,15 @@ public:
|
|||||||
class ReleaseHandle;
|
class ReleaseHandle;
|
||||||
|
|
||||||
CoQutex() noexcept = default;
|
CoQutex() noexcept = default;
|
||||||
|
|
||||||
|
CoQutex([[maybe_unused]] const std::string &_name) noexcept
|
||||||
|
:
|
||||||
|
#ifdef CONFIG_ENABLE_DEBUG_LOCKS
|
||||||
|
name(_name),
|
||||||
|
#endif
|
||||||
|
isOwned(false)
|
||||||
|
{}
|
||||||
|
|
||||||
CoQutex(const CoQutex &) = delete;
|
CoQutex(const CoQutex &) = delete;
|
||||||
CoQutex(CoQutex &&) noexcept = delete;
|
CoQutex(CoQutex &&) noexcept = delete;
|
||||||
CoQutex &operator=(const CoQutex &) = delete;
|
CoQutex &operator=(const CoQutex &) = delete;
|
||||||
@@ -77,7 +87,13 @@ public:
|
|||||||
std::cout << __func__ << ": " << std::this_thread::get_id() << " Walking caller promise chain.\n";
|
std::cout << __func__ << ": " << std::this_thread::get_id() << " Walking caller promise chain.\n";
|
||||||
#endif
|
#endif
|
||||||
if (link.holdsAcquiredLock(coQutex)) {
|
if (link.holdsAcquiredLock(coQutex)) {
|
||||||
throw std::runtime_error("Deadlock detected: CoQutex re-acquire on caller promise chain.");
|
std::string message =
|
||||||
|
"Deadlock detected: CoQutex re-acquire on caller promise chain";
|
||||||
|
#ifdef CONFIG_ENABLE_DEBUG_LOCKS
|
||||||
|
message += " (" + coQutex.name + ")";
|
||||||
|
#endif
|
||||||
|
message += ".";
|
||||||
|
throw std::runtime_error(message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -130,6 +146,9 @@ private:
|
|||||||
waitingCoroutines.pop_front();
|
waitingCoroutines.pop_front();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_ENABLE_DEBUG_LOCKS
|
||||||
|
std::string name;
|
||||||
|
#endif
|
||||||
sscl::SpinLock spinLock;
|
sscl::SpinLock spinLock;
|
||||||
bool isOwned = false;
|
bool isOwned = false;
|
||||||
std::deque<AcquireInvocationAndSuspensionPolicy::WaitingCoroutine> waitingCoroutines;
|
std::deque<AcquireInvocationAndSuspensionPolicy::WaitingCoroutine> waitingCoroutines;
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef SHARED_RESOURCE_GROUP_H
|
#ifndef SHARED_RESOURCE_GROUP_H
|
||||||
#define SHARED_RESOURCE_GROUP_H
|
#define SHARED_RESOURCE_GROUP_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace sscl {
|
namespace sscl {
|
||||||
|
|
||||||
template <typename LockType, typename ResourceType>
|
template <typename LockType, typename ResourceType>
|
||||||
@@ -8,6 +10,11 @@ class SharedResourceGroup
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SharedResourceGroup() = default;
|
SharedResourceGroup() = default;
|
||||||
|
|
||||||
|
explicit SharedResourceGroup(const std::string& lockName)
|
||||||
|
: lock(lockName)
|
||||||
|
{}
|
||||||
|
|
||||||
~SharedResourceGroup() = default;
|
~SharedResourceGroup() = default;
|
||||||
|
|
||||||
LockType lock;
|
LockType lock;
|
||||||
|
|||||||
Reference in New Issue
Block a user