1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | /*!
|
---|
43 | \page atomic-operations.html
|
---|
44 | \title Implementing Atomic Operations
|
---|
45 | \ingroup architecture
|
---|
46 | \ingroup qt-embedded-linux
|
---|
47 | \brief A guide to implementing atomic operations on new architectures.
|
---|
48 |
|
---|
49 | Qt uses an optimization called \l {Implicitly Shared
|
---|
50 | Classes}{implicit sharing} for many of its value classes.
|
---|
51 |
|
---|
52 | Starting with Qt 4, all of Qt's implicitly shared classes can
|
---|
53 | safely be copied across threads like any other value classes,
|
---|
54 | i.e., they are fully \l {Thread Support in Qt#Reentrancy and
|
---|
55 | Thread-Safety}{reentrant}. This is accomplished by implementing
|
---|
56 | reference counting operations using atomic hardware instructions
|
---|
57 | on all the different platforms supported by Qt.
|
---|
58 |
|
---|
59 | To support a new architecture, it is important to ensure that
|
---|
60 | these platform-specific atomic operations are implemented in a
|
---|
61 | corresponding header file (\c qatomic_ARCH.h), and that this file
|
---|
62 | is located in Qt's \c src/corelib/arch directory. For example, the
|
---|
63 | Intel 80386 implementation is located in \c
|
---|
64 | src/corelib/arch/qatomic_i386.h.
|
---|
65 |
|
---|
66 | Currently, Qt provides two classes providing several atomic
|
---|
67 | operations, QAtomicInt and QAtomicPointer. These classes inherit
|
---|
68 | from QBasicAtomicInt and QBasicAtomicPointer, respectively.
|
---|
69 |
|
---|
70 | When porting Qt to a new architecture, the QBasicAtomicInt and
|
---|
71 | QBasicAtomicPointer classes must be implemented, \e not QAtomicInt
|
---|
72 | and QAtomicPointer. The former classes do not have constructors,
|
---|
73 | which makes them POD (plain-old-data). Both classes only have a
|
---|
74 | single member variable called \c _q_value, which stores the
|
---|
75 | value. This is the value that all of the atomic operations read
|
---|
76 | and modify.
|
---|
77 |
|
---|
78 | All of the member functions mentioned in the QAtomicInt and
|
---|
79 | QAtomicPointer API documentation must be implemented. Note that
|
---|
80 | these the implementations of the atomic operations in these
|
---|
81 | classes must be atomic with respect to both interrupts and
|
---|
82 | multiple processors.
|
---|
83 |
|
---|
84 | \warning The QBasicAtomicInt and QBasicAtomicPointer classes
|
---|
85 | mentioned in this document are used internally by Qt and are not
|
---|
86 | part of the public API. They may change in future versions of
|
---|
87 | Qt. The purpose of this document is to aid people interested in
|
---|
88 | porting Qt to a new architecture.
|
---|
89 | */
|
---|