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