33 jassert (readerThreads.
size() == 0);
34 jassert (numWriters == 0);
41 readWaitEvent.
wait (100);
50 for (
auto& readerThread : readerThreads)
52 if (readerThread.threadID == threadId)
59 if (numWriters + numWaitingWriters == 0
60 || (threadId == writerThreadId && numWriters > 0))
62 readerThreads.add ({ threadId, 1 });
74 for (
int i = 0; i < readerThreads.
size(); ++i)
78 if (readerThread.threadID == threadId)
80 if (--(readerThread.count) == 0)
101 while (! tryEnterWriteInternal (threadId))
105 writeWaitEvent.
wait (100);
117 bool ReadWriteLock::tryEnterWriteInternal (
Thread::ThreadID threadId)
const noexcept
119 if (readerThreads.
size() + numWriters == 0
120 || threadId == writerThreadId
121 || (readerThreads.
size() == 1 && readerThreads.
getReference (0).threadID == threadId))
123 writerThreadId = threadId;
138 if (--numWriters == 0)
ReadWriteLock() noexcept
Creates a ReadWriteLock object.
void signal() const
Wakes up any threads that are currently waiting on this object.
void exitWrite() const noexcept
Releases the write-lock.
void * ThreadID
A value type used for thread IDs.
void ensureStorageAllocated(int minNumElements)
Increases the array's internal storage to hold a minimum number of elements.
bool tryEnterRead() const noexcept
Tries to lock this object for reading.
bool tryEnterWrite() const noexcept
Tries to lock this object for writing.
static ThreadID JUCE_CALLTYPE getCurrentThreadId()
Returns an id that identifies the caller thread.
void enter() const noexcept
Acquires the lock.
void exit() const noexcept
Releases the lock.
void enterRead() const noexcept
Locks this object for reading.
bool wait(int timeOutMilliseconds=-1) const
Suspends the calling thread until the event has been signalled.
int size() const noexcept
Returns the current number of elements in the array.
void enterWrite() const noexcept
Locks this object for writing.
~ReadWriteLock() noexcept
Destructor.
ElementType & getReference(int index) noexcept
Returns a direct reference to one of the elements in the array, without checking the index passed in...
Automatically locks and unlocks a mutex object.
void remove(int indexToRemove)
Removes an element from the array.
void exitRead() const noexcept
Releases the read-lock.