Enable atspi
[platform/core/uifw/dali-adaptor.git] / dali / internal / system / common / atomics.h
1 #ifndef _DALI_INTERNAL_PLATFORM_ATOMICS_H_
2 #define _DALI_INTERNAL_PLATFORM_ATOMICS_H_
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <cstddef>
23
24 /*
25  * atomics.h
26  *
27  * Interface for atomic memory operations.
28  * There may be platform-specific versions of this file in other directories.
29  */
30
31 namespace Dali
32 {
33 namespace Internal
34 {
35
36 /**
37  * @brief Atomic write to an aligned memory location in cacheable memory.
38  *
39  * For common platforms with coherent caches such as ARM mpcore and Intel CPUs,
40  * a cacheline can be in a writeable state in the L1 cache of exactly one core
41  * at a time. Therefore, a write to a location that does not require a read /
42  * modify / write cycle or cross a cacheline boundary is  automatically
43  * atomic.
44  *
45  * @param address A pointer to a location in a cacheable memory region that is
46  *        aligned to a 4 byte boundary.
47  * @param value A value to assign to the memory location in address.
48  */
49 inline void AtomicWriteToCacheableAlignedAddress( volatile uint32_t * const address, const uint32_t value )
50 {
51   DALI_ASSERT_DEBUG( ptrdiff_t(address) % 4 == 0 && "Address must be 32 bit aligned" );
52   *address = value;
53 }
54
55 /**
56  * @brief Atomic read from an aligned memory location in cacheable memory.
57  *
58  * For common platforms with coherent caches such as ARM mpcore and Intel CPUs,
59  * a cacheline can be in a writeable state in the L1 cache of exactly one core
60  * at a time. Therefore, a read a location that does not cross a cacheline
61  * boundary is automatically atomic.
62  *
63  * @param  address A pointer to a location in a cacheable memory region that is
64  *         aligned to a 4 byte boundary.
65  * @return The value stored at the memory location in address.
66  */
67 inline uint32_t AtomicReadFromCacheableAlignedAddress( const volatile uint32_t * const address )
68 {
69   DALI_ASSERT_DEBUG( ptrdiff_t(address) % 4 == 0 && "Address must be 32 bit aligned" );
70   return *address;
71 }
72
73 } /* namespace Internal */
74 } /* namespace Dali */
75
76 #endif /* _DALI_INTERNAL_PLATFORM_ATOMICS_H_ */