ImFusion C++ SDK 4.5.0
Multi-Threading Utilities

Utility classes for multi-threading. More...

Collaboration diagram for Multi-Threading Utilities:

Detailed Description

Utility classes for multi-threading.

Namespaces

namespace  ImFusion::Threading
 Utility classes for multi-threading.

Classes

class  ImFusion::Threading::PlaybackTimer
 Recurring timer class that allows for playback over a range at given timestamps/intervals. More...
class  ImFusion::Threading::StoppableThread
 Extension of a std::thread to allow for signalling the thread to abort its execution. More...
class  ImFusion::Threading::ThreadPool
 Lightweight implementation of a thread pool for distributing work onto a fixed number of threads. More...
class  ImFusion::Threading::Protected< T >
 Thread-safe wrapper for a shared resource protected by a mutex. More...

Typedefs

template<class T>
using ImFusion::Threading::SharedProtected = std::shared_ptr<Protected<T>>
 Convenience for storing the same Protected<T> in multiple objects.

Functions

void ImFusion::Threading::setCurrentThreadName (const std::string &threadName)
 Sets the current thread's name to the given string so that a debugger may show it as description.
std::optional< PriorityImFusion::Threading::currentThreadPriority ()
 Queries the current thread's priority from the operating system or std::nullopt if an error occurred.
bool ImFusion::Threading::setCurrentThreadPriority (Priority priority)
 Sets the current thread's priority to the given value.
void ImFusion::Threading::runAsyncAndForget (std::function< void()> func)
 Launches the given function in a background thread using std::thread This function will return immediately and there is no built-in way to know when func has completed.
template<typename... ProtectedT, std::enable_if_t<(detail::IsProtectedV< std::remove_const_t< ProtectedT > > &&...), int > = 0>
auto ImFusion::Threading::lockAll (ProtectedT &... resources)
 Locks multiple Protected<T>s simultaneously and returns a tuple of Locked handles.

Typedef Documentation

◆ SharedProtected

#include <ImFusion/Core/Threading/Protected.h>

Convenience for storing the same Protected<T> in multiple objects.

Should be used instead of Protected<std::shared_ptr<T>> and Protected<T*>.

Function Documentation

◆ setCurrentThreadName()

void ImFusion::Threading::setCurrentThreadName ( const std::string & threadName)

#include <ImFusion/Core/Threading.h>

Sets the current thread's name to the given string so that a debugger may show it as description.

This functionality is platform-dependent and may not reliably work on all platforms.

◆ currentThreadPriority()

std::optional< Priority > ImFusion::Threading::currentThreadPriority ( )

#include <ImFusion/Core/Threading.h>

Queries the current thread's priority from the operating system or std::nullopt if an error occurred.

See also
setCurrentThreadPriority()

◆ setCurrentThreadPriority()

bool ImFusion::Threading::setCurrentThreadPriority ( Priority priority)

#include <ImFusion/Core/Threading.h>

Sets the current thread's priority to the given value.

It will not affect the scheduling of other threads or of the whole process.

Note
On Linux the main executable needs the CAP_SYS_NICE capability for the process to be able to modify its own priority, or an EACCES error will be reported.
Returns
True on success, false otherwise.
See also
makeCurrentThreadRealTime()

◆ lockAll()

template<typename... ProtectedT, std::enable_if_t<(detail::IsProtectedV< std::remove_const_t< ProtectedT > > &&...), int > = 0>
auto ImFusion::Threading::lockAll ( ProtectedT &... resources)

#include <ImFusion/Core/Threading/Protected.h>

Locks multiple Protected<T>s simultaneously and returns a tuple of Locked handles.

This function acquires locks on all provided Protected<T>s simultaneously (using std::lock to avoid deadlocks) and returns a tuple of Locked objects that hold the locks and provide access to the underlying resources.

Both const and non-const Protected<T>s are accepted in any combination. A const Protected<T> yields a Locked<true> (read-only) handle; a non-const Protected<T> yields a Locked<false> (read-write) handle.

Template Parameters
ProtectedTThe Protected<T> or const Protected<T> types to lock
Parameters
resourcesThe Protected values to lock

Usage example:

Protected<int> syncInt(42);
const Protected<std::string> syncStr(std::string("hello"));
auto [lockedInt, lockedStr] = lockAll(syncInt, syncStr);
*lockedInt += 10; // write access
std::cout << *lockedStr; // read-only access
Thread-safe wrapper for a shared resource protected by a mutex.
Definition Protected.h:67
auto lockAll(ProtectedT &... resources)
Locks multiple Protected<T>s simultaneously and returns a tuple of Locked handles.
Definition Protected.h:268
Note
All locks are acquired simultaneously to prevent deadlocks. CAUTION: Calling two locking functions in the same scope can lead to deadlocks.
Search Tab / S to search, Esc to close