Mercurial > sdl-ios-xcode
annotate test/testsem.c @ 1169:4b3e2294782d
Date: Sun, 06 Nov 2005 18:23:03 +0900
From: Hayashi Naoyuki <titan@culzean.org>
To: "A list for developers using the SDL library. \(includes SDL-announce\)" <sdl@libsdl.org>
Subject: Re: [SDL] Dynamic X11...
1. Compilation produce the following error on Tru64 UNIX.
cc: Severe: SDL_x11dyn.h, line 31: Cannot find file
<X11/extensions/extutil.h> specified in #include directive. (noinclfilef)
#include <X11/extensions/extutil.h>
Because Tru64 UNIX doesn't have extutil.h, this error is caused.
2. Compilation with --enable-x11-shared=no produce the following error.
cc: Error: SDL_x11sym.h, line 115: In this statement,
"Xutf8TextListToTextProperty" is not declared. (undeclared)
SDL_X11_SYM(int,Xutf8TextListToTextProperty,(Display*,char**,int,XICCEncodingStyle,XTextProperty*))
Though it doesn't have Xutf8TextListToTextProperty,
"pXutf8TextListToTextProperty = Xutf8TextListToTextProperty;"
in SDL_x11dyn.c,117-119
#define SDL_X11_SYM(r,fn,arg) p##fn = fn;
#include "SDL_x11sym.h"
#undef SDL_X11_SYM
-- Hayashi Naoyuki Key fingerprint = 60A0 D5D3 F58B 3633 2E52 0147 D17F 5578 3FDF F5B6
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sun, 06 Nov 2005 17:05:12 +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 } |