Example
Dependencies: FXAS21002 FXOS8700Q
simple-mbed-cloud-client/mbed-cloud-client/update-client-hub/modules/atomic-queue/source/atomic.h@0:11cc2b7889af, 2019-11-19 (annotated)
- Committer:
- maygup01
- Date:
- Tue Nov 19 09:49:38 2019 +0000
- Revision:
- 0:11cc2b7889af
Example
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
maygup01 | 0:11cc2b7889af | 1 | // ---------------------------------------------------------------------------- |
maygup01 | 0:11cc2b7889af | 2 | // Copyright 2015-2017 ARM Ltd. |
maygup01 | 0:11cc2b7889af | 3 | // |
maygup01 | 0:11cc2b7889af | 4 | // SPDX-License-Identifier: Apache-2.0 |
maygup01 | 0:11cc2b7889af | 5 | // |
maygup01 | 0:11cc2b7889af | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); |
maygup01 | 0:11cc2b7889af | 7 | // you may not use this file except in compliance with the License. |
maygup01 | 0:11cc2b7889af | 8 | // You may obtain a copy of the License at |
maygup01 | 0:11cc2b7889af | 9 | // |
maygup01 | 0:11cc2b7889af | 10 | // http://www.apache.org/licenses/LICENSE-2.0 |
maygup01 | 0:11cc2b7889af | 11 | // |
maygup01 | 0:11cc2b7889af | 12 | // Unless required by applicable law or agreed to in writing, software |
maygup01 | 0:11cc2b7889af | 13 | // distributed under the License is distributed on an "AS IS" BASIS, |
maygup01 | 0:11cc2b7889af | 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
maygup01 | 0:11cc2b7889af | 15 | // See the License for the specific language governing permissions and |
maygup01 | 0:11cc2b7889af | 16 | // limitations under the License. |
maygup01 | 0:11cc2b7889af | 17 | // ---------------------------------------------------------------------------- |
maygup01 | 0:11cc2b7889af | 18 | |
maygup01 | 0:11cc2b7889af | 19 | #ifndef ATOMIC_QUEUE_ATOMIC_H |
maygup01 | 0:11cc2b7889af | 20 | #define ATOMIC_QUEUE_ATOMIC_H |
maygup01 | 0:11cc2b7889af | 21 | #include <stdint.h> |
maygup01 | 0:11cc2b7889af | 22 | |
maygup01 | 0:11cc2b7889af | 23 | |
maygup01 | 0:11cc2b7889af | 24 | |
maygup01 | 0:11cc2b7889af | 25 | #ifdef __cplusplus |
maygup01 | 0:11cc2b7889af | 26 | extern "C" { |
maygup01 | 0:11cc2b7889af | 27 | #endif |
maygup01 | 0:11cc2b7889af | 28 | |
maygup01 | 0:11cc2b7889af | 29 | enum { |
maygup01 | 0:11cc2b7889af | 30 | AQ_ATOMIC_CAS_DEREF_SUCCESS = 0, |
maygup01 | 0:11cc2b7889af | 31 | AQ_ATOMIC_CAS_DEREF_NULLPTR, |
maygup01 | 0:11cc2b7889af | 32 | AQ_ATOMIC_CAS_DEREF_VALUE, |
maygup01 | 0:11cc2b7889af | 33 | AQ_ATOMIC_CAS_DEREF_INTERUPTED, |
maygup01 | 0:11cc2b7889af | 34 | }; |
maygup01 | 0:11cc2b7889af | 35 | |
maygup01 | 0:11cc2b7889af | 36 | /** |
maygup01 | 0:11cc2b7889af | 37 | * @brief Atomically compares the value of a dereferenced pointer, replacing the pointer on success. |
maygup01 | 0:11cc2b7889af | 38 | * @detail aq_atomic_cas_deref_uintptr provides a mechanism to atomically change a pointer based on a value contained |
maygup01 | 0:11cc2b7889af | 39 | * in the structure referenced by the pointer. This is done in the following sequence of operations: |
maygup01 | 0:11cc2b7889af | 40 | * |
maygup01 | 0:11cc2b7889af | 41 | * 1. Load the value of `*ptrAddr` |
maygup01 | 0:11cc2b7889af | 42 | * 2. Optionally store the current value of `*ptrAddr` |
maygup01 | 0:11cc2b7889af | 43 | * 3. Check that the pointer is valid: `*ptrAddr != NULL` |
maygup01 | 0:11cc2b7889af | 44 | * 4. Check the value of the referenced location: `*(*ptrAddr + valueOffset) == expectedDerefValue` (casts omitted) |
maygup01 | 0:11cc2b7889af | 45 | * 5. If 3 and 4 succeeded, store newPtrValue: `*ptrAddr = newPtrValue` (NOTE: in non-blocking implementations, this step can fail) |
maygup01 | 0:11cc2b7889af | 46 | * 6. Return a status code based on the results of 3, 4, 5. |
maygup01 | 0:11cc2b7889af | 47 | * |
maygup01 | 0:11cc2b7889af | 48 | * @param[in,out] ptrAddr The address of the pointer to manipulate |
maygup01 | 0:11cc2b7889af | 49 | * @param[out] currentPtrValue A pointer to a container for the current value of *ptrAddr |
maygup01 | 0:11cc2b7889af | 50 | * @param[in] expectedDerefValue This is the value that is expected at *(uintptr_t *)((uintptr_t)*ptrAddr + valueOffset) |
maygup01 | 0:11cc2b7889af | 51 | * @param[in] newPtrValue The value to store to *ptrAddr if the comparison is successful |
maygup01 | 0:11cc2b7889af | 52 | * @param[in] valueOffset The offset of the target value from *ptrAddr |
maygup01 | 0:11cc2b7889af | 53 | * |
maygup01 | 0:11cc2b7889af | 54 | * @retval AQ_ATOMIC_CAS_DEREF_SUCCESS The compare and set has succeeded |
maygup01 | 0:11cc2b7889af | 55 | * @retval AQ_ATOMIC_CAS_DEREF_NULLPTR `*ptrAddr` was `NULL` |
maygup01 | 0:11cc2b7889af | 56 | * @retval AQ_ATOMIC_CAS_DEREF_VALUE The value test failed (*(*ptrAddr + valueOffset) != expectedDerefValue`) |
maygup01 | 0:11cc2b7889af | 57 | * @retval AQ_ATOMIC_CAS_DEREF_INTERUPTED Another context modified `*ptrAddr` |
maygup01 | 0:11cc2b7889af | 58 | */ |
maygup01 | 0:11cc2b7889af | 59 | int aq_atomic_cas_deref_uintptr(uintptr_t *volatile *ptrAddr, |
maygup01 | 0:11cc2b7889af | 60 | uintptr_t **currentPtrValue, |
maygup01 | 0:11cc2b7889af | 61 | uintptr_t expectedDerefValue, |
maygup01 | 0:11cc2b7889af | 62 | uintptr_t *newPtrValue, |
maygup01 | 0:11cc2b7889af | 63 | uintptr_t valueOffset); |
maygup01 | 0:11cc2b7889af | 64 | |
maygup01 | 0:11cc2b7889af | 65 | #ifdef __cplusplus |
maygup01 | 0:11cc2b7889af | 66 | } // extern "C" |
maygup01 | 0:11cc2b7889af | 67 | #endif |
maygup01 | 0:11cc2b7889af | 68 | #endif // ATOMIC_QUEUE_ATOMIC_H |