Mercurial > sdl-ios-xcode
comparison test/testsem.c @ 1151:be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
if SDL is built with a non-cdecl calling convention, and it's just generally
bad practice anyhow.
Now programs explicitly call SDL_Quit() where appropriate, wrap SDL_Quit() in
a cdecl function where it can't be avoided, and rely on the parachute where
a crash might have hit the atexit() before (these ARE test programs, after
all!).
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Wed, 28 Sep 2005 11:36:20 +0000 |
parents | 74212992fb08 |
children | 4d3bb026cd16 |
comparison
equal
deleted
inserted
replaced
1150:7d8e1925f35b | 1151:be9c9c8f6d53 |
---|---|
10 | 10 |
11 #define NUM_THREADS 10 | 11 #define NUM_THREADS 10 |
12 | 12 |
13 static SDL_sem *sem; | 13 static SDL_sem *sem; |
14 int alive = 1; | 14 int alive = 1; |
15 | |
16 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ | |
17 static void quit(int rc) | |
18 { | |
19 SDL_Quit(); | |
20 exit(rc); | |
21 } | |
15 | 22 |
16 int ThreadFunc(void *data) | 23 int ThreadFunc(void *data) |
17 { | 24 { |
18 while ( alive ) { | 25 while ( alive ) { |
19 SDL_SemWait(sem); | 26 SDL_SemWait(sem); |
37 SDL_Thread *threads[NUM_THREADS]; | 44 SDL_Thread *threads[NUM_THREADS]; |
38 int i, init_sem; | 45 int i, init_sem; |
39 | 46 |
40 if(argc < 2) { | 47 if(argc < 2) { |
41 fprintf(stderr,"Usage: %s init_value\n", argv[0]); | 48 fprintf(stderr,"Usage: %s init_value\n", argv[0]); |
42 exit(1); | 49 return(1); |
43 } | 50 } |
44 | 51 |
45 /* Load the SDL library */ | 52 /* Load the SDL library */ |
46 if ( SDL_Init(0) < 0 ) { | 53 if ( SDL_Init(0) < 0 ) { |
47 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); | 54 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); |
48 exit(1); | 55 return(1); |
49 } | 56 } |
50 atexit(SDL_Quit); | |
51 signal(SIGTERM, killed); | 57 signal(SIGTERM, killed); |
52 signal(SIGINT, killed); | 58 signal(SIGINT, killed); |
53 | 59 |
54 init_sem = atoi(argv[1]); | 60 init_sem = atoi(argv[1]); |
55 sem = SDL_CreateSemaphore(init_sem); | 61 sem = SDL_CreateSemaphore(init_sem); |
70 SDL_WaitThread(threads[i], NULL); | 76 SDL_WaitThread(threads[i], NULL); |
71 } | 77 } |
72 printf("Finished waiting for threads\n"); | 78 printf("Finished waiting for threads\n"); |
73 | 79 |
74 SDL_DestroySemaphore(sem); | 80 SDL_DestroySemaphore(sem); |
81 SDL_Quit(); | |
75 return(0); | 82 return(0); |
76 } | 83 } |