aboutsummaryrefslogtreecommitdiffstats
path: root/doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qatomic.cpp
diff options
context:
space:
mode:
authorLauro Neto <lauro.neto@openbossa.org>2010-04-27 18:12:50 -0300
committerRenato Filho <renato.filho@openbossa.org>2010-04-28 16:36:47 -0300
commitaaece960d3cf1c9d19dd84fe8171769517647724 (patch)
treeea2e20d2c8738cc407f60b10b6cccfb4e1fc2b70 /doc/codesnippets/doc/src/snippets/code/src_corelib_thread_qatomic.cpp
parent685246809debe672a0007b67fe78f7c77bad6739 (diff)
Adding ./doc from boost
Reviewer: Lauro Moura <lauro.neto@openbossa.org> Luciano Wolf <luciano.wolf@openbossa.org>
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.cpp58
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]