OpenShot Audio Library | OpenShotAudio: juce::LockingAsyncUpdater Class Reference

OpenShot Audio Library | OpenShotAudio 0.6.0

Loading...
Searching...
No Matches
juce::LockingAsyncUpdater Class Referencefinal

`#include <juce_LockingAsyncUpdater.h>`

## Public Member Functions
| LockingAsyncUpdater (std::function< void()> callbackToUse)
| LockingAsyncUpdater (LockingAsyncUpdater &&other) noexcept
LockingAsyncUpdater & | operator= (LockingAsyncUpdater &&other) noexcept
| ~LockingAsyncUpdater ()
void | triggerAsyncUpdate ()
void | cancelPendingUpdate () noexcept
void | handleUpdateNowIfNeeded ()
bool | isUpdatePending () const noexcept

## Detailed Description

A bit like an AsyncUpdater, but guarantees that after cancelPendingUpdate() returns, the async function will never be called until triggerAsyncUpdate() is called again. This is an important guarantee for writing classes with async behaviour that can still be destroyed safely from a background thread.

Note that all of the member functions of this type have a chance of blocking, so this class is unsuitable for broadcasting changes from a realtime thread.

Definition at line 38 of file juce_LockingAsyncUpdater.h.

## Constructor & Destructor Documentation

## ◆ LockingAsyncUpdater() [1/2]

juce::LockingAsyncUpdater::LockingAsyncUpdater | ( | std::function< void()> | callbackToUse | ) |
| explicit

Creates a LockingAsyncUpdater object that will call the provided callback on the main thread when triggered.

Note that the LockingAsyncUpdater takes an internal mutex before calling the provided callback. Therefore, in order to avoid deadlocks, you should (ideally) ensure that no locks are taken inside the callbackToUse. If you do need to take a lock inside the callback, make sure that you do not hold the same lock while calling any of the LockingAsyncUpdater member functions.

Definition at line 81 of file juce_LockingAsyncUpdater.cpp.

Referenced by LockingAsyncUpdater(), and operator=().

## ◆ LockingAsyncUpdater() [2/2]

juce::LockingAsyncUpdater::LockingAsyncUpdater | ( | LockingAsyncUpdater && | other | ) |
| noexcept

Move constructor.

Definition at line 84 of file juce_LockingAsyncUpdater.cpp.

## ◆ ~LockingAsyncUpdater()

juce::LockingAsyncUpdater::~LockingAsyncUpdater | ( |  | ) |

Destructor. If there are any pending callbacks when the object is deleted, these are lost. The async callback is guaranteed not to be called again once the destructor has completed.

Definition at line 94 of file juce_LockingAsyncUpdater.cpp.

## Member Function Documentation

## ◆ cancelPendingUpdate()

void juce::LockingAsyncUpdater::cancelPendingUpdate | ( |  | ) |
| noexcept

This will stop any pending updates from happening.

If a callback is already in progress on another thread, this will block until the callback has finished before returning.

Definition at line 108 of file juce_LockingAsyncUpdater.cpp.

## ◆ handleUpdateNowIfNeeded()

void juce::LockingAsyncUpdater::handleUpdateNowIfNeeded | ( |  | ) |

If an update has been triggered and is pending, this will invoke it synchronously.

Use this as a kind of "flush" operation - if an update is pending, the handleAsyncUpdate() method will be called immediately; if no update is pending, then nothing will be done.

Because this may invoke the callback, this method must only be called on the main event thread.

Definition at line 116 of file juce_LockingAsyncUpdater.cpp.

## ◆ isUpdatePending()

bool juce::LockingAsyncUpdater::isUpdatePending | ( |  | ) | const
| noexcept

Returns true if there's an update callback in the pipeline.

Definition at line 124 of file juce_LockingAsyncUpdater.cpp.

## ◆ operator=()

LockingAsyncUpdater & juce::LockingAsyncUpdater::operator= | ( | LockingAsyncUpdater && | other | ) |
| noexcept

Move assignment operator.

Definition at line 87 of file juce_LockingAsyncUpdater.cpp.

## ◆ triggerAsyncUpdate()

void juce::LockingAsyncUpdater::triggerAsyncUpdate | ( |  | ) |

Causes the callback to be triggered at a later time.

This method returns quickly, after which a callback to the handleAsyncUpdate() method will be made by the impl thread as soon as possible.

If an update callback is already pending but hasn't started yet, calling this method will have no effect.

It's thread-safe to call this method from any thread, BUT beware of calling it from a real-time (e.g. audio) thread, because it unconditionally locks a mutex. This may block, e.g. if this is called from a background thread while the async callback is in progress on the main thread.

Definition at line 100 of file juce_LockingAsyncUpdater.cpp.

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

- juce_LockingAsyncUpdater.h
- juce_LockingAsyncUpdater.cpp