Mercurial > sdl-ios-xcode
annotate src/thread/linux/SDL_sysmutex.c @ 1133:609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
To: SDL Developers <sdl@libsdl.org>
From: =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb@algonet.se>
Date: Mon, 30 May 2005 23:29:04 +0200
Subject: [SDL] Mac OS X Video Drivers [patch]
I've updated/added the Carbon and X11 video drivers
to the Mac OS X port of SDL 1.2 (the CVS version),
and made the Cocoa driver and runtime *optional*.
The default is still Cocoa, and the "Quartz" driver.
But you can now also use "toolbox" for Carbon, and
"x11" for running with Apple's (or other) X11 server:
export SDL_VIDEODRIVER=x11
export SDL_VIDEO_GL_DRIVER=/usr/X11R6/lib/libGL.dylib
It also checks if the frameworks are available, by a:
#include <Carbon/Carbon.h> or #import <Cocoa/Cocoa.h>
(this should make it configure on plain Darwin as well?)
Here are the new configure targets:
--enable-video-cocoa use Cocoa/Quartz video driver default=yes
--enable-video-carbon use Carbon/QuickDraw video driver default=yes
--enable-video-x11 use X11 video driver default=no
./configure --enable-video-cocoa --enable-video-carbon
--enable-video-x11 \
--x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib
The Carbon version is just an updated version of the old
SDL driver for Mac OS 9, and could probably be improved...
(but it does work, including the Carbon version of SDLmain)
If you disable cocoa, you can run with -framework Carbon only,
and the C version of SDL_main.c. And if you disable carbon too,
you can still use the X11 version which doesn't require SDLmain.
I updated the DrawSprocket version, but did not include it.
(no blitters or VRAM GWorlds etc. available on OS X anyway)
Besides for Mac OS 9, I don't think there's any use for it ?
And note that any performance on Mac OS X equals OpenGL anyway...
You can get "fair" software SDL results on captured CG displays,
but for decent frame rates you need to be using GL for rendering.
Finally, here is the patch itself:
http://www.algonet.se/~afb/SDL-12CVS-macvideo.patch
--anders
PS. It says "video", but as usual it applies to mouse/keyboard too.
------
To: A list for developers using the SDL library <sdl@libsdl.org>
From: =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb@algonet.se>
Date: Sun, 4 Sep 2005 10:02:15 +0200
Subject: [SDL] Updated Mac patch
Updated the previous Mac patch to disable Carbon by default.
Also "fixed" the SDL.spec again, so that it builds on Darwin.
http://www.algonet.se/~afb/SDL-1.2.9-mac.patch
Also applied fine to SDL12 CVS, when I tried it.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Thu, 08 Sep 2005 06:16:14 +0000 |
parents | b8d311d90021 |
children | c9b51268668f |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
769
b8d311d90021
Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
3 Copyright (C) 1997-2004 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
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 | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 #ifdef linux | |
29 /* Look to see if glibc is available, and if so, what version */ | |
30 #include <features.h> | |
31 | |
32 #if (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0) | |
33 #warning Working around a bug in glibc 2.0 pthreads | |
34 #undef SDL_USE_PTHREADS | |
35 /* The bug is actually a problem where threads are suspended, but don't | |
36 wake up when the thread manager sends them a signal. This is a problem | |
37 with thread creation too, but it happens less often. :-/ | |
38 We avoid this by using System V IPC for mutexes. | |
39 */ | |
40 #endif /* glibc 2.0 */ | |
41 #endif /* linux */ | |
42 | |
43 #ifdef SDL_USE_PTHREADS | |
44 | |
45 #include <stdlib.h> | |
46 #include <stdio.h> | |
47 #include <pthread.h> | |
48 | |
49 #include "SDL_error.h" | |
50 #include "SDL_thread.h" | |
51 | |
52 | |
53 struct SDL_mutex { | |
54 pthread_mutex_t id; | |
55 #ifdef PTHREAD_NO_RECURSIVE_MUTEX | |
56 int recursive; | |
57 pthread_t owner; | |
58 #endif | |
59 }; | |
60 | |
61 SDL_mutex *SDL_CreateMutex (void) | |
62 { | |
63 SDL_mutex *mutex; | |
64 pthread_mutexattr_t attr; | |
65 | |
66 /* Allocate the structure */ | |
67 mutex = (SDL_mutex *)calloc(1, sizeof(*mutex)); | |
68 if ( mutex ) { | |
69 pthread_mutexattr_init(&attr); | |
70 #ifdef PTHREAD_NO_RECURSIVE_MUTEX | |
71 /* No extra attributes necessary */ | |
72 #else | |
73 #ifdef linux | |
74 pthread_mutexattr_setkind_np(&attr, PTHREAD_MUTEX_RECURSIVE_NP); | |
75 #else | |
76 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); | |
77 #endif | |
78 #endif /* PTHREAD_NO_RECURSIVE_MUTEX */ | |
79 if ( pthread_mutex_init(&mutex->id, &attr) != 0 ) { | |
80 SDL_SetError("pthread_mutex_init() failed"); | |
81 free(mutex); | |
82 mutex = NULL; | |
83 } | |
84 } else { | |
85 SDL_OutOfMemory(); | |
86 } | |
87 return(mutex); | |
88 } | |
89 | |
90 void SDL_DestroyMutex(SDL_mutex *mutex) | |
91 { | |
92 if ( mutex ) { | |
93 pthread_mutex_destroy(&mutex->id); | |
94 free(mutex); | |
95 } | |
96 } | |
97 | |
98 /* Lock the mutex */ | |
99 int SDL_mutexP(SDL_mutex *mutex) | |
100 { | |
101 int retval; | |
102 #ifdef PTHREAD_NO_RECURSIVE_MUTEX | |
103 pthread_t this_thread; | |
104 #endif | |
105 | |
106 if ( mutex == NULL ) { | |
107 SDL_SetError("Passed a NULL mutex"); | |
108 return -1; | |
109 } | |
110 | |
111 retval = 0; | |
112 #ifdef PTHREAD_NO_RECURSIVE_MUTEX | |
113 this_thread = pthread_self(); | |
114 if ( mutex->owner == this_thread ) { | |
115 ++mutex->recursive; | |
116 } else { | |
117 /* The order of operations is important. | |
118 We set the locking thread id after we obtain the lock | |
119 so unlocks from other threads will fail. | |
120 */ | |
121 if ( pthread_mutex_lock(&mutex->id) == 0 ) { | |
122 mutex->owner = this_thread; | |
123 mutex->recursive = 0; | |
124 } else { | |
125 SDL_SetError("pthread_mutex_lock() failed"); | |
126 retval = -1; | |
127 } | |
128 } | |
129 #else | |
130 if ( pthread_mutex_lock(&mutex->id) < 0 ) { | |
131 SDL_SetError("pthread_mutex_lock() failed"); | |
132 retval = -1; | |
133 } | |
134 #endif | |
135 return retval; | |
136 } | |
137 | |
138 int SDL_mutexV(SDL_mutex *mutex) | |
139 { | |
140 int retval; | |
141 | |
142 if ( mutex == NULL ) { | |
143 SDL_SetError("Passed a NULL mutex"); | |
144 return -1; | |
145 } | |
146 | |
147 retval = 0; | |
148 #ifdef PTHREAD_NO_RECURSIVE_MUTEX | |
149 /* We can only unlock the mutex if we own it */ | |
150 if ( pthread_self() == mutex->owner ) { | |
151 if ( mutex->recursive ) { | |
152 --mutex->recursive; | |
153 } else { | |
154 /* The order of operations is important. | |
155 First reset the owner so another thread doesn't lock | |
156 the mutex and set the ownership before we reset it, | |
157 then release the lock semaphore. | |
158 */ | |
159 mutex->owner = 0; | |
160 pthread_mutex_unlock(&mutex->id); | |
161 } | |
162 } else { | |
163 SDL_SetError("mutex not owned by this thread"); | |
164 retval = -1; | |
165 } | |
166 | |
167 #else | |
168 if ( pthread_mutex_unlock(&mutex->id) < 0 ) { | |
169 SDL_SetError("pthread_mutex_unlock() failed"); | |
170 retval = -1; | |
171 } | |
172 #endif /* PTHREAD_NO_RECURSIVE_MUTEX */ | |
173 | |
174 return retval; | |
175 } | |
176 | |
177 #else /* Use semaphore implementation */ | |
178 | |
179 #include "generic/SDL_sysmutex.c" | |
180 | |
181 #endif /* SDL_USE_PTHREADS */ |