Mercurial > sdl-ios-xcode
annotate src/thread/amigaos/SDL_syssem.c @ 1551:02e19471a694
Fixed bug #4
[Note: I'm applying this patch since it's a cleaner version of what's already implemented, and supports this controller on older kernels. I'll ask to make sure this doesn't break on the new kernels where it's no longer necessary]
Date: Mon, 21 Mar 2005 09:41:11 -0500
From: Chris Nelson
Subject: SDL Patch
Hey, Ryan.
I submitted the following patch about a year ago. It's just a simple
patch for the linux port, to make multiple joysticks each appear to SDL
as their own device, if they are on the same USB port (specifically,
these guys
<http://www.consoleplus.co.uk/product_info.php?pName=super-joybox-5-quad-joypad-converter>,
which allow 4 Playstation2 controllers to be accessed via a single USB
port). Without this patch, SDL pretty much drops the ball, and reports
that there are 4 joysticks available when less than that number are
plugged in.
My work built upon the work of another person with the same device. When
I submitted the patch to the list, he tested it, but it didn't work for
him, so the patch was never accepted. Maybe about 3 times in the past
year, I've tried to email the guy, to see if he couldn't run my new
version, complete with debug code to diagnose the problem he was having.
He never got back to me.
So, I'm attaching the patch. I wish I knew why it didn't work for him,
but I've been using it for the last year with no problems. Let me know
if you need any more information, or have any ideas as to how I could
test it. I'd like to see it in the tree, but I want to make sure it works.
-Chris
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 19 Mar 2006 06:31:34 +0000 |
parents | d910939febfa |
children | 782fd950bd46 c121d94672cb |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
24 /* An implementation of semaphores using mutexes and condition variables */ |
0 | 25 |
26 #include "SDL_thread.h" | |
27 #include "SDL_systhread_c.h" | |
28 | |
29 | |
30 struct SDL_semaphore | |
31 { | |
32 struct SignalSemaphore Sem; | |
33 }; | |
34 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
35 #undef D |
0 | 36 |
37 #define D(x) | |
38 | |
39 SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) | |
40 { | |
41 SDL_sem *sem; | |
42 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
43 sem = (SDL_sem *)SDL_malloc(sizeof(*sem)); |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
44 |
0 | 45 if ( ! sem ) { |
46 SDL_OutOfMemory(); | |
47 return(0); | |
48 } | |
49 | |
50 D(bug("Creating semaphore %lx...\n",sem)); | |
51 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
52 SDL_memset(sem,0,sizeof(*sem)); |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
53 |
0 | 54 InitSemaphore(&sem->Sem); |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
55 |
0 | 56 return(sem); |
57 } | |
58 | |
59 void SDL_DestroySemaphore(SDL_sem *sem) | |
60 { | |
61 D(bug("Destroying semaphore %lx...\n",sem)); | |
62 | |
63 if ( sem ) { | |
64 // Condizioni per liberare i task in attesa? | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
65 SDL_free(sem); |
0 | 66 } |
67 } | |
68 | |
69 int SDL_SemTryWait(SDL_sem *sem) | |
70 { | |
71 if ( ! sem ) { | |
72 SDL_SetError("Passed a NULL semaphore"); | |
73 return -1; | |
74 } | |
75 | |
76 D(bug("TryWait semaphore...%lx\n",sem)); | |
77 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
78 ObtainSemaphore(&sem->Sem); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
79 // ReleaseSemaphore(&sem->Sem); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
80 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
81 return 1; |
0 | 82 } |
83 | |
84 int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) | |
85 { | |
86 int retval; | |
87 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
88 |
0 | 89 if ( ! sem ) { |
90 SDL_SetError("Passed a NULL semaphore"); | |
91 return -1; | |
92 } | |
93 | |
94 D(bug("WaitTimeout (%ld) semaphore...%lx\n",timeout,sem)); | |
95 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
96 /* A timeout of 0 is an easy case */ |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
97 if ( timeout == 0 ) { |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
98 ObtainSemaphore(&sem->Sem); |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
99 return 1; |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
100 } |
0 | 101 if(!(retval=AttemptSemaphore(&sem->Sem))) |
102 { | |
103 SDL_Delay(timeout); | |
104 retval=AttemptSemaphore(&sem->Sem); | |
105 } | |
106 | |
107 if(retval==TRUE) | |
108 { | |
109 // ReleaseSemaphore(&sem->Sem); | |
110 retval=1; | |
111 } | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
112 |
0 | 113 return retval; |
114 } | |
115 | |
116 int SDL_SemWait(SDL_sem *sem) | |
117 { | |
118 ObtainSemaphore(&sem->Sem); | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
119 return 0; |
0 | 120 } |
121 | |
122 Uint32 SDL_SemValue(SDL_sem *sem) | |
123 { | |
124 Uint32 value; | |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
125 |
0 | 126 value = 0; |
127 if ( sem ) { | |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
128 #ifdef STORMC4_WOS |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
129 value = sem->Sem.ssppc_SS.ss_NestCount; |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
130 #else |
0 | 131 value = sem->Sem.ss_NestCount; |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
132 #endif |
0 | 133 } |
134 return value; | |
135 } | |
136 | |
137 int SDL_SemPost(SDL_sem *sem) | |
138 { | |
139 if ( ! sem ) { | |
140 SDL_SetError("Passed a NULL semaphore"); | |
141 return -1; | |
142 } | |
143 D(bug("SemPost semaphore...%lx\n",sem)); | |
144 | |
145 ReleaseSemaphore(&sem->Sem); | |
146 return 0; | |
147 } | |
148 |