ruby-glfw 0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -0
- data/README.API +73 -0
- data/Rakefile +120 -0
- data/examples/boing.rb +519 -0
- data/examples/gears.rb +327 -0
- data/examples/keytest.rb +117 -0
- data/examples/listmodes.rb +20 -0
- data/examples/mipmaps.rb +104 -0
- data/examples/mipmaps.tga +0 -0
- data/examples/particles.rb +837 -0
- data/examples/pong3d.rb +741 -0
- data/examples/pong3d_field.tga +0 -0
- data/examples/pong3d_instr.tga +0 -0
- data/examples/pong3d_menu.tga +0 -0
- data/examples/pong3d_title.tga +0 -0
- data/examples/pong3d_winner1.tga +0 -0
- data/examples/pong3d_winner2.tga +0 -0
- data/examples/splitview.rb +432 -0
- data/examples/triangle.rb +89 -0
- data/examples/wave.rb +294 -0
- data/ext/glfw/glfw.c +1094 -0
- data/ext/glfw/mkrf_conf.rb +70 -0
- data/glfw-src/Makefile +220 -0
- data/glfw-src/compile.ami +61 -0
- data/glfw-src/compile.bat +217 -0
- data/glfw-src/compile.sh +607 -0
- data/glfw-src/docs/Makefile +57 -0
- data/glfw-src/docs/Reference.pdf +0 -0
- data/glfw-src/docs/UsersGuide.pdf +0 -0
- data/glfw-src/docs/cleanup.bat +22 -0
- data/glfw-src/docs/glfwdoc.sty +80 -0
- data/glfw-src/docs/glfwrm.tex +3034 -0
- data/glfw-src/docs/glfwug.tex +2024 -0
- data/glfw-src/docs/readme.txt +80 -0
- data/glfw-src/examples/Makefile.amigaos.gcc +70 -0
- data/glfw-src/examples/Makefile.amigaos.vbcc +70 -0
- data/glfw-src/examples/Makefile.dos.djgpp +71 -0
- data/glfw-src/examples/Makefile.macosx.gcc +96 -0
- data/glfw-src/examples/Makefile.win32.bcc +75 -0
- data/glfw-src/examples/Makefile.win32.cross-mgw +79 -0
- data/glfw-src/examples/Makefile.win32.cygwin +79 -0
- data/glfw-src/examples/Makefile.win32.lcc +74 -0
- data/glfw-src/examples/Makefile.win32.mgw +75 -0
- data/glfw-src/examples/Makefile.win32.msvc +74 -0
- data/glfw-src/examples/Makefile.win32.ow +74 -0
- data/glfw-src/examples/Makefile.win32.pellesc +74 -0
- data/glfw-src/examples/Makefile.x11.in +54 -0
- data/glfw-src/examples/boing.c +606 -0
- data/glfw-src/examples/bundle.sh +46 -0
- data/glfw-src/examples/gears.c +382 -0
- data/glfw-src/examples/keytest.c +264 -0
- data/glfw-src/examples/listmodes.c +48 -0
- data/glfw-src/examples/mipmaps.c +126 -0
- data/glfw-src/examples/mipmaps.tga +0 -0
- data/glfw-src/examples/mtbench.c +301 -0
- data/glfw-src/examples/mthello.c +48 -0
- data/glfw-src/examples/particles.c +1148 -0
- data/glfw-src/examples/pong3d.c +839 -0
- data/glfw-src/examples/pong3d_field.tga +0 -0
- data/glfw-src/examples/pong3d_instr.tga +0 -0
- data/glfw-src/examples/pong3d_menu.tga +0 -0
- data/glfw-src/examples/pong3d_title.tga +0 -0
- data/glfw-src/examples/pong3d_winner1.tga +0 -0
- data/glfw-src/examples/pong3d_winner2.tga +0 -0
- data/glfw-src/examples/splitview.c +506 -0
- data/glfw-src/examples/triangle.c +108 -0
- data/glfw-src/examples/wave.c +397 -0
- data/glfw-src/images/opengl.gif +0 -0
- data/glfw-src/images/osicert.gif +0 -0
- data/glfw-src/include/GL/glfw.h +486 -0
- data/glfw-src/lib/amigaos/Makefile.amigaos.gcc +128 -0
- data/glfw-src/lib/amigaos/Makefile.amigaos.vbcc +128 -0
- data/glfw-src/lib/amigaos/SDI_compiler.h +94 -0
- data/glfw-src/lib/amigaos/amigaos_enable.c +51 -0
- data/glfw-src/lib/amigaos/amigaos_fullscreen.c +319 -0
- data/glfw-src/lib/amigaos/amigaos_glext.c +61 -0
- data/glfw-src/lib/amigaos/amigaos_init.c +284 -0
- data/glfw-src/lib/amigaos/amigaos_joystick.c +359 -0
- data/glfw-src/lib/amigaos/amigaos_thread.c +494 -0
- data/glfw-src/lib/amigaos/amigaos_time.c +206 -0
- data/glfw-src/lib/amigaos/amigaos_window.c +830 -0
- data/glfw-src/lib/amigaos/platform.h +337 -0
- data/glfw-src/lib/dos/Makefile.dos.djgpp +146 -0
- data/glfw-src/lib/dos/dos_enable.c +51 -0
- data/glfw-src/lib/dos/dos_events.c +173 -0
- data/glfw-src/lib/dos/dos_fullscreen.c +101 -0
- data/glfw-src/lib/dos/dos_glext.c +59 -0
- data/glfw-src/lib/dos/dos_init.c +105 -0
- data/glfw-src/lib/dos/dos_irq.s +246 -0
- data/glfw-src/lib/dos/dos_joystick.c +94 -0
- data/glfw-src/lib/dos/dos_keyboard.c +694 -0
- data/glfw-src/lib/dos/dos_mouse.c +337 -0
- data/glfw-src/lib/dos/dos_thread.c +267 -0
- data/glfw-src/lib/dos/dos_time.c +309 -0
- data/glfw-src/lib/dos/dos_window.c +563 -0
- data/glfw-src/lib/dos/platform.h +341 -0
- data/glfw-src/lib/enable.c +295 -0
- data/glfw-src/lib/fullscreen.c +95 -0
- data/glfw-src/lib/glext.c +201 -0
- data/glfw-src/lib/image.c +629 -0
- data/glfw-src/lib/init.c +108 -0
- data/glfw-src/lib/input.c +280 -0
- data/glfw-src/lib/internal.h +210 -0
- data/glfw-src/lib/joystick.c +101 -0
- data/glfw-src/lib/macosx/Makefile.macosx.gcc +172 -0
- data/glfw-src/lib/macosx/Makefile.macosx.gcc.universal +166 -0
- data/glfw-src/lib/macosx/libglfw.pc.in +11 -0
- data/glfw-src/lib/macosx/macosx_enable.c +42 -0
- data/glfw-src/lib/macosx/macosx_fullscreen.c +126 -0
- data/glfw-src/lib/macosx/macosx_glext.c +52 -0
- data/glfw-src/lib/macosx/macosx_init.c +194 -0
- data/glfw-src/lib/macosx/macosx_joystick.c +50 -0
- data/glfw-src/lib/macosx/macosx_thread.c +414 -0
- data/glfw-src/lib/macosx/macosx_time.c +112 -0
- data/glfw-src/lib/macosx/macosx_window.c +1279 -0
- data/glfw-src/lib/macosx/platform.h +349 -0
- data/glfw-src/lib/stream.c +194 -0
- data/glfw-src/lib/tga.c +405 -0
- data/glfw-src/lib/thread.c +340 -0
- data/glfw-src/lib/time.c +83 -0
- data/glfw-src/lib/win32/Makefile.win32.bcc +265 -0
- data/glfw-src/lib/win32/Makefile.win32.cross-mgw +274 -0
- data/glfw-src/lib/win32/Makefile.win32.cygwin +279 -0
- data/glfw-src/lib/win32/Makefile.win32.lcc +246 -0
- data/glfw-src/lib/win32/Makefile.win32.mgw +243 -0
- data/glfw-src/lib/win32/Makefile.win32.msvc +242 -0
- data/glfw-src/lib/win32/Makefile.win32.ow +242 -0
- data/glfw-src/lib/win32/Makefile.win32.pellesc +242 -0
- data/glfw-src/lib/win32/glfwdll.def +67 -0
- data/glfw-src/lib/win32/glfwdll_mgw1.def +67 -0
- data/glfw-src/lib/win32/glfwdll_mgw2.def +67 -0
- data/glfw-src/lib/win32/glfwdll_pellesc.def +65 -0
- data/glfw-src/lib/win32/libglfw.pc.in +11 -0
- data/glfw-src/lib/win32/platform.h +474 -0
- data/glfw-src/lib/win32/win32_dllmain.c +60 -0
- data/glfw-src/lib/win32/win32_enable.c +155 -0
- data/glfw-src/lib/win32/win32_fullscreen.c +317 -0
- data/glfw-src/lib/win32/win32_glext.c +85 -0
- data/glfw-src/lib/win32/win32_init.c +356 -0
- data/glfw-src/lib/win32/win32_joystick.c +234 -0
- data/glfw-src/lib/win32/win32_thread.c +511 -0
- data/glfw-src/lib/win32/win32_time.c +146 -0
- data/glfw-src/lib/win32/win32_window.c +1714 -0
- data/glfw-src/lib/window.c +727 -0
- data/glfw-src/lib/x11/Makefile.x11.in +243 -0
- data/glfw-src/lib/x11/platform.h +415 -0
- data/glfw-src/lib/x11/x11_enable.c +51 -0
- data/glfw-src/lib/x11/x11_fullscreen.c +524 -0
- data/glfw-src/lib/x11/x11_glext.c +69 -0
- data/glfw-src/lib/x11/x11_init.c +275 -0
- data/glfw-src/lib/x11/x11_joystick.c +371 -0
- data/glfw-src/lib/x11/x11_keysym2unicode.c +902 -0
- data/glfw-src/lib/x11/x11_thread.c +507 -0
- data/glfw-src/lib/x11/x11_time.c +154 -0
- data/glfw-src/lib/x11/x11_window.c +1746 -0
- data/glfw-src/license.txt +21 -0
- data/glfw-src/readme.html +927 -0
- data/glfw-src/support/d/examples/Makefile +59 -0
- data/glfw-src/support/d/examples/boing.d +610 -0
- data/glfw-src/support/d/examples/gears.d +379 -0
- data/glfw-src/support/d/examples/keytest.d +272 -0
- data/glfw-src/support/d/examples/listmodes.d +48 -0
- data/glfw-src/support/d/examples/mipmaps.d +126 -0
- data/glfw-src/support/d/examples/mtbench.d +304 -0
- data/glfw-src/support/d/examples/mthello.d +54 -0
- data/glfw-src/support/d/examples/particles.d +1150 -0
- data/glfw-src/support/d/examples/pong3d.d +840 -0
- data/glfw-src/support/d/examples/splitview.d +486 -0
- data/glfw-src/support/d/examples/triangle.d +108 -0
- data/glfw-src/support/d/examples/wave.d +400 -0
- data/glfw-src/support/d/imports/gl.d +4539 -0
- data/glfw-src/support/d/imports/glfw.d +349 -0
- data/glfw-src/support/d/imports/glu.d +328 -0
- data/glfw-src/support/d/lib/glfwdll.def +64 -0
- data/glfw-src/support/d/lib/glu32.def +56 -0
- data/glfw-src/support/d/lib/makefile +12 -0
- data/glfw-src/support/d/lib/opengl32.def +372 -0
- data/glfw-src/support/d/readme.html +83 -0
- data/glfw-src/support/delphi/examples/Triangle.dpr +105 -0
- data/glfw-src/support/delphi/lib/glfw.pas +437 -0
- data/glfw-src/support/delphi/readme.html +97 -0
- data/glfw-src/support/lua/examples/gears.lua +383 -0
- data/glfw-src/support/lua/examples/test1.lua +68 -0
- data/glfw-src/support/lua/readme.html +128 -0
- data/glfw-src/support/lua/src/luaglfw.c +1179 -0
- data/glfw-src/support/lua/src/luaglfw.h +48 -0
- data/glfw-src/support/lua/src/runlua.c +82 -0
- data/glfw-src/support/masm/examples/fpc.mac +47 -0
- data/glfw-src/support/masm/examples/makeit.bat +66 -0
- data/glfw-src/support/masm/examples/triangle.asm +232 -0
- data/glfw-src/support/masm/include/glfw.inc +326 -0
- data/glfw-src/support/masm/include/glu32.inc +55 -0
- data/glfw-src/support/masm/include/opengl32.inc +372 -0
- data/glfw-src/support/masm/lib/glfwdll.lib +0 -0
- data/glfw-src/support/masm/readme.html +170 -0
- data/glfw-src/support/msvc80/GLFW.sln +26 -0
- data/glfw-src/support/msvc80/GLFW.vcproj +257 -0
- data/glfw-src/support/msvc80/GLFWDLL.vcproj +287 -0
- data/glfw-src/support/visualbasic/bindings/glfw.bas +320 -0
- data/glfw-src/support/visualbasic/bindings/glu32.bas +284 -0
- data/glfw-src/support/visualbasic/bindings/opengl32.bas +999 -0
- data/glfw-src/support/visualbasic/examples/Triangle.bas +101 -0
- data/glfw-src/support/visualbasic/readme.html +164 -0
- data/website/index.html +84 -0
- data/website/style.css +110 -0
- metadata +301 -0
@@ -0,0 +1,494 @@
|
|
1
|
+
//========================================================================
|
2
|
+
// GLFW - An OpenGL framework
|
3
|
+
// File: amigaos_thread.c
|
4
|
+
// Platforms: AmigaOS, MorphOS
|
5
|
+
// API version: 2.6
|
6
|
+
// WWW: http://glfw.sourceforge.net
|
7
|
+
//------------------------------------------------------------------------
|
8
|
+
// Copyright (c) 2002-2006 Camilla Berglund
|
9
|
+
//
|
10
|
+
// This software is provided 'as-is', without any express or implied
|
11
|
+
// warranty. In no event will the authors be held liable for any damages
|
12
|
+
// arising from the use of this software.
|
13
|
+
//
|
14
|
+
// Permission is granted to anyone to use this software for any purpose,
|
15
|
+
// including commercial applications, and to alter it and redistribute it
|
16
|
+
// freely, subject to the following restrictions:
|
17
|
+
//
|
18
|
+
// 1. The origin of this software must not be misrepresented; you must not
|
19
|
+
// claim that you wrote the original software. If you use this software
|
20
|
+
// in a product, an acknowledgment in the product documentation would
|
21
|
+
// be appreciated but is not required.
|
22
|
+
//
|
23
|
+
// 2. Altered source versions must be plainly marked as such, and must not
|
24
|
+
// be misrepresented as being the original software.
|
25
|
+
//
|
26
|
+
// 3. This notice may not be removed or altered from any source
|
27
|
+
// distribution.
|
28
|
+
//
|
29
|
+
//========================================================================
|
30
|
+
|
31
|
+
#include "internal.h"
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
//************************************************************************
|
36
|
+
//**** GLFW internal functions ****
|
37
|
+
//************************************************************************
|
38
|
+
|
39
|
+
//========================================================================
|
40
|
+
// _glfwNewThread() - This is simply a "wrapper" for calling the user
|
41
|
+
// thread function.
|
42
|
+
//========================================================================
|
43
|
+
|
44
|
+
int _glfwNewThread( void )
|
45
|
+
{
|
46
|
+
GLFWthreadfun threadfun;
|
47
|
+
void *arg;
|
48
|
+
_GLFWthread *t, *t_wait;
|
49
|
+
struct Task *amiTask;
|
50
|
+
int waitSig;
|
51
|
+
|
52
|
+
// Allocate a signal to use for waiting (glfwWaitThread and
|
53
|
+
// glfwWaitCond)
|
54
|
+
waitSig = AllocSignal( -1 );
|
55
|
+
if( waitSig == -1 )
|
56
|
+
{
|
57
|
+
// If we could not get a signal (VERY UNLIKELY), exit immediately
|
58
|
+
return 0;
|
59
|
+
}
|
60
|
+
|
61
|
+
// Get current task
|
62
|
+
amiTask = FindTask( NULL );
|
63
|
+
|
64
|
+
// Enter critical section
|
65
|
+
ENTER_THREAD_CRITICAL_SECTION
|
66
|
+
|
67
|
+
// The task's user data points to the GLFW thread struct
|
68
|
+
t = (_GLFWthread *) amiTask->tc_UserData;
|
69
|
+
|
70
|
+
// Store wait signal handle
|
71
|
+
t->WaitSig = waitSig;
|
72
|
+
t->WaitFor = NULL;
|
73
|
+
|
74
|
+
// Get user thread function pointer and argument
|
75
|
+
threadfun = t->Function;
|
76
|
+
arg = t->Arg;
|
77
|
+
|
78
|
+
// Leave critical section
|
79
|
+
LEAVE_THREAD_CRITICAL_SECTION
|
80
|
+
|
81
|
+
// Call the user thread function
|
82
|
+
threadfun( arg );
|
83
|
+
|
84
|
+
ENTER_THREAD_CRITICAL_SECTION
|
85
|
+
|
86
|
+
// Remove thread from thread list
|
87
|
+
_glfwRemoveThread( t );
|
88
|
+
|
89
|
+
// Signal any waiting threads that we have died
|
90
|
+
for( t_wait = &_glfwThrd.First; t_wait; t_wait = t_wait->Next )
|
91
|
+
{
|
92
|
+
if( t_wait->WaitFor == (void *) t )
|
93
|
+
{
|
94
|
+
Signal( t_wait->AmiTask, 1L<<t_wait->WaitSig );
|
95
|
+
t_wait->WaitFor = NULL;
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
LEAVE_THREAD_CRITICAL_SECTION
|
100
|
+
|
101
|
+
// When the process function returns, the process will die...
|
102
|
+
return 0;
|
103
|
+
}
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
//************************************************************************
|
108
|
+
//**** Platform implementation functions ****
|
109
|
+
//************************************************************************
|
110
|
+
|
111
|
+
//========================================================================
|
112
|
+
// _glfwPlatformCreateThread() - Create a new thread
|
113
|
+
//========================================================================
|
114
|
+
|
115
|
+
GLFWthread _glfwPlatformCreateThread( GLFWthreadfun fun, void *arg )
|
116
|
+
{
|
117
|
+
GLFWthread ID;
|
118
|
+
_GLFWthread *t;
|
119
|
+
struct TagItem tagList[ 10 ];
|
120
|
+
int tagNR;
|
121
|
+
|
122
|
+
|
123
|
+
// Enter critical section
|
124
|
+
ENTER_THREAD_CRITICAL_SECTION
|
125
|
+
|
126
|
+
// Create a new thread information memory area
|
127
|
+
t = (_GLFWthread *) malloc( sizeof(_GLFWthread) );
|
128
|
+
if( t == NULL )
|
129
|
+
{
|
130
|
+
// Leave critical section
|
131
|
+
LEAVE_THREAD_CRITICAL_SECTION
|
132
|
+
return -1;
|
133
|
+
}
|
134
|
+
|
135
|
+
// Get a new unique thread id
|
136
|
+
ID = _glfwThrd.NextID ++;
|
137
|
+
|
138
|
+
// Store thread information in the thread list
|
139
|
+
t->ID = ID;
|
140
|
+
t->Function = fun;
|
141
|
+
t->Arg = arg;
|
142
|
+
|
143
|
+
#ifdef _GLFW_MORPHOS
|
144
|
+
// For MorphOS, we set up a 68k -> PPC switch trap instruction.
|
145
|
+
// CreateNewProc actually creates a 68k process (emulated), so we make
|
146
|
+
// sure that the first 68k instruction that is executed is a trap
|
147
|
+
// instruction that forces the execution model to change from emulated
|
148
|
+
// 68k to native PPC (and starts execution at _glfwNewThread).
|
149
|
+
t->mosEmulLibEntry.Trap = TRAP_LIB;
|
150
|
+
t->mosEmulLibEntry.Extension = 0;
|
151
|
+
t->mosEmulLibEntry.Func = _glfwNewThread;
|
152
|
+
#endif
|
153
|
+
|
154
|
+
// Create new process
|
155
|
+
tagNR = 0;
|
156
|
+
tagList[ tagNR ].ti_Tag = NP_Entry;
|
157
|
+
#ifdef _GLFW_MORPHOS
|
158
|
+
tagList[ tagNR++ ].ti_Data = (ULONG) &t->mosEmulLibEntry;
|
159
|
+
#else
|
160
|
+
tagList[ tagNR++ ].ti_Data = (ULONG) _glfwNewThread;
|
161
|
+
#endif
|
162
|
+
tagList[ tagNR ].ti_Tag = NP_StackSize;
|
163
|
+
tagList[ tagNR++ ].ti_Data = _GLFW_TASK_STACK_SIZE;
|
164
|
+
tagList[ tagNR ].ti_Tag = NP_Input;
|
165
|
+
tagList[ tagNR++ ].ti_Data = (ULONG) Input();
|
166
|
+
tagList[ tagNR ].ti_Tag = NP_Output;
|
167
|
+
tagList[ tagNR++ ].ti_Data = (ULONG) Output();
|
168
|
+
tagList[ tagNR ].ti_Tag = NP_CloseInput;
|
169
|
+
tagList[ tagNR++ ].ti_Data = FALSE;
|
170
|
+
tagList[ tagNR ].ti_Tag = NP_CloseOutput;
|
171
|
+
tagList[ tagNR++ ].ti_Data = FALSE;
|
172
|
+
tagList[ tagNR ].ti_Tag = TAG_DONE;
|
173
|
+
t->AmiProc = CreateNewProc( tagList );
|
174
|
+
|
175
|
+
// Did the process creation fail?
|
176
|
+
if( !t->AmiProc )
|
177
|
+
{
|
178
|
+
free( (void *) t );
|
179
|
+
LEAVE_THREAD_CRITICAL_SECTION
|
180
|
+
return -1;
|
181
|
+
}
|
182
|
+
|
183
|
+
// Get pointer to task structure
|
184
|
+
t->AmiTask = &(t->AmiProc->pr_Task);
|
185
|
+
|
186
|
+
// Store GLFW thread struct pointer in task user data
|
187
|
+
t->AmiTask->tc_UserData = (APTR) t;
|
188
|
+
|
189
|
+
// Append thread to thread list
|
190
|
+
_glfwAppendThread( t );
|
191
|
+
|
192
|
+
// Leave critical section
|
193
|
+
LEAVE_THREAD_CRITICAL_SECTION
|
194
|
+
|
195
|
+
// Return the GLFW thread ID
|
196
|
+
return ID;
|
197
|
+
}
|
198
|
+
|
199
|
+
|
200
|
+
//========================================================================
|
201
|
+
// _glfwPlatformDestroyThread() - Kill a thread. NOTE: THIS IS A VERY
|
202
|
+
// DANGEROUS OPERATION, AND SHOULD NOT BE USED EXCEPT IN EXTREME
|
203
|
+
// SITUATIONS!
|
204
|
+
//========================================================================
|
205
|
+
|
206
|
+
void _glfwPlatformDestroyThread( GLFWthread ID )
|
207
|
+
{
|
208
|
+
_GLFWthread *t, *t_wait;
|
209
|
+
|
210
|
+
// Enter critical section
|
211
|
+
ENTER_THREAD_CRITICAL_SECTION
|
212
|
+
|
213
|
+
// Get thread information pointer
|
214
|
+
t = _glfwGetThreadPointer( ID );
|
215
|
+
if( t == NULL )
|
216
|
+
{
|
217
|
+
LEAVE_THREAD_CRITICAL_SECTION
|
218
|
+
return;
|
219
|
+
}
|
220
|
+
|
221
|
+
// Simply murder the process, no mercy!
|
222
|
+
// ?? How about Process resources ??
|
223
|
+
RemTask( t->AmiTask );
|
224
|
+
|
225
|
+
// Remove thread from thread list
|
226
|
+
_glfwRemoveThread( t );
|
227
|
+
|
228
|
+
// Signal any waiting threads that the thread has died
|
229
|
+
for( t_wait = &_glfwThrd.First; t_wait; t_wait = t_wait->Next )
|
230
|
+
{
|
231
|
+
if( t_wait->WaitFor == (void *) t )
|
232
|
+
{
|
233
|
+
Signal( t_wait->AmiTask, 1L<<t_wait->WaitSig );
|
234
|
+
t_wait->WaitFor = NULL;
|
235
|
+
}
|
236
|
+
}
|
237
|
+
|
238
|
+
// Leave critical section
|
239
|
+
LEAVE_THREAD_CRITICAL_SECTION
|
240
|
+
}
|
241
|
+
|
242
|
+
|
243
|
+
//========================================================================
|
244
|
+
// _glfwPlatformWaitThread() - Wait for a thread to die
|
245
|
+
//========================================================================
|
246
|
+
|
247
|
+
int _glfwPlatformWaitThread( GLFWthread ID, int waitmode )
|
248
|
+
{
|
249
|
+
struct Task *amiTask;
|
250
|
+
_GLFWthread *t, *t_this;
|
251
|
+
int waitSig;
|
252
|
+
|
253
|
+
// Enter critical section
|
254
|
+
ENTER_THREAD_CRITICAL_SECTION
|
255
|
+
|
256
|
+
// Get thread information pointer
|
257
|
+
t = _glfwGetThreadPointer( ID );
|
258
|
+
|
259
|
+
// Is the thread already dead?
|
260
|
+
if( t == NULL )
|
261
|
+
{
|
262
|
+
LEAVE_THREAD_CRITICAL_SECTION
|
263
|
+
return GL_TRUE;
|
264
|
+
}
|
265
|
+
|
266
|
+
// If got this far, the thread is alive => polling returns FALSE
|
267
|
+
if( waitmode == GLFW_NOWAIT )
|
268
|
+
{
|
269
|
+
LEAVE_THREAD_CRITICAL_SECTION
|
270
|
+
return GL_FALSE;
|
271
|
+
}
|
272
|
+
|
273
|
+
// Find pointer to this threads structure
|
274
|
+
amiTask = FindTask( NULL );
|
275
|
+
t_this = (_GLFWthread *) amiTask->tc_UserData;
|
276
|
+
|
277
|
+
// Store information in our thread structure that we want to wait for
|
278
|
+
// the specified thread to die
|
279
|
+
t_this->WaitFor = (void *) t;
|
280
|
+
waitSig = t_this->WaitSig;
|
281
|
+
|
282
|
+
// Leave critical section
|
283
|
+
LEAVE_THREAD_CRITICAL_SECTION
|
284
|
+
|
285
|
+
// Wait for thread to die
|
286
|
+
Wait( 1L<<waitSig );
|
287
|
+
|
288
|
+
return GL_TRUE;
|
289
|
+
}
|
290
|
+
|
291
|
+
|
292
|
+
//========================================================================
|
293
|
+
// _glfwPlatformGetThreadID() - Return the thread ID for the current
|
294
|
+
// thread
|
295
|
+
//========================================================================
|
296
|
+
|
297
|
+
GLFWthread _glfwPlatformGetThreadID( void )
|
298
|
+
{
|
299
|
+
_GLFWthread *t;
|
300
|
+
struct Task *amiTask;
|
301
|
+
|
302
|
+
// Get current task
|
303
|
+
amiTask = FindTask( NULL );
|
304
|
+
|
305
|
+
// The task's user data points to the GLFW thread struct
|
306
|
+
t = (_GLFWthread *) amiTask->tc_UserData;
|
307
|
+
|
308
|
+
// Return the found GLFW thread identifier
|
309
|
+
return t->ID;
|
310
|
+
}
|
311
|
+
|
312
|
+
|
313
|
+
//========================================================================
|
314
|
+
// _glfwPlatformCreateMutex() - Create a mutual exclusion object
|
315
|
+
//========================================================================
|
316
|
+
|
317
|
+
GLFWmutex _glfwPlatformCreateMutex( void )
|
318
|
+
{
|
319
|
+
struct SignalSemaphore *mutex;
|
320
|
+
|
321
|
+
// Allocate memory for mutex
|
322
|
+
mutex = (struct SignalSemaphore *) malloc( sizeof(struct SignalSemaphore) );
|
323
|
+
if( !mutex )
|
324
|
+
{
|
325
|
+
return NULL;
|
326
|
+
}
|
327
|
+
|
328
|
+
// Initialize mutex object
|
329
|
+
memset( mutex, 0, sizeof(struct SignalSemaphore) );
|
330
|
+
InitSemaphore( mutex );
|
331
|
+
|
332
|
+
// Cast to GLFWmutex and return
|
333
|
+
return (GLFWmutex) mutex;
|
334
|
+
}
|
335
|
+
|
336
|
+
|
337
|
+
//========================================================================
|
338
|
+
// _glfwPlatformDestroyMutex() - Destroy a mutual exclusion object
|
339
|
+
//========================================================================
|
340
|
+
|
341
|
+
void _glfwPlatformDestroyMutex( GLFWmutex mutex )
|
342
|
+
{
|
343
|
+
// Free memory for mutex object
|
344
|
+
free( (void *) mutex );
|
345
|
+
}
|
346
|
+
|
347
|
+
|
348
|
+
//========================================================================
|
349
|
+
// _glfwPlatformLockMutex() - Request access to a mutex
|
350
|
+
//========================================================================
|
351
|
+
|
352
|
+
void _glfwPlatformLockMutex( GLFWmutex mutex )
|
353
|
+
{
|
354
|
+
// Wait for mutex to be released
|
355
|
+
ObtainSemaphore( (struct SignalSemaphore *) mutex );
|
356
|
+
}
|
357
|
+
|
358
|
+
|
359
|
+
//========================================================================
|
360
|
+
// _glfwPlatformUnlockMutex() - Release a mutex
|
361
|
+
//========================================================================
|
362
|
+
|
363
|
+
void _glfwPlatformUnlockMutex( GLFWmutex mutex )
|
364
|
+
{
|
365
|
+
// Release mutex
|
366
|
+
ReleaseSemaphore( (struct SignalSemaphore *) mutex );
|
367
|
+
}
|
368
|
+
|
369
|
+
|
370
|
+
//========================================================================
|
371
|
+
// _glfwPlatformCreateCond() - Create a new condition variable object
|
372
|
+
//========================================================================
|
373
|
+
|
374
|
+
GLFWcond _glfwPlatformCreateCond( void )
|
375
|
+
{
|
376
|
+
unsigned int cond;
|
377
|
+
|
378
|
+
// Generate a new unique cond ID
|
379
|
+
ENTER_THREAD_CRITICAL_SECTION
|
380
|
+
cond = _glfwThrd.NextCondID --;
|
381
|
+
LEAVE_THREAD_CRITICAL_SECTION
|
382
|
+
|
383
|
+
// Cast to GLFWcond and return
|
384
|
+
return (GLFWcond) cond;
|
385
|
+
}
|
386
|
+
|
387
|
+
|
388
|
+
//========================================================================
|
389
|
+
// _glfwPlatformDestroyCond() - Destroy a condition variable object
|
390
|
+
//========================================================================
|
391
|
+
|
392
|
+
void _glfwPlatformDestroyCond( GLFWcond cond )
|
393
|
+
{
|
394
|
+
}
|
395
|
+
|
396
|
+
|
397
|
+
//========================================================================
|
398
|
+
// _glfwPlatformWaitCond() - Wait for a condition to be raised
|
399
|
+
//========================================================================
|
400
|
+
|
401
|
+
void _glfwPlatformWaitCond( GLFWcond cond, GLFWmutex mutex,
|
402
|
+
double timeout )
|
403
|
+
{
|
404
|
+
struct Task *amiTask;
|
405
|
+
_GLFWthread *t_this;
|
406
|
+
|
407
|
+
// Do we need a limited timeout?
|
408
|
+
if( timeout < GLFW_INFINITY )
|
409
|
+
{
|
410
|
+
// Oooops! Not implemented properly yet!
|
411
|
+
ReleaseSemaphore( (struct SignalSemaphore *) mutex );
|
412
|
+
Delay( 1 );
|
413
|
+
ObtainSemaphore( (struct SignalSemaphore *) mutex );
|
414
|
+
return;
|
415
|
+
}
|
416
|
+
|
417
|
+
// Find pointer to this threads structure
|
418
|
+
amiTask = FindTask( NULL );
|
419
|
+
t_this = (_GLFWthread *) amiTask->tc_UserData;
|
420
|
+
|
421
|
+
// Store information in our thread structure that we want to wait for
|
422
|
+
// the specified condition variable to be signaled
|
423
|
+
ENTER_THREAD_CRITICAL_SECTION
|
424
|
+
t_this->WaitFor = (void *) cond;
|
425
|
+
LEAVE_THREAD_CRITICAL_SECTION
|
426
|
+
|
427
|
+
// Release the mutex
|
428
|
+
ReleaseSemaphore( (struct SignalSemaphore *) mutex );
|
429
|
+
|
430
|
+
// Wait for condition variable
|
431
|
+
Wait( 1L<<(t_this->WaitSig) );
|
432
|
+
|
433
|
+
// Reacquire the mutex
|
434
|
+
ObtainSemaphore( (struct SignalSemaphore *) mutex );
|
435
|
+
}
|
436
|
+
|
437
|
+
|
438
|
+
//========================================================================
|
439
|
+
// _glfwPlatformSignalCond() - Signal a condition to one waiting thread
|
440
|
+
//========================================================================
|
441
|
+
|
442
|
+
void _glfwPlatformSignalCond( GLFWcond cond )
|
443
|
+
{
|
444
|
+
_GLFWthread *t_wait;
|
445
|
+
|
446
|
+
// Broadcast condition to one waiting thread
|
447
|
+
ENTER_THREAD_CRITICAL_SECTION
|
448
|
+
for( t_wait = &_glfwThrd.First; t_wait; t_wait = t_wait->Next )
|
449
|
+
{
|
450
|
+
if( t_wait->WaitFor == (void *) cond )
|
451
|
+
{
|
452
|
+
Signal( t_wait->AmiTask, 1L<<t_wait->WaitSig );
|
453
|
+
t_wait->WaitFor = NULL;
|
454
|
+
break;
|
455
|
+
}
|
456
|
+
}
|
457
|
+
LEAVE_THREAD_CRITICAL_SECTION
|
458
|
+
}
|
459
|
+
|
460
|
+
|
461
|
+
//========================================================================
|
462
|
+
// _glfwPlatformBroadcastCond() - Broadcast a condition to all waiting
|
463
|
+
// threads
|
464
|
+
//========================================================================
|
465
|
+
|
466
|
+
void _glfwPlatformBroadcastCond( GLFWcond cond )
|
467
|
+
{
|
468
|
+
_GLFWthread *t_wait;
|
469
|
+
|
470
|
+
// Broadcast condition to any waiting threads
|
471
|
+
ENTER_THREAD_CRITICAL_SECTION
|
472
|
+
for( t_wait = &_glfwThrd.First; t_wait; t_wait = t_wait->Next )
|
473
|
+
{
|
474
|
+
if( t_wait->WaitFor == (void *) cond )
|
475
|
+
{
|
476
|
+
Signal( t_wait->AmiTask, 1L<<t_wait->WaitSig );
|
477
|
+
t_wait->WaitFor = NULL;
|
478
|
+
}
|
479
|
+
}
|
480
|
+
LEAVE_THREAD_CRITICAL_SECTION
|
481
|
+
}
|
482
|
+
|
483
|
+
|
484
|
+
//========================================================================
|
485
|
+
// _glfwPlatformGetNumberOfProcessors() - Return the number of processors
|
486
|
+
// in the system.
|
487
|
+
//========================================================================
|
488
|
+
|
489
|
+
int _glfwPlatformGetNumberOfProcessors( void )
|
490
|
+
{
|
491
|
+
// Return number of processors online (MorphOS has SMP support, so we
|
492
|
+
// should do something useful here...)
|
493
|
+
return 1;
|
494
|
+
}
|