mirror of
https://github.com/hyprwm/hyprutils.git
synced 2025-12-20 21:00:05 +01:00
Compare commits
3 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
51a4f93ce8 | ||
|
|
5ac060bfcf | ||
| 1c527b30fe |
3 changed files with 31 additions and 22 deletions
|
|
@ -26,10 +26,13 @@ namespace Hyprutils {
|
|||
template <typename... Args>
|
||||
class CSignalT : public CSignalBase {
|
||||
template <typename T>
|
||||
using RefArg = std::conditional_t<std::is_reference_v<T> || std::is_arithmetic_v<T>, T, const T&>;
|
||||
using RefArg = std::conditional_t<std::is_trivially_copyable_v<T>, T, const T&>;
|
||||
|
||||
public:
|
||||
void emit(RefArg<Args>... args) {
|
||||
if (m_vListeners.empty() && m_vStaticListeners.empty())
|
||||
return;
|
||||
|
||||
if constexpr (sizeof...(Args) == 0)
|
||||
emitInternal(nullptr);
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -134,6 +134,7 @@ void CLoggerImpl::log(eLogLevel level, const std::string_view& msg, const std::s
|
|||
if (m_stdoutEnabled) {
|
||||
try {
|
||||
std::println("{}{}", m_colorEnabled ? logPrefixColor : logPrefix, logMsg);
|
||||
std::fflush(stdout);
|
||||
} catch (std::exception& e) {
|
||||
; // this could be e.g. stdout closed
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,18 +10,18 @@ using namespace Hyprutils::Memory;
|
|||
#define WP CWeakPointer
|
||||
|
||||
void Hyprutils::Signal::CSignalBase::emitInternal(void* args) {
|
||||
if (!m_vListeners.empty()) {
|
||||
std::vector<SP<CSignalListener>> listeners;
|
||||
listeners.reserve(m_vListeners.size());
|
||||
for (auto& l : m_vListeners) {
|
||||
|
||||
for (const auto& l : m_vListeners) {
|
||||
if (l.expired())
|
||||
continue;
|
||||
|
||||
listeners.emplace_back(l.lock());
|
||||
}
|
||||
|
||||
auto statics = m_vStaticListeners;
|
||||
|
||||
for (auto& l : listeners) {
|
||||
for (const auto& l : listeners) {
|
||||
// if there is only one lock, it means the event is only held by the listeners
|
||||
// vector and was removed during our iteration
|
||||
if (l.strongRef() == 1)
|
||||
|
|
@ -30,12 +30,17 @@ void Hyprutils::Signal::CSignalBase::emitInternal(void* args) {
|
|||
l->emitInternal(args);
|
||||
}
|
||||
|
||||
for (auto& l : statics) {
|
||||
l->emitInternal(args);
|
||||
}
|
||||
|
||||
// release SPs
|
||||
listeners.clear();
|
||||
}
|
||||
|
||||
if (!m_vStaticListeners.empty()) {
|
||||
const auto statics = m_vStaticListeners;
|
||||
|
||||
for (const auto& l : statics) {
|
||||
l->emitInternal(args);
|
||||
}
|
||||
}
|
||||
|
||||
// we cannot release any expired refs here as one of the listeners could've removed this object and
|
||||
// as such we'd be doing a UAF
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue