Merge pull request #20 from lioncash/move

BooObject: Make ObjToken interface noexcept where applicable
This commit is contained in:
Phillip Stephens 2019-08-17 22:56:26 -07:00 committed by GitHub
commit 8114361966
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 92 additions and 96 deletions

View File

@ -1,8 +1,6 @@
#pragma once #pragma once
#include <atomic> #include <atomic>
#include <mutex>
#include "nxstl/mutex"
namespace boo { namespace boo {
@ -13,11 +11,10 @@ protected:
virtual ~IObj() = default; virtual ~IObj() = default;
public: public:
virtual std::unique_lock<std::recursive_mutex> destructorLock() = 0; void increment() noexcept { m_refCount.fetch_add(1, std::memory_order_relaxed); }
void increment() { m_refCount++; } void decrement() noexcept {
void decrement() { if (m_refCount.fetch_sub(1, std::memory_order_release) == 1) {
if (m_refCount.fetch_sub(1) == 1) { std::atomic_thread_fence(std::memory_order_acquire);
auto lk = destructorLock();
delete this; delete this;
} }
} }
@ -28,17 +25,17 @@ class ObjToken {
SubCls* m_obj = nullptr; SubCls* m_obj = nullptr;
public: public:
ObjToken() = default; ObjToken() noexcept = default;
ObjToken(SubCls* obj) : m_obj(obj) { ObjToken(SubCls* obj) noexcept : m_obj(obj) {
if (m_obj) if (m_obj)
m_obj->increment(); m_obj->increment();
} }
ObjToken(const ObjToken& other) : m_obj(other.m_obj) { ObjToken(const ObjToken& other) noexcept : m_obj(other.m_obj) {
if (m_obj) if (m_obj)
m_obj->increment(); m_obj->increment();
} }
ObjToken(ObjToken&& other) : m_obj(other.m_obj) { other.m_obj = nullptr; } ObjToken(ObjToken&& other) noexcept : m_obj(other.m_obj) { other.m_obj = nullptr; }
ObjToken& operator=(SubCls* obj) { ObjToken& operator=(SubCls* obj) noexcept {
if (m_obj) if (m_obj)
m_obj->decrement(); m_obj->decrement();
m_obj = obj; m_obj = obj;
@ -46,7 +43,7 @@ public:
m_obj->increment(); m_obj->increment();
return *this; return *this;
} }
ObjToken& operator=(const ObjToken& other) { ObjToken& operator=(const ObjToken& other) noexcept {
if (m_obj) if (m_obj)
m_obj->decrement(); m_obj->decrement();
m_obj = other.m_obj; m_obj = other.m_obj;
@ -54,26 +51,26 @@ public:
m_obj->increment(); m_obj->increment();
return *this; return *this;
} }
ObjToken& operator=(ObjToken&& other) { ObjToken& operator=(ObjToken&& other) noexcept {
if (m_obj) if (m_obj)
m_obj->decrement(); m_obj->decrement();
m_obj = other.m_obj; m_obj = other.m_obj;
other.m_obj = nullptr; other.m_obj = nullptr;
return *this; return *this;
} }
~ObjToken() { ~ObjToken() noexcept {
if (m_obj) if (m_obj)
m_obj->decrement(); m_obj->decrement();
} }
SubCls* get() const { return m_obj; } SubCls* get() const noexcept { return m_obj; }
SubCls* operator->() const { return m_obj; } SubCls* operator->() const noexcept { return m_obj; }
SubCls& operator*() const { return *m_obj; } SubCls& operator*() const noexcept { return *m_obj; }
template <class T> template <class T>
T* cast() const { T* cast() const noexcept {
return static_cast<T*>(m_obj); return static_cast<T*>(m_obj);
} }
operator bool() const { return m_obj != nullptr; } operator bool() const noexcept { return m_obj != nullptr; }
void reset() { void reset() noexcept {
if (m_obj) if (m_obj)
m_obj->decrement(); m_obj->decrement();
m_obj = nullptr; m_obj = nullptr;

View File

@ -1,5 +1,4 @@
#include "AudioVoiceEngine.hpp" #include "AudioVoiceEngine.hpp"
#include "logvisor/logvisor.hpp"
#include "boo/IApplication.hpp" #include "boo/IApplication.hpp"
#include "../CFPointer.hpp" #include "../CFPointer.hpp"
@ -7,8 +6,7 @@
#include <CoreMIDI/CoreMIDI.h> #include <CoreMIDI/CoreMIDI.h>
#include <CoreAudio/HostTime.h> #include <CoreAudio/HostTime.h>
#include <mutex> #include <logvisor/logvisor.hpp>
#include <condition_variable>
namespace boo { namespace boo {
static logvisor::Module Log("boo::AQS"); static logvisor::Module Log("boo::AQS");

View File

@ -21,9 +21,6 @@ AudioSubmix*& AudioSubmix::_getHeadPtr(BaseAudioVoiceEngine* head) { return head
std::unique_lock<std::recursive_mutex> AudioSubmix::_getHeadLock(BaseAudioVoiceEngine* head) { std::unique_lock<std::recursive_mutex> AudioSubmix::_getHeadLock(BaseAudioVoiceEngine* head) {
return std::unique_lock<std::recursive_mutex>{head->m_dataMutex}; return std::unique_lock<std::recursive_mutex>{head->m_dataMutex};
} }
std::unique_lock<std::recursive_mutex> AudioSubmix::destructorLock() {
return std::unique_lock<std::recursive_mutex>{m_head->m_dataMutex};
}
bool AudioSubmix::_isDirectDependencyOf(AudioSubmix* send) { return m_sendGains.find(send) != m_sendGains.cend(); } bool AudioSubmix::_isDirectDependencyOf(AudioSubmix* send) { return m_sendGains.find(send) != m_sendGains.cend(); }

View File

@ -1,10 +1,11 @@
#pragma once #pragma once
#include "boo/audiodev/IAudioSubmix.hpp" #include "boo/audiodev/IAudioSubmix.hpp"
#include <list>
#include <vector>
#include <array> #include <array>
#include <list>
#include <mutex>
#include <unordered_map> #include <unordered_map>
#include <vector>
#include "Common.hpp" #include "Common.hpp"
#if __SSE__ #if __SSE__
@ -80,7 +81,6 @@ class AudioSubmix : public ListNode<AudioSubmix, BaseAudioVoiceEngine*, IAudioSu
public: public:
static AudioSubmix*& _getHeadPtr(BaseAudioVoiceEngine* head); static AudioSubmix*& _getHeadPtr(BaseAudioVoiceEngine* head);
static std::unique_lock<std::recursive_mutex> _getHeadLock(BaseAudioVoiceEngine* head); static std::unique_lock<std::recursive_mutex> _getHeadLock(BaseAudioVoiceEngine* head);
std::unique_lock<std::recursive_mutex> destructorLock() override;
AudioSubmix(BaseAudioVoiceEngine& root, IAudioSubmixCallback* cb, int busId, bool mainOut); AudioSubmix(BaseAudioVoiceEngine& root, IAudioSubmixCallback* cb, int busId, bool mainOut);
~AudioSubmix() override; ~AudioSubmix() override;

View File

@ -18,9 +18,6 @@ AudioVoice*& AudioVoice::_getHeadPtr(BaseAudioVoiceEngine* head) { return head->
std::unique_lock<std::recursive_mutex> AudioVoice::_getHeadLock(BaseAudioVoiceEngine* head) { std::unique_lock<std::recursive_mutex> AudioVoice::_getHeadLock(BaseAudioVoiceEngine* head) {
return std::unique_lock<std::recursive_mutex>{head->m_dataMutex}; return std::unique_lock<std::recursive_mutex>{head->m_dataMutex};
} }
std::unique_lock<std::recursive_mutex> AudioVoice::destructorLock() {
return std::unique_lock<std::recursive_mutex>{m_head->m_dataMutex};
}
void AudioVoice::_setPitchRatio(double ratio, bool slew) { void AudioVoice::_setPitchRatio(double ratio, bool slew) {
if (m_dynamicRate) { if (m_dynamicRate) {

View File

@ -1,12 +1,12 @@
#pragma once #pragma once
#include <soxr.h> #include <soxr.h>
#include <list> #include <mutex>
#include <unordered_map> #include <unordered_map>
#include "boo/audiodev/IAudioVoice.hpp" #include "boo/audiodev/IAudioVoice.hpp"
#include "AudioMatrix.hpp" #include "AudioMatrix.hpp"
#include "Common.hpp"
#include "AudioVoiceEngine.hpp" #include "AudioVoiceEngine.hpp"
#include "Common.hpp"
struct AudioUnitVoiceEngine; struct AudioUnitVoiceEngine;
struct VSTVoiceEngine; struct VSTVoiceEngine;
@ -64,7 +64,6 @@ protected:
public: public:
static AudioVoice*& _getHeadPtr(BaseAudioVoiceEngine* head); static AudioVoice*& _getHeadPtr(BaseAudioVoiceEngine* head);
static std::unique_lock<std::recursive_mutex> _getHeadLock(BaseAudioVoiceEngine* head); static std::unique_lock<std::recursive_mutex> _getHeadLock(BaseAudioVoiceEngine* head);
std::unique_lock<std::recursive_mutex> destructorLock() override;
~AudioVoice() override; ~AudioVoice() override;
void resetSampleRate(double sampleRate) override; void resetSampleRate(double sampleRate) override;

View File

@ -3,14 +3,15 @@
/* Private header for managing shader data /* Private header for managing shader data
* binding lifetimes through rendering cycle */ * binding lifetimes through rendering cycle */
#include <array>
#include <atomic> #include <atomic>
#include <vector>
#include <mutex>
#include <cassert> #include <cassert>
#include <thread>
#include <mutex>
#include <condition_variable> #include <condition_variable>
#include <mutex>
#include <queue> #include <queue>
#include <thread>
#include <vector>
#include "boo/graphicsdev/IGraphicsDataFactory.hpp" #include "boo/graphicsdev/IGraphicsDataFactory.hpp"
#include "boo/graphicsdev/IGraphicsCommandQueue.hpp" #include "boo/graphicsdev/IGraphicsCommandQueue.hpp"
#include "../Common.hpp" #include "../Common.hpp"
@ -63,9 +64,6 @@ struct BaseGraphicsData : ListNode<BaseGraphicsData, GraphicsDataFactoryHead*> {
auto* head = getHead<T>(); auto* head = getHead<T>();
return head ? head->countForward() : 0; return head ? head->countForward() : 0;
} }
std::unique_lock<std::recursive_mutex> destructorLock() override {
return std::unique_lock<std::recursive_mutex>{m_head->m_dataMutex};
}
explicit BaseGraphicsData(GraphicsDataFactoryHead& head __BooTraceArgs) explicit BaseGraphicsData(GraphicsDataFactoryHead& head __BooTraceArgs)
: ListNode<BaseGraphicsData, GraphicsDataFactoryHead*>(&head) __BooTraceInitializer {} : ListNode<BaseGraphicsData, GraphicsDataFactoryHead*>(&head) __BooTraceInitializer {}
@ -131,9 +129,6 @@ struct BaseGraphicsPool : ListNode<BaseGraphicsPool, GraphicsDataFactoryHead*> {
auto* head = getHead<T>(); auto* head = getHead<T>();
return head ? head->countForward() : 0; return head ? head->countForward() : 0;
} }
std::unique_lock<std::recursive_mutex> destructorLock() override {
return std::unique_lock<std::recursive_mutex>{m_head->m_dataMutex};
}
explicit BaseGraphicsPool(GraphicsDataFactoryHead& head __BooTraceArgs) explicit BaseGraphicsPool(GraphicsDataFactoryHead& head __BooTraceArgs)
: ListNode<BaseGraphicsPool, GraphicsDataFactoryHead*>(&head) __BooTraceInitializer {} : ListNode<BaseGraphicsPool, GraphicsDataFactoryHead*>(&head) __BooTraceInitializer {}
@ -158,10 +153,6 @@ struct GraphicsDataNode : ListNode<GraphicsDataNode<NodeCls, DataCls>, ObjToken<
return std::unique_lock<std::recursive_mutex>{head->m_head->m_dataMutex}; return std::unique_lock<std::recursive_mutex>{head->m_head->m_dataMutex};
} }
std::unique_lock<std::recursive_mutex> destructorLock() override {
return std::unique_lock<std::recursive_mutex>{base::m_head->m_head->m_dataMutex};
}
explicit GraphicsDataNode(const ObjToken<DataCls>& data) explicit GraphicsDataNode(const ObjToken<DataCls>& data)
: ListNode<GraphicsDataNode<NodeCls, DataCls>, ObjToken<DataCls>, NodeCls>(data) {} : ListNode<GraphicsDataNode<NodeCls, DataCls>, ObjToken<DataCls>, NodeCls>(data) {}

View File

@ -1,18 +1,20 @@
#include "../win/Win32Common.hpp" #include "../win/Win32Common.hpp"
#include "logvisor/logvisor.hpp"
#include "boo/graphicsdev/D3D.hpp" #include "boo/graphicsdev/D3D.hpp"
#include "boo/IGraphicsContext.hpp" #include "boo/IGraphicsContext.hpp"
#include "Common.hpp" #include "Common.hpp"
#include <vector>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <d3dcompiler.h>
#include <comdef.h>
#include <algorithm> #include <algorithm>
#include <atomic> #include <atomic>
#include <condition_variable>
#include <forward_list> #include <forward_list>
#include "xxhash/xxhash.h" #include <mutex>
#include <thread>
#include <vector>
#include <d3dcompiler.h>
#include <comdef.h>
#include <logvisor/logvisor.hpp>
#undef min #undef min
#undef max #undef max

View File

@ -2,22 +2,22 @@
#include "boo/graphicsdev/glew.h" #include "boo/graphicsdev/glew.h"
#include "boo/IApplication.hpp" #include "boo/IApplication.hpp"
#include "Common.hpp" #include "Common.hpp"
#include <thread>
#include <condition_variable>
#include <array> #include <array>
#include <unordered_map> #include <condition_variable>
#include <unordered_set> #include <mutex>
#include "xxhash/xxhash.h" #include <thread>
#include "glslang/Public/ShaderLang.h"
#include "glslang/Include/Types.h" #include <glslang/Public/ShaderLang.h>
#include "StandAlone/ResourceLimits.h" #include <glslang/Include/Types.h>
#include <StandAlone/ResourceLimits.h>
#include <logvisor/logvisor.hpp>
#if _WIN32 #if _WIN32
#include "../win/WinCommon.hpp" #include "../win/WinCommon.hpp"
#endif #endif
#include "logvisor/logvisor.hpp"
#undef min #undef min
#undef max #undef max

View File

@ -1060,9 +1060,6 @@ struct VulkanDescriptorPool : ListNode<VulkanDescriptorPool, VulkanDataFactoryIm
~VulkanDescriptorPool() { vk::DestroyDescriptorPool(m_head->m_ctx->m_dev, m_descPool, nullptr); } ~VulkanDescriptorPool() { vk::DestroyDescriptorPool(m_head->m_ctx->m_dev, m_descPool, nullptr); }
std::unique_lock<std::recursive_mutex> destructorLock() override {
return std::unique_lock<std::recursive_mutex>{m_head->m_dataMutex};
}
static std::unique_lock<std::recursive_mutex> _getHeadLock(VulkanDataFactoryImpl* factory) { static std::unique_lock<std::recursive_mutex> _getHeadLock(VulkanDataFactoryImpl* factory) {
return std::unique_lock<std::recursive_mutex>{factory->m_dataMutex}; return std::unique_lock<std::recursive_mutex>{factory->m_dataMutex};
} }

View File

@ -2,12 +2,13 @@
#include "IHIDDevice.hpp" #include "IHIDDevice.hpp"
#include "boo/inputdev/DeviceToken.hpp" #include "boo/inputdev/DeviceToken.hpp"
#include "boo/inputdev/DeviceBase.hpp" #include "boo/inputdev/DeviceBase.hpp"
#include <thread>
#include <mutex>
#include <condition_variable>
#include <cstring>
#include <cstdio>
#include <algorithm> #include <algorithm>
#include <condition_variable>
#include <cstdio>
#include <cstring>
#include <mutex>
#include <thread>
#ifndef WIN32_LEAN_AND_MEAN #ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1 #define WIN32_LEAN_AND_MEAN 1

View File

@ -1,12 +1,19 @@
#include "boo/graphicsdev/Metal.hpp" #include "boo/graphicsdev/Metal.hpp"
#include "CocoaCommon.hpp" #include "CocoaCommon.hpp"
#include "boo/IApplication.hpp"
#include "boo/IGraphicsContext.hpp"
#include "boo/IWindow.hpp"
#include "boo/audiodev/IAudioVoiceEngine.hpp"
#include <condition_variable>
#include <memory>
#include <mutex>
#import <AppKit/AppKit.h> #import <AppKit/AppKit.h>
#import <CoreVideo/CVDisplayLink.h> #import <CoreVideo/CVDisplayLink.h>
#include "boo/IApplication.hpp"
#include "boo/IWindow.hpp" #include <logvisor/logvisor.hpp>
#include "boo/IGraphicsContext.hpp"
#include "boo/audiodev/IAudioVoiceEngine.hpp"
#include "logvisor/logvisor.hpp"
#if !__has_feature(objc_arc) #if !__has_feature(objc_arc)
#error ARC Required #error ARC Required

View File

@ -1,9 +1,13 @@
#include "boo/IApplication.hpp"
#include "logvisor/logvisor.hpp"
#include "nxstl/thread" #include "nxstl/thread"
#include "nxstl/condition_variable" #include "nxstl/condition_variable"
#include "nxstl/mutex"
#include "boo/IApplication.hpp"
#include "boo/graphicsdev/NX.hpp" #include "boo/graphicsdev/NX.hpp"
#include <limits.h>
#include <climits>
#include <logvisor/logvisor.hpp>
#include <switch.h> #include <switch.h>

View File

@ -25,6 +25,9 @@ PFN_GetScaleFactorForMonitor MyGetScaleFactorForMonitor = nullptr;
#include "boo/graphicsdev/Vulkan.hpp" #include "boo/graphicsdev/Vulkan.hpp"
#endif #endif
#include <condition_variable>
#include <mutex>
DWORD g_mainThreadId = 0; DWORD g_mainThreadId = 0;
std::mutex g_nwmt; std::mutex g_nwmt;
std::condition_variable g_nwcv; std::condition_variable g_nwcv;

View File

@ -14,6 +14,9 @@
#endif #endif
#include "boo/graphicsdev/GL.hpp" #include "boo/graphicsdev/GL.hpp"
#include <condition_variable>
#include <mutex>
extern DWORD g_mainThreadId; extern DWORD g_mainThreadId;
extern std::mutex g_nwmt; extern std::mutex g_nwmt;
extern std::condition_variable g_nwcv; extern std::condition_variable g_nwcv;

View File

@ -12,16 +12,16 @@
#include <X11/extensions/XInput2.h> #include <X11/extensions/XInput2.h>
#include <GL/glx.h> #include <GL/glx.h>
#include <GL/glxext.h> #include <GL/glxext.h>
#include <locale>
#include <dbus/dbus.h> #include <dbus/dbus.h>
DBusConnection* RegisterDBus(const char* appName, bool& isFirst); DBusConnection* RegisterDBus(const char* appName, bool& isFirst);
#include <signal.h> #include <condition_variable>
#include <csignal>
#include <locale>
#include <mutex>
#include <sys/param.h> #include <sys/param.h>
#include <thread> #include <thread>
#include <mutex>
#include <condition_variable>
#include "XlibCommon.hpp" #include "XlibCommon.hpp"
#include <X11/cursorfont.h> #include <X11/cursorfont.h>

View File

@ -11,16 +11,16 @@
#include <X11/Xlib-xcb.h> #include <X11/Xlib-xcb.h>
#endif #endif
#include <limits.h> #include <climits>
#include <unistd.h>
#include <cstdlib>
#include <cstdio>
#include <cstdint> #include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring> #include <cstring>
#include <memory>
#include <string>
#include <unordered_set>
#include <thread> #include <unistd.h>
#include <mutex>
#include <condition_variable>
#include <GL/glx.h> #include <GL/glx.h>
@ -32,7 +32,7 @@
#include <X11/extensions/XInput2.h> #include <X11/extensions/XInput2.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
#include <X11/extensions/Xrandr.h> #include <X11/extensions/Xrandr.h>
#include "logvisor/logvisor.hpp" #include <logvisor/logvisor.hpp>
#include "XlibCommon.hpp" #include "XlibCommon.hpp"