Mercurial > sdl-ios-xcode
comparison test/testsem.c @ 5108:d547877e355e
Colin Leroy 2011-01-26 04:24:20 PST
the pthread implementation of SDL_SemWaitTimeout() uses busy waiting, while
pthread's sem_timedwait() does work. Attached are patches that make use of it
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 27 Jan 2011 00:34:12 -0800 |
parents | c121d94672cb |
children |
comparison
equal
deleted
inserted
replaced
5106:5fe0330b0fd6 | 5108:d547877e355e |
---|---|
35 | 35 |
36 static void | 36 static void |
37 killed(int sig) | 37 killed(int sig) |
38 { | 38 { |
39 alive = 0; | 39 alive = 0; |
40 } | |
41 | |
42 static void | |
43 TestWaitTimeout(void) | |
44 { | |
45 Uint32 start_ticks; | |
46 Uint32 end_ticks; | |
47 Uint32 duration; | |
48 | |
49 sem = SDL_CreateSemaphore(0); | |
50 printf("Waiting 2 seconds on semaphore\n"); | |
51 | |
52 start_ticks = SDL_GetTicks(); | |
53 SDL_SemWaitTimeout(sem, 2000); | |
54 end_ticks = SDL_GetTicks(); | |
55 | |
56 duration = end_ticks - start_ticks; | |
57 | |
58 /* Accept a little offset in the effective wait */ | |
59 if (duration > 1900 && duration < 2050) | |
60 printf("Wait done.\n"); | |
61 else | |
62 fprintf(stderr, "Wait took %d milliseconds\n", duration); | |
40 } | 63 } |
41 | 64 |
42 int | 65 int |
43 main(int argc, char **argv) | 66 main(int argc, char **argv) |
44 { | 67 { |
79 SDL_WaitThread(threads[i], NULL); | 102 SDL_WaitThread(threads[i], NULL); |
80 } | 103 } |
81 printf("Finished waiting for threads\n"); | 104 printf("Finished waiting for threads\n"); |
82 | 105 |
83 SDL_DestroySemaphore(sem); | 106 SDL_DestroySemaphore(sem); |
107 | |
108 TestWaitTimeout(); | |
109 | |
84 SDL_Quit(); | 110 SDL_Quit(); |
85 return (0); | 111 return (0); |
86 } | 112 } |