[2.2] Modify doxygen comment of AtomicOperation as ACR review
[platform/framework/native/appfw.git] / src / base / inc / FBaseUtil_AtomicOperations.h
1 //
2 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file                FBaseUtil_AtomicOperations.h
19  * @brief               This is the header file for handling atomic operations.
20  */
21 #ifndef _FBASE_UTIL_ATOMIC_OPERATIONS_H_
22 #define _FBASE_UTIL_ATOMIC_OPERATIONS_H_
23
24 namespace Tizen { namespace Base { namespace Utility
25 {
26 namespace _AtomicOperations
27 {
28
29 /**
30  * Atomically add the @c value to the variable that @c pRefCount points to.
31  *
32  * @since       2.2
33  * @remarks     This method supposes 4 byte alignment on ARM architecture.
34  */
35 inline int
36 AtomicAdd(volatile int* pRefCount, int value)
37 {
38 #if defined(__arm__)
39         register int result;
40         asm volatile (
41                 "1: ldrex   %0,  [%1]   \n\t"
42                 "add     r1,   %0,  %2  \n\t"
43                 "strex   r2,   r1, [%1] \n\t"
44                 "cmp     r2,   #0 \n\t"
45                 "bne     1b"
46                 : "=&r" (result)
47                 : "r"(pRefCount), "r"(value)
48                 : "r1","r2"
49         );
50         return result;
51 #else
52         return __sync_fetch_and_add(pRefCount, value);
53 #endif
54 }
55
56 /**
57  * Atomically increase the variable that @c pRefCount points to by 1
58  *
59  * @since       2.2
60  * @remarks     This method supposes 4 byte alignment on ARM architecture.
61  */
62 inline int
63 AtomicInc(volatile int* pRefCount)
64 {
65         return AtomicAdd(pRefCount, 1);
66 }
67
68 /**
69  * Atomically decrease the variable that @c pRefCount points to by 1
70  *
71  * @since       2.2
72  * @remarks     This method supposes 4 byte alignment on ARM architecture.
73  */
74 inline int
75 AtomicDec(volatile int* pRefCount)
76 {
77         return AtomicAdd(pRefCount, -1);
78 }
79
80 }}}} // Tizen::Base::Utility::_AtomicOperations
81 #endif  // _FBASE_UTIL_ATOMIC_OPERATIONS_H_