- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

Classes | Functions

# qatomic.h File Reference

`#include <QtCore/qglobal.h>`
`#include <QtCore/qbasicatomic.h>`

Go to the source code of this file.

## Classes
class | QAtomicInt
class | QAtomicPointer< T >
## Functions
template<typename T >
void | qAtomicAssign (T *&d, T *x)
| This is a helper for the assignment operators of implicitly shared classes.
template<typename T >
void | qAtomicDetach (T *&d)
| This is a helper for the detach method of implicitly shared classes.

## Function Documentation

void qAtomicAssign | ( | T *& | d,
|  | T * | x
| ) |  | `[inline]`

Search for all occurrences

This is a helper for the assignment operators of implicitly shared classes.

Your assignment operator should look like this:

doc/src/snippets/code/src.corelib.thread.qatomic.h 0

Definition at line 195 of file qatomic.h.

    {
        if (d == x)
            return;
        x->ref.ref();
        if (!d->ref.deref())
            delete d;
        d = x;
    }

void qAtomicDetach | ( | T *& | d | ) | `[inline]`

Search for all occurrences

This is a helper for the detach method of implicitly shared classes.

Your private class needs a copy constructor which copies the members and sets the refcount to 1. After that, your detach function should look like this:

doc/src/snippets/code/src.corelib.thread.qatomic.h 1

Definition at line 214 of file qatomic.h.

    {
        if (d->ref == 1)
            return;
        T *x = d;
        d = new T(*d);
        if (!x->ref.deref())
            delete x;
    }