annotate test/testatomic.c @ 3180:77d6336711fc

First commit for SDL atomic operations. On my linux box it compiles and installs correctly and testatomic runs without errors.
author Bob Pendleton <bob@pendleton.com>
date Tue, 09 Jun 2009 17:33:44 +0000
parents
children 51750b7a966f
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
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
4 main(int argc, char** argv)
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
5 {
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
6 int rv = 10;
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
7 volatile int atomic;
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
8
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
9 SDL_atomic_int_set(&atomic, 10);
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
10 if(SDL_atomic_int_get(&atomic) != 10)
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
11 printf("Error: ");
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
12 printf("SDL_atomic_int_set(atomic, 10): atomic-> %d\n",
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
13 SDL_atomic_int_get(&atomic));
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
14
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
15 SDL_atomic_int_add(&atomic, 10);
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
16 if(SDL_atomic_int_get(&atomic) != 20)
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
17 printf("Error: ");
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
18 printf("SDL_atomic_int_add(atomic, 10): atomic-> %d\n",
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
19 SDL_atomic_int_get(&atomic));
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
20
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
21 rv = SDL_atomic_int_cmp_xchg(&atomic, 20, 30);
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
22 if(rv != SDL_TRUE || SDL_atomic_int_get(&atomic) != 30)
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
23 printf("Error: ");
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
24 printf("SDL_atomic_int_cmp_xchg(atomic, 20, 30): rv-> %d, atomic-> %d\n",
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
25 rv, SDL_atomic_int_get(&atomic));
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
26
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
27 rv = SDL_atomic_int_cmp_xchg(&atomic, 20, 30);
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
28 if(rv != SDL_FALSE || SDL_atomic_int_get(&atomic) != 30)
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
29 printf("Error: ");
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
30 printf("SDL_atomic_int_cmp_xchg(atomic, 20, 40): rv-> %d, atomic-> %d\n",
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
31 rv, SDL_atomic_int_get(&atomic));
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
32
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
33 rv = SDL_atomic_int_xchg_add(&atomic, 10);
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
34 if(rv != 30 || SDL_atomic_int_get(&atomic) != 40)
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
35 printf("Error: ");
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
36 printf("SDL_atomic_int_xchg_add(atomic, 10): rv-> %d, atomic-> %d\n",
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
37 rv, SDL_atomic_int_get(&atomic));
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
38
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
39 SDL_atomic_int_inc(&atomic);
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
40 if(SDL_atomic_int_get(&atomic) != 41)
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
41 printf("Error: ");
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
42 printf("SDL_atomic_int_inc(atomic): atomic-> %d\n",
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
43 SDL_atomic_int_get(&atomic));
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
44
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
45 rv = SDL_atomic_int_dec_test(&atomic);
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
46 if(rv != SDL_FALSE || SDL_atomic_int_get(&atomic) != 40)
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
47 printf("Error: ");
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
48 printf("SDL_atomic_int_dec_test(atomic): rv-> %d, atomic-> %d\n",
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
49 rv, SDL_atomic_int_get(&atomic));
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
50
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
51 SDL_atomic_int_set(&atomic, 1);
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
52 if(SDL_atomic_int_get(&atomic) != 1)
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
53 printf("Error: ");
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
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
57 rv = SDL_atomic_int_dec_test(&atomic);
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
58 if(rv != SDL_TRUE || SDL_atomic_int_get(&atomic) != 0)
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
59 printf("Error: ");
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
60 printf("SDL_atomic_int_dec_test(atomic): rv-> %d, atomic-> %d\n",
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
61 rv, SDL_atomic_int_get(&atomic));
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
62
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
63 return 0;
77d6336711fc First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff changeset
64 }