source: mainline/kernel/arch/abs32le/include/atomic.h@ 68667ce

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 68667ce was 33c4f72, checked in by Martin Decky <martin@…>, 15 years ago

improve annotations
move to the newest VCC syntax
use VCC specifications as a separate vcc.h header

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 * Copyright (c) 2010 Martin Decky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup abs32le
30 * @{
31 */
32/** @file
33 */
34
35#ifndef KERN_abs32le_ATOMIC_H_
36#define KERN_abs32le_ATOMIC_H_
37
38#include <typedefs.h>
39#include <arch/barrier.h>
40#include <preemption.h>
41#include <verify.h>
42
43ATOMIC static inline void atomic_inc(atomic_t *val)
44 WRITES(&val->count)
45 REQUIRES_EXTENT_MUTABLE(val)
46 REQUIRES(val->count < ATOMIC_COUNT_MAX)
47{
48 /* On real hardware the increment has to be done
49 as an atomic action. */
50
51 val->count++;
52}
53
54ATOMIC static inline void atomic_dec(atomic_t *val)
55 WRITES(&val->count)
56 REQUIRES_EXTENT_MUTABLE(val)
57 REQUIRES(val->count > ATOMIC_COUNT_MIN)
58{
59 /* On real hardware the decrement has to be done
60 as an atomic action. */
61
62 val->count--;
63}
64
65ATOMIC static inline atomic_count_t atomic_postinc(atomic_t *val)
66 WRITES(&val->count)
67 REQUIRES_EXTENT_MUTABLE(val)
68 REQUIRES(val->count < ATOMIC_COUNT_MAX)
69{
70 /* On real hardware both the storing of the previous
71 value and the increment have to be done as a single
72 atomic action. */
73
74 atomic_count_t prev = val->count;
75
76 val->count++;
77 return prev;
78}
79
80ATOMIC static inline atomic_count_t atomic_postdec(atomic_t *val)
81 WRITES(&val->count)
82 REQUIRES_EXTENT_MUTABLE(val)
83 REQUIRES(val->count > ATOMIC_COUNT_MIN)
84{
85 /* On real hardware both the storing of the previous
86 value and the decrement have to be done as a single
87 atomic action. */
88
89 atomic_count_t prev = val->count;
90
91 val->count--;
92 return prev;
93}
94
95#define atomic_preinc(val) (atomic_postinc(val) + 1)
96#define atomic_predec(val) (atomic_postdec(val) - 1)
97
98ATOMIC static inline atomic_count_t test_and_set(atomic_t *val)
99 WRITES(&val->count)
100 REQUIRES_EXTENT_MUTABLE(val)
101{
102 /* On real hardware the retrieving of the original
103 value and storing 1 have to be done as a single
104 atomic action. */
105
106 atomic_count_t prev = val->count;
107 val->count = 1;
108 return prev;
109}
110
111static inline void atomic_lock_arch(atomic_t *val)
112 WRITES(&val->count)
113 REQUIRES_EXTENT_MUTABLE(val)
114{
115 do {
116 while (val->count);
117 } while (test_and_set(val));
118}
119
120#endif
121
122/** @}
123 */
Note: See TracBrowser for help on using the repository browser.