source: mainline/kernel/arch/sparc32/include/arch/atomic.h@ 32e8cd1

lfn serial ticket/834-toolchain-update topic/fix-logger-deadlock topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 32e8cd1 was 32e8cd1, checked in by Martin Decky <martin@…>, 13 years ago

code revision
coding style fixes
removal of debugging printouts and other temporary stuff

  • Property mode set to 100644
File size: 3.1 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 sparc32
30 * @{
31 */
32/** @file
33 */
34
35#ifndef KERN_sparc32_ATOMIC_H_
36#define KERN_sparc32_ATOMIC_H_
37
38#include <typedefs.h>
39#include <arch/barrier.h>
40#include <preemption.h>
41#include <verify.h>
42#include <trace.h>
43
44NO_TRACE ATOMIC static inline void atomic_inc(atomic_t *val)
45 WRITES(&val->count)
46 REQUIRES_EXTENT_MUTABLE(val)
47 REQUIRES(val->count < ATOMIC_COUNT_MAX)
48{
49 // FIXME TODO
50 val->count++;
51}
52
53NO_TRACE ATOMIC static inline void atomic_dec(atomic_t *val)
54 WRITES(&val->count)
55 REQUIRES_EXTENT_MUTABLE(val)
56 REQUIRES(val->count > ATOMIC_COUNT_MIN)
57{
58 // FIXME TODO
59 val->count--;
60}
61
62NO_TRACE ATOMIC static inline atomic_count_t atomic_postinc(atomic_t *val)
63 WRITES(&val->count)
64 REQUIRES_EXTENT_MUTABLE(val)
65 REQUIRES(val->count < ATOMIC_COUNT_MAX)
66{
67 // FIXME TODO
68
69 atomic_count_t prev = val->count;
70
71 val->count++;
72 return prev;
73}
74
75NO_TRACE ATOMIC static inline atomic_count_t atomic_postdec(atomic_t *val)
76 WRITES(&val->count)
77 REQUIRES_EXTENT_MUTABLE(val)
78 REQUIRES(val->count > ATOMIC_COUNT_MIN)
79{
80 // FIXME TODO
81
82 atomic_count_t prev = val->count;
83
84 val->count--;
85 return prev;
86}
87
88#define atomic_preinc(val) (atomic_postinc(val) + 1)
89#define atomic_predec(val) (atomic_postdec(val) - 1)
90
91NO_TRACE ATOMIC static inline atomic_count_t test_and_set(atomic_t *val)
92 WRITES(&val->count)
93 REQUIRES_EXTENT_MUTABLE(val)
94{
95 // FIXME TODO
96
97 atomic_count_t prev = val->count;
98 val->count = 1;
99 return prev;
100}
101
102NO_TRACE static inline void atomic_lock_arch(atomic_t *val)
103 WRITES(&val->count)
104 REQUIRES_EXTENT_MUTABLE(val)
105{
106 // FIXME TODO
107
108 do {
109 while (val->count);
110 } while (test_and_set(val));
111}
112
113#endif
114
115/** @}
116 */
Note: See TracBrowser for help on using the repository browser.