diff options
Diffstat (limited to 'doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qatomic.cpp')
-rw-r--r-- | doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qatomic.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qatomic.cpp b/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qatomic.cpp new file mode 100644 index 000000000..3f67ddf8e --- /dev/null +++ b/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qatomic.cpp @@ -0,0 +1,58 @@ +//! [0] +MySharedType &MySharedType::operator=(const MySharedType &other) +{ + (void) other.data->atomicInt.ref(); + if (!data->atomicInt.deref()) { + // The last reference has been released + delete d; + } + d = other.d; + return *this; +} +//! [0] + + +//! [1] +if (currentValue == expectedValue) { + currentValue = newValue; + return true; +} +return false; +//! [1] + + +//! [2] +int originalValue = currentValue; +currentValue = newValue; +return originalValue; +//! [2] + + +//! [3] +int originalValue = currentValue; +currentValue += valueToAdd; +return originalValue; +//! [3] + + +//! [4] +if (currentValue == expectedValue) { + currentValue = newValue; + return true; +} +return false; +//! [4] + + +//! [5] +T *originalValue = currentValue; +currentValue = newValue; +return originalValue; +//! [5] + + +//! [6] +T *originalValue = currentValue; +currentValue += valueToAdd; +return originalValue; +//! [6] |