This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
基础
专业(SIM)
UnigineEditor
界面概述
资源工作流程
Version Control
设置和首选项
项目开发
调整节点参数
Setting Up Materials
设置属性
照明
Sandworm
使用编辑器工具执行特定任务
如何擴展編輯器功能
嵌入式节点类型
Nodes
Objects
Effects
Decals
光源
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
使用范例
C++
C#
UnigineScript
统一的Unigine着色器语言 UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
材质和着色器
Rebuilding the Engine Tools
GUI
双精度坐标
应用程序接口(API)参考
Animations-Related Classes
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
VR-Related Classes
创建内容
内容优化
材质
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials

Unigine::AtomicWithMutex Class

Header: #include <UnigineThread.h>

Template structure that provides a thread-safe atomic wrapper around a user-defined value using mutex-based synchronization instead of lock-free atomics.

Template Parameters:

  • Type - The type of the stored value. Must be copyable and comparable.
  • MutexType - The mutex implementation used to guard access. Defaults to MutexSpin.

AtomicWithMutex Class

Members


AtomicWithMutex ( ) #

Default constructor. Initializes the internal value with its default constructor.

AtomicWithMutex ( const Type& v ) #

Constructor. Initializes the internal value with the provided input.

Arguments

  • const Type& v - Initial value.

AtomicWithMutex ( const AtomicWithMutex& v ) #

Copy constructor. Locks both source and destination mutexes to safely copy the provided value.

Arguments

  • const AtomicWithMutex& v

Type operator Type() ( ) #

Implicitly converts the AtomicWithMutex object to a value of type Type. Internally calls fetch() to return a thread-safe snapshot of the current value.

Return value

Returns copy of the current value.

Type & getUnsafeValue ( ) #

Provides direct, non-synchronized access to the internal value. Calling this bypasses all thread safety and must only be used when external synchronization is guaranteed by the caller.

Return value

Returns non-thread-safe reference to the stored value.

const Type & getUnsafeValue ( ) const#

Const-qualified version of getUnsafeValue(). Provides read-only, non-thread-safe access to the stored value.

Return value

Returns non-thread-safe const reference to the stored value.

Type * getValuePtr ( ) #

Returns a raw pointer to the internal value without locking. Unsafe in multithreaded contexts unless externally synchronized.

Return value

Returns pointer to the internal value.

const Type * getValuePtr ( ) const#

Const-qualified version of getValuePtr().

Return value

Returns const pointer to the internal value.

MutexType & getMutex ( ) #

Provides direct access to the internal mutex object. This allows external code to manually lock or unlock the mutex.

Return value

Returns the reference to the mutex used for protecting the internal value.

const MutexType & getMutex ( ) const#

Const-qualified version of getMutex().

Return value

Returns the const reference to the mutex used for protecting the internal value.

Type fetch ( ) const#

Retrieves the current value in a thread-safe manner. Acquires the mutex, copies the internal value, then releases the mutex. Preferred over direct access when consistent reads are required.

Return value

Returns copy of the stored value.

void store ( const Type& v ) #

Sets the internal value to a new value in a thread-safe way. The entire assignment is protected by the mutex to avoid race conditions with readers or other writers.

Arguments

  • const Type& v - The new value to store.

const Type & operator= ( const Type& v ) #

Thread-safe assignment operator that stores a new value internally. Equivalent to calling store().

Arguments

  • const Type& v - The new value to assign.

Return value

Returns a const reference to the assigned value.

Type operator= ( const AtomicWithMutex& v ) #

Thread-safe copy assignment from another AtomicWithMutex. Locks both the source and destination mutexes to prevent data races.

Arguments

  • const AtomicWithMutex& v - Another AtomicWithMutex to copy from.

Return value

Returns the copied value.

Type swap ( const Type& v ) #

Atomically replaces the current value with a new one and returns the old value.

Arguments

  • const Type& v - The new value to set.

Return value

Returns the value that was stored before swap.

bool compareAndSwap ( const Type& old_value, const Type& new_value ) #

Performs a compare-and-swap operation. If the current value equals old_value, it is replaced with new_value.

Arguments

  • const Type& old_value - Expected current value.
  • const Type& new_value - New value to assign if the current matches the expected.

Return value

true if the internal value was updated; false if the current value did not math old_value.

void spinLock ( const Type& old_value, const Type& new_value ) #

Continuously attempts to atomically swap the value from old_value to new_value using compareAndSwap().

Arguments

  • const Type& old_value - Expected current value.
  • const Type& new_value - New value to assign if the current matches the expected.

void waitValue ( const Type& v ) #

Blocks the current thread in a spin loop until the internal value becomes equal to the provided one. Internally calls spinLock(v, v) and rechecks after each failure.

Arguments

  • const Type& v - The value to wait for.

The information on this page is valid for UNIGINE 2.20 SDK.

Last update: 2025-07-10
Build: ()