JUCE  v6.1.6 (6.0.8-1114)
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::MessageManager::Lock Class Reference

A lock you can use to lock the message manager. More...

#include <juce_MessageManager.h>

Collaboration diagram for juce::MessageManager::Lock:

Public Types

using ScopedLockType = GenericScopedLock< Lock >
 Provides the type of scoped lock to use with a CriticalSection. More...
 
using ScopedTryLockType = GenericScopedTryLock< Lock >
 Provides the type of scoped try-locker to use with a CriticalSection. More...
 
using ScopedUnlockType = GenericScopedUnlock< Lock >
 Provides the type of scoped unlocker to use with a CriticalSection. More...
 

Public Member Functions

 Lock ()
 Creates a new critical section to exclusively access methods which can only be called when the message manager is locked. More...
 
 ~Lock ()
 Destructor. More...
 
void abort () const noexcept
 Unblocks a thread which is waiting in tryEnter Call this method if you want to unblock a thread which is waiting for the MessageManager lock in tryEnter. More...
 
void enter () const noexcept
 Acquires the message manager lock. More...
 
void exit () const noexcept
 Releases the message manager lock. More...
 
bool tryEnter () const noexcept
 Attempts to lock the message manager and exits if abort is called. More...
 

Private Member Functions

void messageCallback () const
 
bool tryAcquire (bool) const noexcept
 

Private Attributes

Atomic< intabortWait
 
ReferenceCountedObjectPtr< BlockingMessage > blockingMessage
 
WaitableEvent lockedEvent
 
Atomic< intlockGained
 

Friends

class ReferenceCountedObjectPtr< BlockingMessage >
 

Detailed Description

A lock you can use to lock the message manager.

You can use this class with the RAII-based ScopedLock classes.

Member Typedef Documentation

◆ ScopedLockType

Provides the type of scoped lock to use with a CriticalSection.

◆ ScopedTryLockType

Provides the type of scoped try-locker to use with a CriticalSection.

◆ ScopedUnlockType

Provides the type of scoped unlocker to use with a CriticalSection.

Constructor & Destructor Documentation

◆ Lock()

juce::MessageManager::Lock::Lock ( )

Creates a new critical section to exclusively access methods which can only be called when the message manager is locked.

Unlike CriticalSection, multiple instances of this lock class provide exclusive access to a single resource - the MessageManager.

◆ ~Lock()

juce::MessageManager::Lock::~Lock ( )

Destructor.

Member Function Documentation

◆ abort()

void juce::MessageManager::Lock::abort ( ) const
noexcept

Unblocks a thread which is waiting in tryEnter Call this method if you want to unblock a thread which is waiting for the MessageManager lock in tryEnter.

This method does not have any effect on a thread waiting for a lock in enter.

See also
tryEnter

◆ enter()

void juce::MessageManager::Lock::enter ( ) const
noexcept

Acquires the message manager lock.

If the caller thread already has exclusive access to the MessageManager, this method will return immediately. If another thread is currently using the MessageManager, this will wait until that thread releases the lock to the MessageManager.

This call will only exit if the lock was acquired by this thread. Calling abort while a thread is waiting for enter to finish, will have no effect.

See also
exit, abort

◆ exit()

void juce::MessageManager::Lock::exit ( ) const
noexcept

Releases the message manager lock.

See also
enter, ScopedLock

◆ messageCallback()

void juce::MessageManager::Lock::messageCallback ( ) const
private

◆ tryAcquire()

bool juce::MessageManager::Lock::tryAcquire ( bool  ) const
privatenoexcept

◆ tryEnter()

bool juce::MessageManager::Lock::tryEnter ( ) const
noexcept

Attempts to lock the message manager and exits if abort is called.

This method behaves identically to enter, except that it will abort waiting for the lock if the abort method is called.

Unlike other JUCE critical sections, this method will block waiting for the lock.

To ensure predictable behaviour, you should re-check your abort condition if tryEnter returns false.

This method can be used if you want to do some work while waiting for the MessageManagerLock:

void doWorkWhileWaitingForMessageManagerLock() { MessageManager::Lock::ScopedTryLockType mmLock (messageManagerLock);

while (! mmLock.isLocked()) { while (workQueue.size() > 0) { auto work = workQueue.pop(); doSomeWork (work); }

this will block until we either have the lock or there is work mmLock.retryLock(); }

we have the mmlock do some message manager stuff like resizing and painting components }

called from another thread void addWorkToDo (Work work) { queue.push (work); messageManagerLock.abort(); }

Returns
false if waiting for a lock was aborted, true if the lock was acquired.
See also
enter, abort, ScopedTryLock

Friends And Related Function Documentation

◆ ReferenceCountedObjectPtr< BlockingMessage >

friend class ReferenceCountedObjectPtr< BlockingMessage >
friend

Member Data Documentation

◆ abortWait

Atomic<int> juce::MessageManager::Lock::abortWait
mutableprivate

◆ blockingMessage

ReferenceCountedObjectPtr<BlockingMessage> juce::MessageManager::Lock::blockingMessage
mutableprivate

◆ lockedEvent

WaitableEvent juce::MessageManager::Lock::lockedEvent
private

◆ lockGained

Atomic<int> juce::MessageManager::Lock::lockGained
private

The documentation for this class was generated from the following file: