Mercurial > sdl-ios-xcode
annotate test/testlock.c @ 1768:814f9f2c7a33
Fixed bug #80
Date: 21 Apr 2003 17:20:20 +0100
From: Alan Swanson <swanson@uklinux.net>
Subject: [SDL] New XFree 4.3 Video Mode Patch
If you look at the unsorted list of modes returned by X, here's mine;
1280 x 1024 @ 85.0 >
1024 x 768 @ 100.3 > USER
800 x 600 @ 125.5 > SET
640 x 480 @ 124.9 >
1280 x 1024 @ 75.0 ]
1280 x 1024 @ 60.0 ]
1280 x 960 @ 85.0 ] X11
1280 x 960 @ 60.0 ] AUTO
1152 x 864 @ 75.0 ]=20
1152 x 768 @ 54.8 ]
960 x 720 @ 120.0 ]
...
640 x 400 @ 85.1 ] 256k
576 x 432 @ 150.0 ] 249k PIXEL
640 x 350 @ 85.1 ] 224k COUNT
576 x 384 @ 109.6 ] 221k
...
The user set modes come first followed by X set modes which are ordered
by decreasing number of pixels and refresh.
The reason why every other library or program not using SDL working is
due to SDL scanning the modes in reverse getting X11 provided modes
modes with the lowest refresh.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 05 May 2006 05:50:26 +0000 |
parents | be9c9c8f6d53 |
children | 14717b52abc0 |
rev | line source |
---|---|
0 | 1 |
2 /* Test the thread and mutex locking functions | |
3 Also exercises the system's signal/thread interaction | |
4 */ | |
5 | |
6 #include <signal.h> | |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 | |
10 #include "SDL.h" | |
11 #include "SDL_mutex.h" | |
12 #include "SDL_thread.h" | |
13 | |
14 static SDL_mutex *mutex = NULL; | |
15 static Uint32 mainthread; | |
16 static SDL_Thread *threads[6]; | |
17 | |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
18 /* |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
19 * SDL_Quit() shouldn't be used with atexit() directly because |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
20 * calling conventions may differ... |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
21 */ |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
22 static void SDL_Quit_Wrapper(void) |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
23 { |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
24 SDL_Quit(); |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
25 } |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
26 |
0 | 27 void printid(void) |
28 { | |
29 printf("Process %u: exiting\n", SDL_ThreadID()); | |
30 } | |
31 | |
32 void terminate(int sig) | |
33 { | |
34 printf("Process %u: raising SIGTERM\n", SDL_ThreadID()); | |
35 raise(SIGTERM); | |
36 } | |
37 void closemutex(int sig) | |
38 { | |
39 Uint32 id = SDL_ThreadID(); | |
40 int i; | |
41 printf("Process %u: Cleaning up...\n", id == mainthread ? 0 : id); | |
42 for ( i=0; i<6; ++i ) | |
43 SDL_KillThread(threads[i]); | |
44 SDL_DestroyMutex(mutex); | |
45 exit(sig); | |
46 } | |
47 int Run(void *data) | |
48 { | |
49 if ( SDL_ThreadID() == mainthread ) | |
50 signal(SIGTERM, closemutex); | |
51 while ( 1 ) { | |
52 printf("Process %u ready to work\n", SDL_ThreadID()); | |
53 if ( SDL_mutexP(mutex) < 0 ) { | |
54 fprintf(stderr, "Couldn't lock mutex: %s", SDL_GetError()); | |
55 exit(1); | |
56 } | |
57 printf("Process %u, working!\n", SDL_ThreadID()); | |
58 SDL_Delay(1*1000); | |
59 printf("Process %u, done!\n", SDL_ThreadID()); | |
60 if ( SDL_mutexV(mutex) < 0 ) { | |
61 fprintf(stderr, "Couldn't unlock mutex: %s", SDL_GetError()); | |
62 exit(1); | |
63 } | |
64 /* If this sleep isn't done, then threads may starve */ | |
65 SDL_Delay(10); | |
66 } | |
67 return(0); | |
68 } | |
69 | |
70 int main(int argc, char *argv[]) | |
71 { | |
72 int i; | |
73 int maxproc = 6; | |
74 | |
75 /* Load the SDL library */ | |
76 if ( SDL_Init(0) < 0 ) { | |
77 fprintf(stderr, "%s\n", SDL_GetError()); | |
78 exit(1); | |
79 } | |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
80 atexit(SDL_Quit_Wrapper); |
0 | 81 |
82 if ( (mutex=SDL_CreateMutex()) == NULL ) { | |
83 fprintf(stderr, "Couldn't create mutex: %s\n", SDL_GetError()); | |
84 exit(1); | |
85 } | |
86 | |
87 mainthread = SDL_ThreadID(); | |
88 printf("Main thread: %u\n", mainthread); | |
89 atexit(printid); | |
90 for ( i=0; i<maxproc; ++i ) { | |
91 if ( (threads[i]=SDL_CreateThread(Run, NULL)) == NULL ) | |
92 fprintf(stderr, "Couldn't create thread!\n"); | |
93 } | |
94 signal(SIGINT, terminate); | |
95 Run(NULL); | |
96 | |
97 return(0); /* Never reached */ | |
98 } |