helpfor studient
Dependents: STM32_F103-C8T6basecanblink_led
Fork of mbed-dev by
common/mbed_critical.c@147:30b64687e01f, 2016-09-16 (annotated)
- Committer:
- <>
- Date:
- Fri Sep 16 16:24:25 2016 +0100
- Revision:
- 147:30b64687e01f
- Parent:
- 144:ef7eb2e8f9f7
This updates the lib to the mbed lib v126
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 144:ef7eb2e8f9f7 | 1 | /* |
<> | 144:ef7eb2e8f9f7 | 2 | * Copyright (c) 2015-2016, ARM Limited, All Rights Reserved |
<> | 144:ef7eb2e8f9f7 | 3 | * SPDX-License-Identifier: Apache-2.0 |
<> | 144:ef7eb2e8f9f7 | 4 | * |
<> | 144:ef7eb2e8f9f7 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
<> | 144:ef7eb2e8f9f7 | 6 | * not use this file except in compliance with the License. |
<> | 144:ef7eb2e8f9f7 | 7 | * You may obtain a copy of the License at |
<> | 144:ef7eb2e8f9f7 | 8 | * |
<> | 144:ef7eb2e8f9f7 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
<> | 144:ef7eb2e8f9f7 | 10 | * |
<> | 144:ef7eb2e8f9f7 | 11 | * Unless required by applicable law or agreed to in writing, software |
<> | 144:ef7eb2e8f9f7 | 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
<> | 144:ef7eb2e8f9f7 | 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
<> | 144:ef7eb2e8f9f7 | 14 | * See the License for the specific language governing permissions and |
<> | 144:ef7eb2e8f9f7 | 15 | * limitations under the License. |
<> | 144:ef7eb2e8f9f7 | 16 | */ |
<> | 144:ef7eb2e8f9f7 | 17 | |
<> | 144:ef7eb2e8f9f7 | 18 | #include "critical.h" |
<> | 144:ef7eb2e8f9f7 | 19 | |
<> | 144:ef7eb2e8f9f7 | 20 | #include "cmsis.h" |
<> | 144:ef7eb2e8f9f7 | 21 | #include "mbed_assert.h" |
<> | 144:ef7eb2e8f9f7 | 22 | |
<> | 144:ef7eb2e8f9f7 | 23 | #define EXCLUSIVE_ACCESS (!defined (__CORTEX_M0) && !defined (__CORTEX_M0PLUS)) |
<> | 144:ef7eb2e8f9f7 | 24 | |
<> | 144:ef7eb2e8f9f7 | 25 | static volatile uint32_t interrupt_enable_counter = 0; |
<> | 144:ef7eb2e8f9f7 | 26 | static volatile bool critical_interrupts_disabled = false; |
<> | 144:ef7eb2e8f9f7 | 27 | |
<> | 144:ef7eb2e8f9f7 | 28 | bool core_util_are_interrupts_enabled(void) |
<> | 144:ef7eb2e8f9f7 | 29 | { |
<> | 144:ef7eb2e8f9f7 | 30 | #if defined(__CORTEX_A9) |
<> | 144:ef7eb2e8f9f7 | 31 | return ((__get_CPSR() & 0x80) == 0); |
<> | 144:ef7eb2e8f9f7 | 32 | #else |
<> | 144:ef7eb2e8f9f7 | 33 | return ((__get_PRIMASK() & 0x1) == 0); |
<> | 144:ef7eb2e8f9f7 | 34 | #endif |
<> | 144:ef7eb2e8f9f7 | 35 | } |
<> | 144:ef7eb2e8f9f7 | 36 | |
<> | 144:ef7eb2e8f9f7 | 37 | void core_util_critical_section_enter(void) |
<> | 144:ef7eb2e8f9f7 | 38 | { |
<> | 144:ef7eb2e8f9f7 | 39 | bool interrupts_disabled = !core_util_are_interrupts_enabled(); |
<> | 144:ef7eb2e8f9f7 | 40 | __disable_irq(); |
<> | 144:ef7eb2e8f9f7 | 41 | |
<> | 144:ef7eb2e8f9f7 | 42 | /* Save the interrupt disabled state as it was prior to any nested critical section lock use */ |
<> | 144:ef7eb2e8f9f7 | 43 | if (!interrupt_enable_counter) { |
<> | 144:ef7eb2e8f9f7 | 44 | critical_interrupts_disabled = interrupts_disabled; |
<> | 144:ef7eb2e8f9f7 | 45 | } |
<> | 144:ef7eb2e8f9f7 | 46 | |
<> | 144:ef7eb2e8f9f7 | 47 | /* If the interrupt_enable_counter overflows or we are in a nested critical section and interrupts |
<> | 144:ef7eb2e8f9f7 | 48 | are enabled, then something has gone badly wrong thus assert an error. |
<> | 144:ef7eb2e8f9f7 | 49 | */ |
<> | 144:ef7eb2e8f9f7 | 50 | MBED_ASSERT(interrupt_enable_counter < UINT32_MAX); |
<> | 144:ef7eb2e8f9f7 | 51 | // FIXME |
<> | 144:ef7eb2e8f9f7 | 52 | #ifndef FEATURE_UVISOR |
<> | 144:ef7eb2e8f9f7 | 53 | if (interrupt_enable_counter > 0) { |
<> | 144:ef7eb2e8f9f7 | 54 | MBED_ASSERT(interrupts_disabled); |
<> | 144:ef7eb2e8f9f7 | 55 | } |
<> | 144:ef7eb2e8f9f7 | 56 | #else |
<> | 144:ef7eb2e8f9f7 | 57 | #warning "core_util_critical_section_enter needs fixing to work from unprivileged code" |
<> | 144:ef7eb2e8f9f7 | 58 | #endif /* FEATURE_UVISOR */ |
<> | 144:ef7eb2e8f9f7 | 59 | interrupt_enable_counter++; |
<> | 144:ef7eb2e8f9f7 | 60 | } |
<> | 144:ef7eb2e8f9f7 | 61 | |
<> | 144:ef7eb2e8f9f7 | 62 | void core_util_critical_section_exit(void) |
<> | 144:ef7eb2e8f9f7 | 63 | { |
<> | 144:ef7eb2e8f9f7 | 64 | /* If critical_section_enter has not previously been called, do nothing */ |
<> | 144:ef7eb2e8f9f7 | 65 | if (interrupt_enable_counter) { |
<> | 144:ef7eb2e8f9f7 | 66 | |
<> | 144:ef7eb2e8f9f7 | 67 | // FIXME |
<> | 144:ef7eb2e8f9f7 | 68 | #ifndef FEATURE_UVISOR |
<> | 144:ef7eb2e8f9f7 | 69 | bool interrupts_disabled = !core_util_are_interrupts_enabled(); /* get the current interrupt disabled state */ |
<> | 144:ef7eb2e8f9f7 | 70 | |
<> | 144:ef7eb2e8f9f7 | 71 | MBED_ASSERT(interrupts_disabled); /* Interrupts must be disabled on invoking an exit from a critical section */ |
<> | 144:ef7eb2e8f9f7 | 72 | #else |
<> | 144:ef7eb2e8f9f7 | 73 | #warning "core_util_critical_section_exit needs fixing to work from unprivileged code" |
<> | 144:ef7eb2e8f9f7 | 74 | #endif /* FEATURE_UVISOR */ |
<> | 144:ef7eb2e8f9f7 | 75 | |
<> | 144:ef7eb2e8f9f7 | 76 | interrupt_enable_counter--; |
<> | 144:ef7eb2e8f9f7 | 77 | |
<> | 144:ef7eb2e8f9f7 | 78 | /* Only re-enable interrupts if we are exiting the last of the nested critical sections and |
<> | 144:ef7eb2e8f9f7 | 79 | interrupts were enabled on entry to the first critical section. |
<> | 144:ef7eb2e8f9f7 | 80 | */ |
<> | 144:ef7eb2e8f9f7 | 81 | if (!interrupt_enable_counter && !critical_interrupts_disabled) { |
<> | 144:ef7eb2e8f9f7 | 82 | __enable_irq(); |
<> | 144:ef7eb2e8f9f7 | 83 | } |
<> | 144:ef7eb2e8f9f7 | 84 | } |
<> | 144:ef7eb2e8f9f7 | 85 | } |
<> | 144:ef7eb2e8f9f7 | 86 | |
<> | 144:ef7eb2e8f9f7 | 87 | #if EXCLUSIVE_ACCESS |
<> | 144:ef7eb2e8f9f7 | 88 | |
<> | 147:30b64687e01f | 89 | /* Supress __ldrex and __strex deprecated warnings - "#3731-D: intrinsic is deprecated" */ |
<> | 147:30b64687e01f | 90 | #if defined (__CC_ARM) |
<> | 147:30b64687e01f | 91 | #pragma diag_suppress 3731 |
<> | 147:30b64687e01f | 92 | #endif |
<> | 147:30b64687e01f | 93 | |
<> | 144:ef7eb2e8f9f7 | 94 | bool core_util_atomic_cas_u8(uint8_t *ptr, uint8_t *expectedCurrentValue, uint8_t desiredValue) |
<> | 144:ef7eb2e8f9f7 | 95 | { |
<> | 144:ef7eb2e8f9f7 | 96 | uint8_t currentValue = __LDREXB((volatile uint8_t*)ptr); |
<> | 144:ef7eb2e8f9f7 | 97 | if (currentValue != *expectedCurrentValue) { |
<> | 144:ef7eb2e8f9f7 | 98 | *expectedCurrentValue = currentValue; |
<> | 144:ef7eb2e8f9f7 | 99 | __CLREX(); |
<> | 144:ef7eb2e8f9f7 | 100 | return false; |
<> | 144:ef7eb2e8f9f7 | 101 | } |
<> | 144:ef7eb2e8f9f7 | 102 | |
<> | 144:ef7eb2e8f9f7 | 103 | return !__STREXB(desiredValue, (volatile uint8_t*)ptr); |
<> | 144:ef7eb2e8f9f7 | 104 | } |
<> | 144:ef7eb2e8f9f7 | 105 | |
<> | 144:ef7eb2e8f9f7 | 106 | bool core_util_atomic_cas_u16(uint16_t *ptr, uint16_t *expectedCurrentValue, uint16_t desiredValue) |
<> | 144:ef7eb2e8f9f7 | 107 | { |
<> | 144:ef7eb2e8f9f7 | 108 | uint16_t currentValue = __LDREXH((volatile uint16_t*)ptr); |
<> | 144:ef7eb2e8f9f7 | 109 | if (currentValue != *expectedCurrentValue) { |
<> | 144:ef7eb2e8f9f7 | 110 | *expectedCurrentValue = currentValue; |
<> | 144:ef7eb2e8f9f7 | 111 | __CLREX(); |
<> | 144:ef7eb2e8f9f7 | 112 | return false; |
<> | 144:ef7eb2e8f9f7 | 113 | } |
<> | 144:ef7eb2e8f9f7 | 114 | |
<> | 144:ef7eb2e8f9f7 | 115 | return !__STREXH(desiredValue, (volatile uint16_t*)ptr); |
<> | 144:ef7eb2e8f9f7 | 116 | } |
<> | 144:ef7eb2e8f9f7 | 117 | |
<> | 144:ef7eb2e8f9f7 | 118 | |
<> | 144:ef7eb2e8f9f7 | 119 | bool core_util_atomic_cas_u32(uint32_t *ptr, uint32_t *expectedCurrentValue, uint32_t desiredValue) |
<> | 144:ef7eb2e8f9f7 | 120 | { |
<> | 144:ef7eb2e8f9f7 | 121 | uint32_t currentValue = __LDREXW((volatile uint32_t*)ptr); |
<> | 144:ef7eb2e8f9f7 | 122 | if (currentValue != *expectedCurrentValue) { |
<> | 144:ef7eb2e8f9f7 | 123 | *expectedCurrentValue = currentValue; |
<> | 144:ef7eb2e8f9f7 | 124 | __CLREX(); |
<> | 144:ef7eb2e8f9f7 | 125 | return false; |
<> | 144:ef7eb2e8f9f7 | 126 | } |
<> | 144:ef7eb2e8f9f7 | 127 | |
<> | 144:ef7eb2e8f9f7 | 128 | return !__STREXW(desiredValue, (volatile uint32_t*)ptr); |
<> | 144:ef7eb2e8f9f7 | 129 | } |
<> | 144:ef7eb2e8f9f7 | 130 | |
<> | 144:ef7eb2e8f9f7 | 131 | uint8_t core_util_atomic_incr_u8(uint8_t *valuePtr, uint8_t delta) |
<> | 144:ef7eb2e8f9f7 | 132 | { |
<> | 144:ef7eb2e8f9f7 | 133 | uint8_t newValue; |
<> | 144:ef7eb2e8f9f7 | 134 | do { |
<> | 144:ef7eb2e8f9f7 | 135 | newValue = __LDREXB((volatile uint8_t*)valuePtr) + delta; |
<> | 144:ef7eb2e8f9f7 | 136 | } while (__STREXB(newValue, (volatile uint8_t*)valuePtr)); |
<> | 144:ef7eb2e8f9f7 | 137 | return newValue; |
<> | 144:ef7eb2e8f9f7 | 138 | } |
<> | 144:ef7eb2e8f9f7 | 139 | |
<> | 144:ef7eb2e8f9f7 | 140 | uint16_t core_util_atomic_incr_u16(uint16_t *valuePtr, uint16_t delta) |
<> | 144:ef7eb2e8f9f7 | 141 | { |
<> | 144:ef7eb2e8f9f7 | 142 | uint16_t newValue; |
<> | 144:ef7eb2e8f9f7 | 143 | do { |
<> | 144:ef7eb2e8f9f7 | 144 | newValue = __LDREXH((volatile uint16_t*)valuePtr) + delta; |
<> | 144:ef7eb2e8f9f7 | 145 | } while (__STREXH(newValue, (volatile uint16_t*)valuePtr)); |
<> | 144:ef7eb2e8f9f7 | 146 | return newValue; |
<> | 144:ef7eb2e8f9f7 | 147 | } |
<> | 144:ef7eb2e8f9f7 | 148 | |
<> | 144:ef7eb2e8f9f7 | 149 | uint32_t core_util_atomic_incr_u32(uint32_t *valuePtr, uint32_t delta) |
<> | 144:ef7eb2e8f9f7 | 150 | { |
<> | 144:ef7eb2e8f9f7 | 151 | uint32_t newValue; |
<> | 144:ef7eb2e8f9f7 | 152 | do { |
<> | 144:ef7eb2e8f9f7 | 153 | newValue = __LDREXW((volatile uint32_t*)valuePtr) + delta; |
<> | 144:ef7eb2e8f9f7 | 154 | } while (__STREXW(newValue, (volatile uint32_t*)valuePtr)); |
<> | 144:ef7eb2e8f9f7 | 155 | return newValue; |
<> | 144:ef7eb2e8f9f7 | 156 | } |
<> | 144:ef7eb2e8f9f7 | 157 | |
<> | 144:ef7eb2e8f9f7 | 158 | |
<> | 144:ef7eb2e8f9f7 | 159 | uint8_t core_util_atomic_decr_u8(uint8_t *valuePtr, uint8_t delta) |
<> | 144:ef7eb2e8f9f7 | 160 | { |
<> | 144:ef7eb2e8f9f7 | 161 | uint8_t newValue; |
<> | 144:ef7eb2e8f9f7 | 162 | do { |
<> | 144:ef7eb2e8f9f7 | 163 | newValue = __LDREXB((volatile uint8_t*)valuePtr) - delta; |
<> | 144:ef7eb2e8f9f7 | 164 | } while (__STREXB(newValue, (volatile uint8_t*)valuePtr)); |
<> | 144:ef7eb2e8f9f7 | 165 | return newValue; |
<> | 144:ef7eb2e8f9f7 | 166 | } |
<> | 144:ef7eb2e8f9f7 | 167 | |
<> | 144:ef7eb2e8f9f7 | 168 | uint16_t core_util_atomic_decr_u16(uint16_t *valuePtr, uint16_t delta) |
<> | 144:ef7eb2e8f9f7 | 169 | { |
<> | 144:ef7eb2e8f9f7 | 170 | uint16_t newValue; |
<> | 144:ef7eb2e8f9f7 | 171 | do { |
<> | 144:ef7eb2e8f9f7 | 172 | newValue = __LDREXH((volatile uint16_t*)valuePtr) - delta; |
<> | 144:ef7eb2e8f9f7 | 173 | } while (__STREXH(newValue, (volatile uint16_t*)valuePtr)); |
<> | 144:ef7eb2e8f9f7 | 174 | return newValue; |
<> | 144:ef7eb2e8f9f7 | 175 | } |
<> | 144:ef7eb2e8f9f7 | 176 | |
<> | 144:ef7eb2e8f9f7 | 177 | uint32_t core_util_atomic_decr_u32(uint32_t *valuePtr, uint32_t delta) |
<> | 144:ef7eb2e8f9f7 | 178 | { |
<> | 144:ef7eb2e8f9f7 | 179 | uint32_t newValue; |
<> | 144:ef7eb2e8f9f7 | 180 | do { |
<> | 144:ef7eb2e8f9f7 | 181 | newValue = __LDREXW((volatile uint32_t*)valuePtr) - delta; |
<> | 144:ef7eb2e8f9f7 | 182 | } while (__STREXW(newValue, (volatile uint32_t*)valuePtr)); |
<> | 144:ef7eb2e8f9f7 | 183 | return newValue; |
<> | 144:ef7eb2e8f9f7 | 184 | } |
<> | 144:ef7eb2e8f9f7 | 185 | |
<> | 144:ef7eb2e8f9f7 | 186 | #else |
<> | 144:ef7eb2e8f9f7 | 187 | |
<> | 144:ef7eb2e8f9f7 | 188 | bool core_util_atomic_cas_u8(uint8_t *ptr, uint8_t *expectedCurrentValue, uint8_t desiredValue) |
<> | 144:ef7eb2e8f9f7 | 189 | { |
<> | 144:ef7eb2e8f9f7 | 190 | bool success; |
<> | 144:ef7eb2e8f9f7 | 191 | uint8_t currentValue; |
<> | 144:ef7eb2e8f9f7 | 192 | core_util_critical_section_enter(); |
<> | 144:ef7eb2e8f9f7 | 193 | currentValue = *ptr; |
<> | 144:ef7eb2e8f9f7 | 194 | if (currentValue == *expectedCurrentValue) { |
<> | 144:ef7eb2e8f9f7 | 195 | *ptr = desiredValue; |
<> | 144:ef7eb2e8f9f7 | 196 | success = true; |
<> | 144:ef7eb2e8f9f7 | 197 | } else { |
<> | 144:ef7eb2e8f9f7 | 198 | *expectedCurrentValue = currentValue; |
<> | 144:ef7eb2e8f9f7 | 199 | success = false; |
<> | 144:ef7eb2e8f9f7 | 200 | } |
<> | 144:ef7eb2e8f9f7 | 201 | core_util_critical_section_exit(); |
<> | 144:ef7eb2e8f9f7 | 202 | return success; |
<> | 144:ef7eb2e8f9f7 | 203 | } |
<> | 144:ef7eb2e8f9f7 | 204 | |
<> | 144:ef7eb2e8f9f7 | 205 | bool core_util_atomic_cas_u16(uint16_t *ptr, uint16_t *expectedCurrentValue, uint16_t desiredValue) |
<> | 144:ef7eb2e8f9f7 | 206 | { |
<> | 144:ef7eb2e8f9f7 | 207 | bool success; |
<> | 144:ef7eb2e8f9f7 | 208 | uint16_t currentValue; |
<> | 144:ef7eb2e8f9f7 | 209 | core_util_critical_section_enter(); |
<> | 144:ef7eb2e8f9f7 | 210 | currentValue = *ptr; |
<> | 144:ef7eb2e8f9f7 | 211 | if (currentValue == *expectedCurrentValue) { |
<> | 144:ef7eb2e8f9f7 | 212 | *ptr = desiredValue; |
<> | 144:ef7eb2e8f9f7 | 213 | success = true; |
<> | 144:ef7eb2e8f9f7 | 214 | } else { |
<> | 144:ef7eb2e8f9f7 | 215 | *expectedCurrentValue = currentValue; |
<> | 144:ef7eb2e8f9f7 | 216 | success = false; |
<> | 144:ef7eb2e8f9f7 | 217 | } |
<> | 144:ef7eb2e8f9f7 | 218 | core_util_critical_section_exit(); |
<> | 144:ef7eb2e8f9f7 | 219 | return success; |
<> | 144:ef7eb2e8f9f7 | 220 | } |
<> | 144:ef7eb2e8f9f7 | 221 | |
<> | 144:ef7eb2e8f9f7 | 222 | |
<> | 144:ef7eb2e8f9f7 | 223 | bool core_util_atomic_cas_u32(uint32_t *ptr, uint32_t *expectedCurrentValue, uint32_t desiredValue) |
<> | 144:ef7eb2e8f9f7 | 224 | { |
<> | 144:ef7eb2e8f9f7 | 225 | bool success; |
<> | 144:ef7eb2e8f9f7 | 226 | uint32_t currentValue; |
<> | 144:ef7eb2e8f9f7 | 227 | core_util_critical_section_enter(); |
<> | 144:ef7eb2e8f9f7 | 228 | currentValue = *ptr; |
<> | 144:ef7eb2e8f9f7 | 229 | if (currentValue == *expectedCurrentValue) { |
<> | 144:ef7eb2e8f9f7 | 230 | *ptr = desiredValue; |
<> | 144:ef7eb2e8f9f7 | 231 | success = true; |
<> | 144:ef7eb2e8f9f7 | 232 | } else { |
<> | 144:ef7eb2e8f9f7 | 233 | *expectedCurrentValue = currentValue; |
<> | 144:ef7eb2e8f9f7 | 234 | success = false; |
<> | 144:ef7eb2e8f9f7 | 235 | } |
<> | 144:ef7eb2e8f9f7 | 236 | core_util_critical_section_exit(); |
<> | 144:ef7eb2e8f9f7 | 237 | return success; |
<> | 144:ef7eb2e8f9f7 | 238 | } |
<> | 144:ef7eb2e8f9f7 | 239 | |
<> | 144:ef7eb2e8f9f7 | 240 | |
<> | 144:ef7eb2e8f9f7 | 241 | uint8_t core_util_atomic_incr_u8(uint8_t *valuePtr, uint8_t delta) |
<> | 144:ef7eb2e8f9f7 | 242 | { |
<> | 144:ef7eb2e8f9f7 | 243 | uint8_t newValue; |
<> | 144:ef7eb2e8f9f7 | 244 | core_util_critical_section_enter(); |
<> | 144:ef7eb2e8f9f7 | 245 | newValue = *valuePtr + delta; |
<> | 144:ef7eb2e8f9f7 | 246 | *valuePtr = newValue; |
<> | 144:ef7eb2e8f9f7 | 247 | core_util_critical_section_exit(); |
<> | 144:ef7eb2e8f9f7 | 248 | return newValue; |
<> | 144:ef7eb2e8f9f7 | 249 | } |
<> | 144:ef7eb2e8f9f7 | 250 | |
<> | 144:ef7eb2e8f9f7 | 251 | uint16_t core_util_atomic_incr_u16(uint16_t *valuePtr, uint16_t delta) |
<> | 144:ef7eb2e8f9f7 | 252 | { |
<> | 144:ef7eb2e8f9f7 | 253 | uint16_t newValue; |
<> | 144:ef7eb2e8f9f7 | 254 | core_util_critical_section_enter(); |
<> | 144:ef7eb2e8f9f7 | 255 | newValue = *valuePtr + delta; |
<> | 144:ef7eb2e8f9f7 | 256 | *valuePtr = newValue; |
<> | 144:ef7eb2e8f9f7 | 257 | core_util_critical_section_exit(); |
<> | 144:ef7eb2e8f9f7 | 258 | return newValue; |
<> | 144:ef7eb2e8f9f7 | 259 | } |
<> | 144:ef7eb2e8f9f7 | 260 | |
<> | 144:ef7eb2e8f9f7 | 261 | uint32_t core_util_atomic_incr_u32(uint32_t *valuePtr, uint32_t delta) |
<> | 144:ef7eb2e8f9f7 | 262 | { |
<> | 144:ef7eb2e8f9f7 | 263 | uint32_t newValue; |
<> | 144:ef7eb2e8f9f7 | 264 | core_util_critical_section_enter(); |
<> | 144:ef7eb2e8f9f7 | 265 | newValue = *valuePtr + delta; |
<> | 144:ef7eb2e8f9f7 | 266 | *valuePtr = newValue; |
<> | 144:ef7eb2e8f9f7 | 267 | core_util_critical_section_exit(); |
<> | 144:ef7eb2e8f9f7 | 268 | return newValue; |
<> | 144:ef7eb2e8f9f7 | 269 | } |
<> | 144:ef7eb2e8f9f7 | 270 | |
<> | 144:ef7eb2e8f9f7 | 271 | |
<> | 144:ef7eb2e8f9f7 | 272 | uint8_t core_util_atomic_decr_u8(uint8_t *valuePtr, uint8_t delta) |
<> | 144:ef7eb2e8f9f7 | 273 | { |
<> | 144:ef7eb2e8f9f7 | 274 | uint8_t newValue; |
<> | 144:ef7eb2e8f9f7 | 275 | core_util_critical_section_enter(); |
<> | 144:ef7eb2e8f9f7 | 276 | newValue = *valuePtr - delta; |
<> | 144:ef7eb2e8f9f7 | 277 | *valuePtr = newValue; |
<> | 144:ef7eb2e8f9f7 | 278 | core_util_critical_section_exit(); |
<> | 144:ef7eb2e8f9f7 | 279 | return newValue; |
<> | 144:ef7eb2e8f9f7 | 280 | } |
<> | 144:ef7eb2e8f9f7 | 281 | |
<> | 144:ef7eb2e8f9f7 | 282 | uint16_t core_util_atomic_decr_u16(uint16_t *valuePtr, uint16_t delta) |
<> | 144:ef7eb2e8f9f7 | 283 | { |
<> | 144:ef7eb2e8f9f7 | 284 | uint16_t newValue; |
<> | 144:ef7eb2e8f9f7 | 285 | core_util_critical_section_enter(); |
<> | 144:ef7eb2e8f9f7 | 286 | newValue = *valuePtr - delta; |
<> | 144:ef7eb2e8f9f7 | 287 | *valuePtr = newValue; |
<> | 144:ef7eb2e8f9f7 | 288 | core_util_critical_section_exit(); |
<> | 144:ef7eb2e8f9f7 | 289 | return newValue; |
<> | 144:ef7eb2e8f9f7 | 290 | } |
<> | 144:ef7eb2e8f9f7 | 291 | |
<> | 144:ef7eb2e8f9f7 | 292 | uint32_t core_util_atomic_decr_u32(uint32_t *valuePtr, uint32_t delta) |
<> | 144:ef7eb2e8f9f7 | 293 | { |
<> | 144:ef7eb2e8f9f7 | 294 | uint32_t newValue; |
<> | 144:ef7eb2e8f9f7 | 295 | core_util_critical_section_enter(); |
<> | 144:ef7eb2e8f9f7 | 296 | newValue = *valuePtr - delta; |
<> | 144:ef7eb2e8f9f7 | 297 | *valuePtr = newValue; |
<> | 144:ef7eb2e8f9f7 | 298 | core_util_critical_section_exit(); |
<> | 144:ef7eb2e8f9f7 | 299 | return newValue; |
<> | 144:ef7eb2e8f9f7 | 300 | } |
<> | 144:ef7eb2e8f9f7 | 301 | |
<> | 144:ef7eb2e8f9f7 | 302 | #endif |
<> | 144:ef7eb2e8f9f7 | 303 | |
<> | 144:ef7eb2e8f9f7 | 304 | |
<> | 144:ef7eb2e8f9f7 | 305 | bool core_util_atomic_cas_ptr(void **ptr, void **expectedCurrentValue, void *desiredValue) { |
<> | 144:ef7eb2e8f9f7 | 306 | return core_util_atomic_cas_u32( |
<> | 144:ef7eb2e8f9f7 | 307 | (uint32_t *)ptr, |
<> | 144:ef7eb2e8f9f7 | 308 | (uint32_t *)expectedCurrentValue, |
<> | 144:ef7eb2e8f9f7 | 309 | (uint32_t)desiredValue); |
<> | 144:ef7eb2e8f9f7 | 310 | } |
<> | 144:ef7eb2e8f9f7 | 311 | |
<> | 144:ef7eb2e8f9f7 | 312 | void *core_util_atomic_incr_ptr(void **valuePtr, ptrdiff_t delta) { |
<> | 144:ef7eb2e8f9f7 | 313 | return (void *)core_util_atomic_incr_u32((uint32_t *)valuePtr, (uint32_t)delta); |
<> | 144:ef7eb2e8f9f7 | 314 | } |
<> | 144:ef7eb2e8f9f7 | 315 | |
<> | 144:ef7eb2e8f9f7 | 316 | void *core_util_atomic_decr_ptr(void **valuePtr, ptrdiff_t delta) { |
<> | 144:ef7eb2e8f9f7 | 317 | return (void *)core_util_atomic_decr_u32((uint32_t *)valuePtr, (uint32_t)delta); |
<> | 144:ef7eb2e8f9f7 | 318 | } |
<> | 144:ef7eb2e8f9f7 | 319 |