diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 8f8303efa8..2c3c9a8442 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -10,12 +10,10 @@ add_library(common) # x86emitter sources target_sources(common PRIVATE AlignedMalloc.cpp - EventSource.inl SafeArray.inl Console.cpp CrashHandler.cpp DynamicLibrary.cpp - EventSource.cpp Exceptions.cpp FastJmp.cpp FileSystem.cpp @@ -71,7 +69,6 @@ target_sources(common PRIVATE DynamicLibrary.h Easing.h EnumOps.h - EventSource.h Exceptions.h FastJmp.h FileSystem.h diff --git a/common/EventSource.cpp b/common/EventSource.cpp deleted file mode 100644 index 607cdc4616..0000000000 --- a/common/EventSource.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2002-2009 PCSX2 Dev Team - * - * PCSX2 is free software: you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with PCSX2. - * If not, see . - */ - -#include "PrecompiledHeader.h" -#include "EventSource.h" -#include "EventSource.inl" - -//template class EventSource< int >; diff --git a/common/EventSource.h b/common/EventSource.h deleted file mode 100644 index df6e5dd0c2..0000000000 --- a/common/EventSource.h +++ /dev/null @@ -1,94 +0,0 @@ -/* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2002-2010 PCSX2 Dev Team - * - * PCSX2 is free software: you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with PCSX2. - * If not, see . - */ - -#pragma once - -#include -#include - -// -------------------------------------------------------------------------------------- -// EventSource< template EvtType > -// -------------------------------------------------------------------------------------- - -template -class EventSource -{ -public: - typedef typename ListenerType::EvtParams EvtParams; - typedef typename std::list ListenerList; - typedef typename ListenerList::iterator ListenerIterator; - -protected: - typedef typename ListenerList::const_iterator ConstIterator; - - ListenerList m_listeners; - - // This is a cached copy of the listener list used to handle standard dispatching, which - // allows for self-modification of the EventSource's listener list by the listeners. - // Translation: The dispatcher uses this copy instead, to avoid iterator invalidation. - ListenerList m_cache_copy; - bool m_cache_valid; - - std::mutex m_listeners_lock; - -public: - EventSource() - { - m_cache_valid = false; - } - - virtual ~EventSource() = default; - - virtual ListenerIterator Add(ListenerType& listener); - virtual void Remove(ListenerType& listener); - virtual void Remove(const ListenerIterator& listenerHandle); - - void Add(ListenerType* listener) - { - if (listener == NULL) - return; - Add(*listener); - } - - void Remove(ListenerType* listener) - { - if (listener == NULL) - return; - Remove(*listener); - } - - void Dispatch(const EvtParams& params); - -protected: - virtual ListenerIterator _AddFast_without_lock(ListenerType& listener); - virtual void _DispatchRaw(ListenerIterator iter, const ListenerIterator& iend, const EvtParams& params); -}; - -// -------------------------------------------------------------------------------------- -// IEventDispatcher -// -------------------------------------------------------------------------------------- -// This class is used as a base interface for EventListeners. It allows the listeners to do -// customized dispatching of several event types into "user friendly" function overrides. -// -template -class IEventDispatcher -{ -protected: - IEventDispatcher() {} - -public: - virtual ~IEventDispatcher() = default; - virtual void DispatchEvent(const EvtParams& params) = 0; -}; diff --git a/common/EventSource.inl b/common/EventSource.inl deleted file mode 100644 index 6342ad9d8d..0000000000 --- a/common/EventSource.inl +++ /dev/null @@ -1,110 +0,0 @@ -/* PCSX2 - PS2 Emulator for PCs -* Copyright (C) 2002-2010 PCSX2 Dev Team -* -* PCSX2 is free software: you can redistribute it and/or modify it under the terms -* of the GNU Lesser General Public License as published by the Free Software Found- -* ation, either version 3 of the License, or (at your option) any later version. -* -* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; -* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -* PURPOSE. See the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License along with PCSX2. -* If not, see . -*/ - -#pragma once -#include "common/Pcsx2Defs.h" -#include "common/Exceptions.h" -#include "common/Console.h" - -template -typename EventSource::ListenerIterator EventSource::Add(ListenerType& listener) -{ - std::unique_lock locker(m_listeners_lock); - - // Check for duplicates before adding the event. - if (IsDebugBuild) - { - ListenerIterator iter = m_listeners.begin(); - while (iter != m_listeners.end()) - { - if ((*iter) == &listener) - return iter; - ++iter; - } - } - return _AddFast_without_lock(listener); -} - -template -void EventSource::Remove(ListenerType& listener) -{ - std::unique_lock locker(m_listeners_lock); - m_cache_valid = false; - m_listeners.remove(&listener); -} - -template -void EventSource::Remove(const ListenerIterator& listenerHandle) -{ - std::unique_lock locker(m_listeners_lock); - m_cache_valid = false; - m_listeners.erase(listenerHandle); -} - -template -typename EventSource::ListenerIterator EventSource::_AddFast_without_lock(ListenerType& listener) -{ - m_cache_valid = false; - m_listeners.push_front(&listener); - return m_listeners.begin(); -} - - -template -__fi void EventSource::_DispatchRaw(ListenerIterator iter, const ListenerIterator& iend, const EvtParams& evtparams) -{ - while (iter != iend) - { - try - { - (*iter)->DispatchEvent(evtparams); - } - catch (Exception::RuntimeError& ex) - { - if (IsDevBuild) - { - pxFailDev(("Ignoring runtime error thrown from event listener (event listeners should not throw exceptions!): " + ex.FormatDiagnosticMessage()).c_str()); - } - else - { - Console.Error("Ignoring runtime error thrown from event listener: %s", ex.FormatDiagnosticMessage().c_str()); - } - } - catch (BaseException& ex) - { - if (IsDevBuild) - { - ex.DiagMsg() = "Non-runtime BaseException thrown from event listener .. " + ex.DiagMsg(); - throw; - } - Console.Error("Ignoring non-runtime BaseException thrown from event listener: %s", ex.FormatDiagnosticMessage().c_str()); - } - ++iter; - } -} - -template -void EventSource::Dispatch(const EvtParams& evtparams) -{ - if (!m_cache_valid) - { - m_cache_copy = m_listeners; - m_cache_valid = true; - } - - if (m_cache_copy.empty()) - return; - _DispatchRaw(m_cache_copy.begin(), m_cache_copy.end(), evtparams); -} diff --git a/common/common.vcxproj b/common/common.vcxproj index 68bdfd19f5..9c981505a4 100644 --- a/common/common.vcxproj +++ b/common/common.vcxproj @@ -130,7 +130,6 @@ - @@ -178,7 +177,6 @@ - diff --git a/common/common.vcxproj.filters b/common/common.vcxproj.filters index c419d377f9..00a6998d07 100644 --- a/common/common.vcxproj.filters +++ b/common/common.vcxproj.filters @@ -232,9 +232,6 @@ Header Files - - Header Files - Header Files @@ -530,9 +527,6 @@ - - Source Files - Source Files\Vulkan