[1] | 1 | /* |
---|
| 2 | * hal_atomic.h - Generic Atomic Operations API definition. |
---|
[17] | 3 | * |
---|
[1] | 4 | * Authors Alain Greiner (2016) |
---|
| 5 | * |
---|
| 6 | * Copyright (c) UPMC Sorbonne Universites |
---|
[17] | 7 | * |
---|
[1] | 8 | * This file is part of ALMOS-MKH. |
---|
| 9 | * |
---|
| 10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
| 11 | * under the terms of the GNU General Public License as published by |
---|
| 12 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 13 | * |
---|
| 14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 17 | * General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
| 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | #ifndef _HAL_ATOMIC_H_ |
---|
| 25 | #define _HAL_ATOMIC_H_ |
---|
| 26 | |
---|
[16] | 27 | #include <kernel_config.h> |
---|
[1] | 28 | #include <hal_types.h> |
---|
| 29 | |
---|
| 30 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[17] | 31 | // Generic Atomic Operations API (implementation in hal_atomic.c) |
---|
[1] | 32 | // |
---|
[17] | 33 | // Atomic read-then-write operations depend on the CPU instruction set. |
---|
[1] | 34 | // ALMOS-MKH uses the following generic API. |
---|
| 35 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 36 | |
---|
| 37 | /***************************************************************************************** |
---|
| 38 | * This blocking function makes an atomic "and" between a 32 bits mask, and a 32 bits |
---|
| 39 | * unsigned int shared variable, returning only when atomic operation is successful. |
---|
| 40 | ***************************************************************************************** |
---|
| 41 | * @ ptr : pointer on the shared variable |
---|
[17] | 42 | * @ val : mask value |
---|
[1] | 43 | ****************************************************************************************/ |
---|
| 44 | void hal_atomic_and( uint32_t * ptr, |
---|
| 45 | uint32_t val ); |
---|
| 46 | |
---|
| 47 | /***************************************************************************************** |
---|
| 48 | * This blocking function makes an atomic "or" between a 32 bits mask, and a 32 bits |
---|
| 49 | * unsigned int shared variable, returning only when atomic operation is successful. |
---|
| 50 | ***************************************************************************************** |
---|
| 51 | * @ ptr : pointer on the shared variable |
---|
| 52 | * @ val : mask value |
---|
| 53 | ****************************************************************************************/ |
---|
| 54 | void hal_atomic_or( uint32_t * ptr, |
---|
| 55 | uint32_t val ); |
---|
| 56 | |
---|
| 57 | /***************************************************************************************** |
---|
| 58 | * This blocking function atomically adds a positive or negative value to a 32 bits |
---|
| 59 | * signed or unsigned int shared variable, returning only when atomic add is successful. |
---|
| 60 | ***************************************************************************************** |
---|
| 61 | * @ ptr : pointer on the shared variable (signed or unsigned) |
---|
| 62 | * @ val : signed value to add |
---|
| 63 | * @ return shared variable value before add |
---|
| 64 | ****************************************************************************************/ |
---|
| 65 | uint32_t hal_atomic_add( void * ptr, |
---|
| 66 | int32_t val ); |
---|
| 67 | |
---|
| 68 | /***************************************************************************************** |
---|
| 69 | * This blocking function atomically increments a 32 bits unsigned int shared variable, |
---|
| 70 | * returning only when atomic increment is successful. |
---|
| 71 | ***************************************************************************************** |
---|
| 72 | * @ ptr : pointer on the shared variable |
---|
| 73 | * @ return shared variable value before increment |
---|
| 74 | ****************************************************************************************/ |
---|
| 75 | uint32_t hal_atomic_inc( uint32_t * ptr ); |
---|
| 76 | |
---|
| 77 | /***************************************************************************************** |
---|
| 78 | * This blocking function atomically decrements a 32 bits unsigned int shared variable, |
---|
| 79 | * returning only when atomic decrement is successful. |
---|
| 80 | ***************************************************************************************** |
---|
| 81 | * @ ptr : pointer on the shared variable |
---|
| 82 | * @ return shared variable value before decrement |
---|
| 83 | ****************************************************************************************/ |
---|
| 84 | uint32_t hal_atomic_dec( uint32_t * ptr ); |
---|
| 85 | |
---|
| 86 | /***************************************************************************************** |
---|
[17] | 87 | * This NON blocking function makes an atomic Compare-And-Swap on a 32 bits unsigned int |
---|
[1] | 88 | * shared variable, returning a Boolean to indicate both success and atomicity. |
---|
| 89 | ***************************************************************************************** |
---|
| 90 | * @ ptr : pointer on the shared variable |
---|
| 91 | * @ old : expected value for the shared variable |
---|
| 92 | * @ new : value to be writen if success |
---|
| 93 | * @ return true if (current == old) and (access is atomic) |
---|
| 94 | ****************************************************************************************/ |
---|
| 95 | bool_t hal_atomic_cas( uint32_t * ptr, |
---|
| 96 | uint32_t old, |
---|
| 97 | uint32_t new ); |
---|
| 98 | |
---|
| 99 | /***************************************************************************************** |
---|
[17] | 100 | * This non blocking function makes an atomic Test-if-zero-And-Set on a 32 bits unsigned |
---|
[1] | 101 | * int shared variable, returning a Boolean to indicate both success and atomicity. |
---|
| 102 | ***************************************************************************************** |
---|
| 103 | * @ ptr : pointer on the shared variable |
---|
| 104 | * @ val : value to be writen if success |
---|
| 105 | * @ return true if (current == 0) and (access is atomic) |
---|
| 106 | ****************************************************************************************/ |
---|
[17] | 107 | bool_t hal_atomic_test_set( uint32_t * ptr, |
---|
[1] | 108 | uint32_t val ); |
---|
| 109 | |
---|
| 110 | #endif /* _HAL_ATOMIC_H_ */ |
---|