Mercurial > sdl-ios-xcode
annotate test/testsem.c @ 1282:217f5d5a49e5
Date: Sat, 15 Jan 2005 02:01:51 +0000 (UTC)
From: jimrandomh
Subject: [SDL] Re: Modifier keys pressed during initialization stick
I wrote a simple test program which initializes SDL, prints the SDL
version number, then prints any keydown and keyup events with their
modifiers. (Source code below). Compilation was done using Visual
Studio 6, release mode.
My test sequence was:
Start a command prompt. Type the name of the test program.
shift down
enter down (program starts)
Wait for window to appear
enter up
shift up
spacebar down
spacebar up
Under Windows 98, the output was correct:
SDL 1.2.8
left shift down
shift-return down
shift-return up
left shift up
space down
space up
Under Windows 2000 and under Windows XP, the output was:
SDL 1.2.8
shift-space down
shift-space up
Since shift was not held at the time space was pressed, this is
incorrect. Similar results were observed with launching in different
ways (including double-clicking in Windows Explorer), so it does not
depend on the launching terminal.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 29 Jan 2006 07:57:13 +0000 |
parents | be9c9c8f6d53 |
children | 4d3bb026cd16 |
rev | line source |
---|---|
0 | 1 |
2 /* Simple test of the SDL semaphore code */ | |
3 | |
4 #include <stdio.h> | |
5 #include <stdlib.h> | |
6 #include <signal.h> | |
7 | |
8 #include "SDL.h" | |
9 #include "SDL_thread.h" | |
10 | |
11 #define NUM_THREADS 10 | |
12 | |
13 static SDL_sem *sem; | |
14 int alive = 1; | |
15 | |
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
|
16 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ |
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
|
17 static void quit(int rc) |
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(); |
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 exit(rc); |
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 |
0 | 23 int ThreadFunc(void *data) |
24 { | |
25 while ( alive ) { | |
26 SDL_SemWait(sem); | |
27 fprintf(stderr, "Thread number %d has got the semaphore (value = %d)!\n", (int)data, SDL_SemValue(sem)); | |
28 SDL_Delay(200); | |
29 SDL_SemPost(sem); | |
30 fprintf(stderr, "Thread number %d has released the semaphore (value = %d)!\n", (int)data, SDL_SemValue(sem)); | |
31 SDL_Delay(1); /* For the scheduler */ | |
32 } | |
33 printf("Thread number %d exiting.\n", (int)data); | |
34 return 0; | |
35 } | |
36 | |
37 static void killed(int sig) | |
38 { | |
39 alive = 0; | |
40 } | |
41 | |
42 int main(int argc, char **argv) | |
43 { | |
44 SDL_Thread *threads[NUM_THREADS]; | |
45 int i, init_sem; | |
46 | |
47 if(argc < 2) { | |
48 fprintf(stderr,"Usage: %s init_value\n", argv[0]); | |
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
|
49 return(1); |
0 | 50 } |
51 | |
52 /* Load the SDL library */ | |
53 if ( SDL_Init(0) < 0 ) { | |
54 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); | |
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
|
55 return(1); |
0 | 56 } |
57 signal(SIGTERM, killed); | |
58 signal(SIGINT, killed); | |
59 | |
60 init_sem = atoi(argv[1]); | |
61 sem = SDL_CreateSemaphore(init_sem); | |
62 | |
63 printf("Running %d threads, semaphore value = %d\n", NUM_THREADS, init_sem); | |
64 /* Create all the threads */ | |
65 for( i = 0; i < NUM_THREADS; ++i ) { | |
66 threads[i] = SDL_CreateThread(ThreadFunc, (void*)i); | |
67 } | |
68 | |
69 /* Wait 10 seconds */ | |
70 SDL_Delay(10 * 1000); | |
71 | |
72 /* Wait for all threads to finish */ | |
73 printf("Waiting for threads to finish\n"); | |
74 alive = 0; | |
75 for( i = 0; i < NUM_THREADS; ++i ) { | |
76 SDL_WaitThread(threads[i], NULL); | |
77 } | |
78 printf("Finished waiting for threads\n"); | |
79 | |
80 SDL_DestroySemaphore(sem); | |
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
|
81 SDL_Quit(); |
0 | 82 return(0); |
83 } |