leo hendrickson / Mbed OS example-Ethernet-mbed-Cloud-connect
Committer:
leothedragon
Date:
Tue May 04 08:55:12 2021 +0000
Revision:
0:8f0bb79ddd48
nmn

Who changed what in which revision?

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