Loading...
Searching...
No Matches
juce_ReadWriteLock.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
To use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
class JUCE_API ReadWriteLock
{
public:
//==============================================================================
ReadWriteLock() noexcept;
~ReadWriteLock() noexcept;
//==============================================================================
void enterRead() const noexcept;
bool tryEnterRead() const noexcept;
void exitRead() const noexcept;
//==============================================================================
void enterWrite() const noexcept;
bool tryEnterWrite() const noexcept;
void exitWrite() const noexcept;
private:
//==============================================================================
SpinLock accessLock;
WaitableEvent readWaitEvent, writeWaitEvent;
mutable int numWaitingWriters = 0, numWriters = 0;
mutable Thread::ThreadID writerThreadId = {};
struct ThreadRecursionCount
{
Thread::ThreadID threadID;
int count;
};
mutable Array <ThreadRecursionCount> readerThreads;
bool tryEnterWriteInternal (Thread::ThreadID) const noexcept;
JUCE_DECLARE_NON_COPYABLE (ReadWriteLock)
};
} // namespace juce
juce::ReadWriteLock::ReadWriteLock
ReadWriteLock() noexcept
Definition juce_ReadWriteLock.cpp:26
juce::ReadWriteLock::tryEnterRead
bool tryEnterRead() const noexcept
Definition juce_ReadWriteLock.cpp:44
juce::ReadWriteLock::enterWrite
void enterWrite() const noexcept
Definition juce_ReadWriteLock.cpp:96
juce::ReadWriteLock::exitRead
void exitRead() const noexcept
Definition juce_ReadWriteLock.cpp:69
juce::ReadWriteLock::enterRead
void enterRead() const noexcept
Definition juce_ReadWriteLock.cpp:38
juce::ReadWriteLock::exitWrite
void exitWrite() const noexcept
Definition juce_ReadWriteLock.cpp:131
juce::ReadWriteLock::tryEnterWrite
bool tryEnterWrite() const noexcept
Definition juce_ReadWriteLock.cpp:111
juce::SpinLock
Definition juce_SpinLock.h:42
juce::Thread::ThreadID
void * ThreadID
Definition juce_Thread.h:477
juce::WaitableEvent
Definition juce_WaitableEvent.h:36