2 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FBaseUtil_AtomicOperations.h
19 * @brief This is the header file for handling atomic operations.
21 #ifndef _FBASE_UTIL_ATOMIC_OPERATIONS_H_
22 #define _FBASE_UTIL_ATOMIC_OPERATIONS_H_
24 namespace Tizen { namespace Base { namespace Utility
26 namespace _AtomicOperations
30 * Atomically add the @c value to the variable that @c pRefCount points to.
33 * @remarks This method supposes 4 byte alignment in ARM architecture.
36 AtomicAdd(volatile int* pRefCount, int value)
41 "1: ldrex %0, [%1] \n\t"
43 "strex r2, r1, [%1] \n\t"
47 : "r"(pRefCount), "r"(value)
52 return __sync_fetch_and_add(pRefCount, value);
57 * Atomically increase the variable that @c pRefCount points to by 1
60 * @remarks This method supposes 4 byte alignment in ARM architecture.
63 AtomicInc(volatile int* pRefCount)
65 return AtomicAdd(pRefCount, 1);
69 * Atomically decrease the variable that @c pRefCount points to by 1
72 * @remarks This method supposes 4 byte alignment in ARM architecture.
75 AtomicDec(volatile int* pRefCount)
77 return AtomicAdd(pRefCount, -1);
80 }}}} // Tizen::Base::Utility::_AtomicOperations
81 #endif // _FBASE_UTIL_ATOMIC_OPERATIONS_H_