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

Last change on this file since 444 was 408, checked in by alain, 7 years ago

Fix several bugs in the fork() syscall.

File size: 4.5 KB
RevLine 
[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 ****************************************************************************************/
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 ****************************************************************************************/
65uint32_t hal_atomic_add( void     * ptr,
66                         int32_t    val );
67
68/*****************************************************************************************
[17]69 * This NON blocking function makes an atomic Compare-And-Swap on a 32 bits unsigned int
[408]70 * shared variable, returning a Boolean to indicate success.
[1]71 *****************************************************************************************
72 * @ ptr     : pointer on the shared variable
73 * @ old     : expected value for the shared variable
[108]74 * @ new     : value to be written if success
[408]75 * @ return true if success.
[1]76 ****************************************************************************************/
77bool_t hal_atomic_cas( uint32_t * ptr,
78                       uint32_t   old,
79                       uint32_t   new );
80
81/*****************************************************************************************
[17]82 * This non blocking function makes an atomic Test-if-zero-And-Set on a 32 bits unsigned
[1]83 * int shared variable, returning a Boolean to indicate both success and atomicity.
84 *****************************************************************************************
85 * @ ptr     : pointer on the shared variable
[108]86 * @ val     : value to be written if success
[1]87 * @ return true if (current == 0) and (access is atomic)
88 ****************************************************************************************/
[17]89bool_t hal_atomic_test_set( uint32_t * ptr,
[1]90                            uint32_t   val );
91
92#endif  /* _HAL_ATOMIC_H_ */
Note: See TracBrowser for help on using the repository browser.