Mercurial > sdl-ios-xcode
annotate src/thread/pth/SDL_syscond.c @ 4384:6800e2560310 SDL-1.2
Fixed bugs #882 and 865, re-opening bug #634
Ronald Lamprecht to SDL
Hi,
Sam Lantinga wrote:
The problem with that fix is that it breaks IME events again. Maybe
we can handle keyboard events differently to prevent this issue?
Spending an hour reading MSDN, analysing SDL and another hour testing the reality on XP I am really wondering how patch r4990 could have ever worked in any situation. It's main effect is to break the unicode translation and causing spurious activation events!
Why does TranslateMessage(&msg) nothing useful? Simply because it does not affect "msg" at all! All keyboard events are dispatched without the slightest change (see MSDN). TranslateMessage() just appends additional WM_CHAR, WM_DEADCHAR, WM_SYSCHAR, WM_SYSDEADCHAR event messages to the queue. But I could not find any SDL event handling routine that catches these events and transforms them to proper SDL keyevents while eliminating the corresponding WM_KEYDOWN, etc. events. Thus any IME input like the '@' generated by "Alt + 6(Numpad) + 4(Numpad)" is simply lost.
But the situation is even worse! Up to r4990 the TranslateKey()/ToUnicode() calls did evaluate dead keys and did deliver proper key events for subsequent key strokes like '´' + 'e' resulting in 'é'. ToUnicode() needs proper key state informations to be able to handle these substitutions. But unfortunatly TranslateMessage() needs the same state information and eats it up while generating the WM_CHAR messages :-( Thus the current 1.2.14 breakes the partial IME support of previous releases, too.
The key state race condition between ToUnicode() and TranslateMessage() requires to avoid any ToUnicode() usage for receiving proper WM_CHAR, etc. messages generated by TranslateMessage(). (Yes - the '@' and 'é' appear as WM_CHAR messages when unicode is switched off).
The spurious SDL activation events are *not* caused by additional WM_ACTIVATE Windows messages! Besides DIB_HandleMessage() SDL_PrivateAppActive() is called by another source which I am not yet aware of - any hints?
Thus I do strongly recommend the deletion of the TranslateMessage(&msg) call as a quick fix.
A proper support of unicode and IME requires a clean SDL keyboard input concept first. Which SDL keyboards events should be transmitted to the app when the user presses '´' + 'e' ? Within the current unicode handling the first key stroke is hidden. Even though ToUnicode() delivers the proper key SDL does ignore it in TranslateKey(). Just the composed key event is transmitted to the app. That is what you expect for text input, but the app can no longer use keys like '^' as a key button because it will never receive a key event for it!
With a given concept it seems to be necessary to regenerate SDL key events out of the WM_CHAR, etc. events and to drop all related direct WM_KEYDOWN, etc. events while the remaining basic WM_KEYDOWN, etc. events would still have to result in SDL key events.
Anyway the source of the spurious WM_ACTIVATE should be located to avoid future trouble.
Greets,
Ronald
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 17 Nov 2009 04:59:13 +0000 |
parents | a1b03ba2fcd0 |
children |
rev | line source |
---|---|
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
1 /* |
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
4159 | 3 Copyright (C) 1997-2009 Sam Lantinga |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
4 |
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
7 License as published by the Free Software Foundation; either |
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
9 |
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
13 Lesser General Public License for more details. |
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
14 |
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
18 |
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
19 Sam Lantinga |
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
20 slouken@libsdl.org |
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
21 */ |
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
22 #include "SDL_config.h" |
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
23 |
329
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 /* |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 * GNU pth conditions variables |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 * |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 * Patrice Mandin |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 */ |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 #include <pth.h> |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 #include "SDL_thread.h" |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 #include "SDL_sysmutex_c.h" |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
35 struct SDL_cond |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
36 { |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
37 pth_cond_t condpth_p; |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
38 }; |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
39 |
329
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 /* Create a condition variable */ |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 SDL_cond * SDL_CreateCond(void) |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 SDL_cond *cond; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
329
diff
changeset
|
45 cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond)); |
329
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 if ( cond ) { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 if ( pth_cond_init(&(cond->condpth_p)) < 0 ) { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 SDL_SetError("pthread_cond_init() failed"); |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
329
diff
changeset
|
49 SDL_free(cond); |
329
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 cond = NULL; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 } |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 } else { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 SDL_OutOfMemory(); |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 } |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 return(cond); |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 } |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 /* Destroy a condition variable */ |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 void SDL_DestroyCond(SDL_cond *cond) |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 if ( cond ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
329
diff
changeset
|
62 SDL_free(cond); |
329
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 } |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 } |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 /* Restart one of the threads that are waiting on the condition variable */ |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 int SDL_CondSignal(SDL_cond *cond) |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 int retval; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 if ( ! cond ) { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 SDL_SetError("Passed a NULL condition variable"); |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 return -1; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 } |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 retval = 0; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 if ( pth_cond_notify(&(cond->condpth_p), FALSE) != 0 ) { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 SDL_SetError("pth_cond_notify() failed"); |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 retval = -1; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 } |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 return retval; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 } |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 /* Restart all threads that are waiting on the condition variable */ |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 int SDL_CondBroadcast(SDL_cond *cond) |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 int retval; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 if ( ! cond ) { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 SDL_SetError("Passed a NULL condition variable"); |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 return -1; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 } |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 retval = 0; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 if ( pth_cond_notify(&(cond->condpth_p), TRUE) != 0 ) { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 SDL_SetError("pth_cond_notify() failed"); |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
97 retval = -1; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 } |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 return retval; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 } |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 /* Wait on the condition variable for at most 'ms' milliseconds. |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 The mutex must be locked before entering this function! |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 The mutex is unlocked during the wait, and locked again after the wait. |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 Typical use: |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 Thread A: |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 SDL_LockMutex(lock); |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 while ( ! condition ) { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 SDL_CondWait(cond); |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 } |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 SDL_UnlockMutex(lock); |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 Thread B: |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 SDL_LockMutex(lock); |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 ... |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 condition = true; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 ... |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 SDL_UnlockMutex(lock); |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 */ |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms) |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 int retval; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
125 pth_event_t ev; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
126 int sec; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
127 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 if ( ! cond ) { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 SDL_SetError("Passed a NULL condition variable"); |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 return -1; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 } |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
133 retval = 0; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 sec = ms/1000; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 ev = pth_event(PTH_EVENT_TIME, pth_timeout(sec,(ms-sec*1000)*1000)); |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 if ( pth_cond_await(&(cond->condpth_p), &(mutex->mutexpth_p), ev) != 0 ) { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 SDL_SetError("pth_cond_await() failed"); |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 retval = -1; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
141 } |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 pth_event_free(ev, PTH_FREE_ALL); |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 return retval; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 } |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 /* Wait on the condition variable forever */ |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 int SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex) |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 int retval; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 if ( ! cond ) { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
154 SDL_SetError("Passed a NULL condition variable"); |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 return -1; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
156 } |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 retval = 0; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 if ( pth_cond_await(&(cond->condpth_p), &(mutex->mutexpth_p), NULL) != 0 ) { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
160 SDL_SetError("pth_cond_await() failed"); |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
161 retval = -1; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 } |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 return retval; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 } |