source: trunk/hal/generic/hal_atomic.h @ 506

Last change on this file since 506 was 505, checked in by viala@…, 6 years ago

[hal] Fix protoypes and add headers in hal mips32 implementation.

Fix types mismatch between implementation and interface in .h.
Add header where they were absent.

File size: 4.5 KB
Line 
1/*
2 * hal_atomic.h - Generic Atomic Operations API definition.
3 *
4 * Authors   Alain Greiner    (2016)
5 *
6 * Copyright (c)  UPMC Sorbonne Universites
7 *
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
27#include <kernel_config.h>
28#include <hal_kernel_types.h>
29
30//////////////////////////////////////////////////////////////////////////////////////////
31//            Generic Atomic Operations API (implementation in hal_atomic.c)
32//
33// Atomic read-then-write operations depend on the CPU instruction set.
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
42 * @ val     : mask value
43 ****************************************************************************************/
44void 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 ****************************************************************************************/
54void 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 ****************************************************************************************/
65int32_t hal_atomic_add( void     * ptr,
66                        int32_t    val );
67
68/*****************************************************************************************
69 * This NON blocking function makes an atomic Compare-And-Swap on a 32 bits unsigned int
70 * shared variable, returning a Boolean to indicate success.
71 *****************************************************************************************
72 * @ ptr     : pointer on the shared variable
73 * @ old     : expected value for the shared variable
74 * @ new     : value to be written if success
75 * @ return true if success.
76 ****************************************************************************************/
77bool_t hal_atomic_cas( uint32_t * ptr,
78                       uint32_t   old,
79                       uint32_t   new );
80
81/*****************************************************************************************
82 * This non blocking function makes an atomic Test-if-zero-And-Set on a 32 bits unsigned
83 * int shared variable, returning a Boolean to indicate both success and atomicity.
84 *****************************************************************************************
85 * @ ptr     : pointer on the shared variable
86 * @ val     : value to be written if success
87 * @ return true if (current == 0) and (access is atomic)
88 ****************************************************************************************/
89bool_t hal_atomic_test_set( uint32_t * ptr,
90                            uint32_t   val );
91
92#endif  /* _HAL_ATOMIC_H_ */
Note: See TracBrowser for help on using the repository browser.