BooObject: Remove destructorLock()

Now that we have the fencing and atomic operations in place to ensure
access to data on other threads will always occur before the use of
delete, we can remove the destructor lock. This will be useful for
making ObjToken's move assignment operator noexcept.
This commit is contained in:
Lioncash 2019-08-17 13:39:39 -04:00
parent 4d91a1b3c3
commit 84f62a0f2c
17 changed files with 75 additions and 80 deletions

View File

@ -1,8 +1,6 @@
#pragma once
#include <atomic>
#include <mutex>
#include "nxstl/mutex"
namespace boo {
@ -13,12 +11,10 @@ protected:
virtual ~IObj() = default;
public:
virtual std::unique_lock<std::recursive_mutex> destructorLock() = 0;
void increment() { m_refCount.fetch_add(1, std::memory_order_relaxed); }
void decrement() {
if (m_refCount.fetch_sub(1, std::memory_order_acq_rel) == 1) {
if (m_refCount.fetch_sub(1, std::memory_order_release) == 1) {
std::atomic_thread_fence(std::memory_order_acquire);
auto lk = destructorLock();
delete this;
}
}

View File

@ -1,5 +1,4 @@
#include "AudioVoiceEngine.hpp"
#include "logvisor/logvisor.hpp"
#include "boo/IApplication.hpp"
#include "../CFPointer.hpp"
@ -7,8 +6,7 @@
#include <CoreMIDI/CoreMIDI.h>
#include <CoreAudio/HostTime.h>
#include <mutex>
#include <condition_variable>
#include <logvisor/logvisor.hpp>
namespace boo {
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) {
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(); }

View File

@ -1,10 +1,11 @@
#pragma once
#include "boo/audiodev/IAudioSubmix.hpp"
#include <list>
#include <vector>
#include <array>
#include <list>
#include <mutex>
#include <unordered_map>
#include <vector>
#include "Common.hpp"
#if __SSE__
@ -80,7 +81,6 @@ class AudioSubmix : public ListNode<AudioSubmix, BaseAudioVoiceEngine*, IAudioSu
public:
static AudioSubmix*& _getHeadPtr(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() override;

View File

@ -18,9 +18,6 @@ AudioVoice*& AudioVoice::_getHeadPtr(BaseAudioVoiceEngine* head) { return head->
std::unique_lock<std::recursive_mutex> AudioVoice::_getHeadLock(BaseAudioVoiceEngine* head) {
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) {
if (m_dynamicRate) {

View File

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

View File

@ -3,14 +3,15 @@
/* Private header for managing shader data
* binding lifetimes through rendering cycle */
#include <array>
#include <atomic>
#include <vector>
#include <mutex>
#include <cassert>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <mutex>
#include <queue>
#include <thread>
#include <vector>
#include "boo/graphicsdev/IGraphicsDataFactory.hpp"
#include "boo/graphicsdev/IGraphicsCommandQueue.hpp"
#include "../Common.hpp"
@ -63,9 +64,6 @@ struct BaseGraphicsData : ListNode<BaseGraphicsData, GraphicsDataFactoryHead*> {
auto* head = getHead<T>();
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)
: ListNode<BaseGraphicsData, GraphicsDataFactoryHead*>(&head) __BooTraceInitializer {}
@ -131,9 +129,6 @@ struct BaseGraphicsPool : ListNode<BaseGraphicsPool, GraphicsDataFactoryHead*> {
auto* head = getHead<T>();
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)
: 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};
}
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)
: ListNode<GraphicsDataNode<NodeCls, DataCls>, ObjToken<DataCls>, NodeCls>(data) {}

View File

@ -1,18 +1,20 @@
#include "../win/Win32Common.hpp"
#include "logvisor/logvisor.hpp"
#include "boo/graphicsdev/D3D.hpp"
#include "boo/IGraphicsContext.hpp"
#include "Common.hpp"
#include <vector>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <d3dcompiler.h>
#include <comdef.h>
#include <algorithm>
#include <atomic>
#include <condition_variable>
#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 max

View File

@ -2,22 +2,22 @@
#include "boo/graphicsdev/glew.h"
#include "boo/IApplication.hpp"
#include "Common.hpp"
#include <thread>
#include <condition_variable>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include "xxhash/xxhash.h"
#include "glslang/Public/ShaderLang.h"
#include "glslang/Include/Types.h"
#include "StandAlone/ResourceLimits.h"
#include <condition_variable>
#include <mutex>
#include <thread>
#include <glslang/Public/ShaderLang.h>
#include <glslang/Include/Types.h>
#include <StandAlone/ResourceLimits.h>
#include <logvisor/logvisor.hpp>
#if _WIN32
#include "../win/WinCommon.hpp"
#endif
#include "logvisor/logvisor.hpp"
#undef min
#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); }
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) {
return std::unique_lock<std::recursive_mutex>{factory->m_dataMutex};
}

View File

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

View File

@ -1,12 +1,19 @@
#include "boo/graphicsdev/Metal.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 <CoreVideo/CVDisplayLink.h>
#include "boo/IApplication.hpp"
#include "boo/IWindow.hpp"
#include "boo/IGraphicsContext.hpp"
#include "boo/audiodev/IAudioVoiceEngine.hpp"
#include "logvisor/logvisor.hpp"
#include <logvisor/logvisor.hpp>
#if !__has_feature(objc_arc)
#error ARC Required

View File

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

View File

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

View File

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

View File

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

View File

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