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>
|
template <typename... Args>
|
||||||
class CSignalT : public CSignalBase {
|
class CSignalT : public CSignalBase {
|
||||||
template <typename T>
|
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:
|
public:
|
||||||
void emit(RefArg<Args>... args) {
|
void emit(RefArg<Args>... args) {
|
||||||
|
if (m_vListeners.empty() && m_vStaticListeners.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
if constexpr (sizeof...(Args) == 0)
|
if constexpr (sizeof...(Args) == 0)
|
||||||
emitInternal(nullptr);
|
emitInternal(nullptr);
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
|
|
@ -134,6 +134,7 @@ void CLoggerImpl::log(eLogLevel level, const std::string_view& msg, const std::s
|
||||||
if (m_stdoutEnabled) {
|
if (m_stdoutEnabled) {
|
||||||
try {
|
try {
|
||||||
std::println("{}{}", m_colorEnabled ? logPrefixColor : logPrefix, logMsg);
|
std::println("{}{}", m_colorEnabled ? logPrefixColor : logPrefix, logMsg);
|
||||||
|
std::fflush(stdout);
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
; // this could be e.g. stdout closed
|
; // this could be e.g. stdout closed
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,18 +10,18 @@ using namespace Hyprutils::Memory;
|
||||||
#define WP CWeakPointer
|
#define WP CWeakPointer
|
||||||
|
|
||||||
void Hyprutils::Signal::CSignalBase::emitInternal(void* args) {
|
void Hyprutils::Signal::CSignalBase::emitInternal(void* args) {
|
||||||
|
if (!m_vListeners.empty()) {
|
||||||
std::vector<SP<CSignalListener>> listeners;
|
std::vector<SP<CSignalListener>> listeners;
|
||||||
listeners.reserve(m_vListeners.size());
|
listeners.reserve(m_vListeners.size());
|
||||||
for (auto& l : m_vListeners) {
|
|
||||||
|
for (const auto& l : m_vListeners) {
|
||||||
if (l.expired())
|
if (l.expired())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
listeners.emplace_back(l.lock());
|
listeners.emplace_back(l.lock());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto statics = m_vStaticListeners;
|
for (const auto& l : listeners) {
|
||||||
|
|
||||||
for (auto& l : listeners) {
|
|
||||||
// if there is only one lock, it means the event is only held by the listeners
|
// if there is only one lock, it means the event is only held by the listeners
|
||||||
// vector and was removed during our iteration
|
// vector and was removed during our iteration
|
||||||
if (l.strongRef() == 1)
|
if (l.strongRef() == 1)
|
||||||
|
|
@ -30,12 +30,17 @@ void Hyprutils::Signal::CSignalBase::emitInternal(void* args) {
|
||||||
l->emitInternal(args);
|
l->emitInternal(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& l : statics) {
|
|
||||||
l->emitInternal(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
// release SPs
|
// release SPs
|
||||||
listeners.clear();
|
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
|
// 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
|
// as such we'd be doing a UAF
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue