annotate test/testatomic.c @ 3186:51750b7a966f

indent
author Sam Lantinga <slouken@libsdl.org>
date Wed, 10 Jun 2009 13:34:20 +0000
parents 77d6336711fc
children 3e1bf2b8bd81
rev   line source
3180
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
1 #include "SDL.h"
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
2
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
3 int
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
4 main(int argc, char **argv)
3180
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
5 {
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
6 int rv = 10;
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
7 volatile int atomic;
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
8
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
9 SDL_atomic_int_set(&atomic, 10);
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
10 if (SDL_atomic_int_get(&atomic) != 10)
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
11 printf("Error: ");
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
12 printf("SDL_atomic_int_set(atomic, 10): atomic-> %d\n",
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
13 SDL_atomic_int_get(&atomic));
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
14
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
15 SDL_atomic_int_add(&atomic, 10);
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
16 if (SDL_atomic_int_get(&atomic) != 20)
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
17 printf("Error: ");
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
18 printf("SDL_atomic_int_add(atomic, 10): atomic-> %d\n",
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
19 SDL_atomic_int_get(&atomic));
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
20
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
21 rv = SDL_atomic_int_cmp_xchg(&atomic, 20, 30);
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
22 if (rv != SDL_TRUE || SDL_atomic_int_get(&atomic) != 30)
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
23 printf("Error: ");
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
24 printf("SDL_atomic_int_cmp_xchg(atomic, 20, 30): rv-> %d, atomic-> %d\n",
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
25 rv, SDL_atomic_int_get(&atomic));
3180
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
26
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
27 rv = SDL_atomic_int_cmp_xchg(&atomic, 20, 30);
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
28 if (rv != SDL_FALSE || SDL_atomic_int_get(&atomic) != 30)
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
29 printf("Error: ");
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
30 printf("SDL_atomic_int_cmp_xchg(atomic, 20, 40): rv-> %d, atomic-> %d\n",
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
31 rv, SDL_atomic_int_get(&atomic));
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
32
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
33 rv = SDL_atomic_int_xchg_add(&atomic, 10);
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
34 if (rv != 30 || SDL_atomic_int_get(&atomic) != 40)
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
35 printf("Error: ");
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
36 printf("SDL_atomic_int_xchg_add(atomic, 10): rv-> %d, atomic-> %d\n",
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
37 rv, SDL_atomic_int_get(&atomic));
3180
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
38
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
39 SDL_atomic_int_inc(&atomic);
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
40 if (SDL_atomic_int_get(&atomic) != 41)
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
41 printf("Error: ");
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
42 printf("SDL_atomic_int_inc(atomic): atomic-> %d\n",
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
43 SDL_atomic_int_get(&atomic));
3180
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
44
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
45 rv = SDL_atomic_int_dec_test(&atomic);
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
46 if (rv != SDL_FALSE || SDL_atomic_int_get(&atomic) != 40)
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
47 printf("Error: ");
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
48 printf("SDL_atomic_int_dec_test(atomic): rv-> %d, atomic-> %d\n",
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
49 rv, SDL_atomic_int_get(&atomic));
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
50
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
51 SDL_atomic_int_set(&atomic, 1);
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
52 if (SDL_atomic_int_get(&atomic) != 1)
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
53 printf("Error: ");
3180
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
54 printf("SDL_atomic_int_set(atomic, 1): atomic-> %d\n",
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
55 SDL_atomic_int_get(&atomic));
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
56
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
57 rv = SDL_atomic_int_dec_test(&atomic);
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
58 if (rv != SDL_TRUE || SDL_atomic_int_get(&atomic) != 0)
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
59 printf("Error: ");
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
60 printf("SDL_atomic_int_dec_test(atomic): rv-> %d, atomic-> %d\n",
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
61 rv, SDL_atomic_int_get(&atomic));
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
62
Sam Lantinga <slouken@libsdl.org>
parents: 3180
diff changeset
63 return 0;
3180
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
64 }