Skip to content
Snippets Groups Projects
Commit a745c865 authored by Florian Fischer's avatar Florian Fischer
Browse files

[Blockable] add global set of all blocked contexts for debugging

This feature must be activated using the blocked_context_set meson option.
parent a2587f7f
No related branches found
No related tags found
No related merge requests found
......@@ -9,7 +9,11 @@
#include "Context.hpp"
#include "ContextManager.hpp"
#include "Debug.hpp"
#include "Emper.hpp"
#include "Runtime.hpp"
#include "lib/adt/LockedSet.hpp"
static emper::lib::adt::LockedSet<Context*> blockedContexts;
template <LogSubsystem logSubsystem>
class Blockable : public Logger<logSubsystem> {
......@@ -29,12 +33,21 @@ class Blockable : public Logger<logSubsystem> {
assert(Runtime::inRuntime());
LOGD("block() blockedContext is " << Context::getCurrentContext());
if constexpr (emper::BLOCKED_CONTEXT_SET) {
blockedContexts.insert(Context::getCurrentContext());
}
contextManager.saveAndStartNew(std::move(freshContextHook));
}
template <CallerEnvironment callerEnvironment = CallerEnvironment::EMPER>
void unblock(Context* context) {
assert(context != nullptr);
if constexpr (emper::BLOCKED_CONTEXT_SET) {
blockedContexts.erase(context);
}
// cppcheck-suppress unsafeClassCanLeak
Fiber* unblockFiber =
Fiber::from([this, context]() { contextManager.discardAndResume(context); });
......
......@@ -65,4 +65,12 @@ static const bool OVERFLOW_QUEUE =
;
auto getFullVersion() -> std::string;
static const bool BLOCKED_CONTEXT_SET =
#ifdef EMPER_BLOCKED_CONTEXT_SET
DEBUG
#else
false
#endif
;
} // namespace emper
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2020 Florian Fischer
#pragma once
#include <iterator>
#include <mutex>
#include <set>
namespace emper::lib::adt {
template <class Key, class Compare = std::less<Key>, class Allocator = std::allocator<Key>>
class LockedSet {
private:
std::mutex _mutex;
std::set<Key, Compare, Allocator> _set;
public:
auto insert(const Key& item)
-> std::pair<typename std::set<Key, Compare, Allocator>::iterator, bool> {
std::lock_guard<std::mutex> lock(_mutex);
return _set.insert(item);
}
template <class InputIt>
void insert(InputIt first, InputIt last) {
std::lock_guard<std::mutex> lock(_mutex);
_set.insert(first, last);
}
size_t erase(const Key& key) {
std::lock_guard<std::mutex> lock(_mutex);
return _set.erase(key);
}
};
} // namespace emper::lib::adt
......@@ -32,6 +32,7 @@ conf_data.set('EMPER_OVERFLOW_QUEUE', get_option('overflow_queue'))
conf_data.set('EMPER_LOCKED_MPSC_QUEUE', get_option('locked_mpsc_queue'))
conf_data.set('EMPER_STATS', get_option('stats'))
conf_data.set('EMPER_OVERFLOW_QUEUE', get_option('overflow_queue'))
conf_data.set('EMPER_BLOCKED_CONTEXT_SET', get_option('blocked_context_set'))
default_scheduling_strategy = get_option('default_scheduling_strategy')
conf_data.set('EMPER_DEFAULT_SCHEDULING_STRATEGY_' + default_scheduling_strategy.to_upper(), true)
......
......@@ -10,6 +10,12 @@ option(
choices: ['automatic', 'OFF', 'Error', 'Warning', 'Info', 'Debug', 'FineDebug', 'FinerDebug', 'FinestDebug', 'ALL'],
value: 'automatic',
)
option(
'blocked_context_set',
type: 'boolean',
value: false,
description: 'Store all currently blocked contexts for debugging in the set Blockable<LogLevel>::blocked'
)
option(
'log_timestamp',
type: 'boolean',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment