File: atomic.c

package info (click to toggle)
brickos 0.9.0.dfsg-8
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,756 kB
  • ctags: 1,826
  • sloc: ansic: 9,144; cpp: 860; asm: 693; makefile: 648; sh: 124; perl: 61
file content (46 lines) | stat: -rw-r--r-- 1,059 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "config.h"
#include <atomic.h>

#ifdef CONF_ATOMIC
/**
 * increment atomic counter without interruption.
 * locks interrupts except NMI, increments count
 * then restores interrupts.
 * @param counter the counter resource to be incremented
 * @see atomic_dec
 */
void atomic_inc(atomic_t* counter);
__asm__("\n\
.text\n\
.globl _atomic_inc\n\
       _atomic_inc:\n\
	stc   ccr, r1h				; save flags\n\
	orc   #0x80, ccr			; disable all but NMI\n\
	mov.b @r0, r1l\n\
	inc   r1l\n\
	mov.b r1l, @r0\n\
	ldc   r1h, ccr				; restore flags\n\
	rts\n\
");

/**
 * decrement atomic counter without interruption.
 * locks interrupts except NMI, decrements count
 * then restores interrupts.
 * @param counter the counter resource to be decremented
 * @see atomic_inc
 */
void atomic_dec(atomic_t* counter);
__asm__("\n\
.text\n\
.globl _atomic_dec\n\
       _atomic_dec:\n\
         stc   ccr, r1h\n\
         orc   #0x80, ccr\n\
         mov.b @r0, r1l\n\
         dec   r1l\n\
         mov.b r1l, @r0\n\
         ldc   r1h, ccr\n\
         rts\n\
");
#endif