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,414 @@
|
|
1
|
+
//========================================================================
|
2
|
+
// GLFW - An OpenGL framework
|
3
|
+
// File: macosx_thread.c
|
4
|
+
// Platform: Mac OS X
|
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
|
+
void * _glfwNewThread( void * arg )
|
45
|
+
{
|
46
|
+
GLFWthreadfun threadfun;
|
47
|
+
_GLFWthread *t;
|
48
|
+
|
49
|
+
// Get pointer to thread information for current thread
|
50
|
+
t = _glfwGetThreadPointer( glfwGetThreadID() );
|
51
|
+
if( t == NULL )
|
52
|
+
{
|
53
|
+
return 0;
|
54
|
+
}
|
55
|
+
|
56
|
+
// Get user thread function pointer
|
57
|
+
threadfun = t->Function;
|
58
|
+
|
59
|
+
// Call the user thread function
|
60
|
+
threadfun( arg );
|
61
|
+
|
62
|
+
// Remove thread from thread list
|
63
|
+
ENTER_THREAD_CRITICAL_SECTION
|
64
|
+
_glfwRemoveThread( t );
|
65
|
+
LEAVE_THREAD_CRITICAL_SECTION
|
66
|
+
|
67
|
+
// When the thread function returns, the thread will die...
|
68
|
+
return NULL;
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
//************************************************************************
|
74
|
+
//**** Platform implementation functions ****
|
75
|
+
//************************************************************************
|
76
|
+
|
77
|
+
//========================================================================
|
78
|
+
// _glfwPlatformCreateThread() - Create a new thread
|
79
|
+
//========================================================================
|
80
|
+
|
81
|
+
GLFWthread _glfwPlatformCreateThread( GLFWthreadfun fun, void *arg )
|
82
|
+
{
|
83
|
+
GLFWthread ID;
|
84
|
+
_GLFWthread *t;
|
85
|
+
int result;
|
86
|
+
|
87
|
+
// Enter critical section
|
88
|
+
ENTER_THREAD_CRITICAL_SECTION
|
89
|
+
|
90
|
+
// Create a new thread information memory area
|
91
|
+
t = (_GLFWthread *) malloc( sizeof(_GLFWthread) );
|
92
|
+
if( t == NULL )
|
93
|
+
{
|
94
|
+
// Leave critical section
|
95
|
+
LEAVE_THREAD_CRITICAL_SECTION
|
96
|
+
return -1;
|
97
|
+
}
|
98
|
+
|
99
|
+
// Get a new unique thread id
|
100
|
+
ID = _glfwThrd.NextID ++;
|
101
|
+
|
102
|
+
// Store thread information in the thread list
|
103
|
+
t->Function = fun;
|
104
|
+
t->ID = ID;
|
105
|
+
|
106
|
+
// Create thread
|
107
|
+
result = pthread_create(
|
108
|
+
&t->PosixID, // Thread handle
|
109
|
+
NULL, // Default thread attributes
|
110
|
+
_glfwNewThread, // Thread function (a wrapper function)
|
111
|
+
(void *)arg // Argument to thread is user argument
|
112
|
+
);
|
113
|
+
|
114
|
+
// Did the thread creation fail?
|
115
|
+
if( result != 0 )
|
116
|
+
{
|
117
|
+
free( (void *) t );
|
118
|
+
LEAVE_THREAD_CRITICAL_SECTION
|
119
|
+
return -1;
|
120
|
+
}
|
121
|
+
|
122
|
+
// Append thread to thread list
|
123
|
+
_glfwAppendThread( t );
|
124
|
+
|
125
|
+
// Leave critical section
|
126
|
+
LEAVE_THREAD_CRITICAL_SECTION
|
127
|
+
|
128
|
+
// Return the GLFW thread ID
|
129
|
+
return ID;
|
130
|
+
}
|
131
|
+
|
132
|
+
|
133
|
+
//========================================================================
|
134
|
+
// _glfwPlatformDestroyThread() - Kill a thread. NOTE: THIS IS A VERY
|
135
|
+
// DANGEROUS OPERATION, AND SHOULD NOT BE USED EXCEPT IN EXTREME
|
136
|
+
// SITUATIONS!
|
137
|
+
//========================================================================
|
138
|
+
|
139
|
+
void _glfwPlatformDestroyThread( GLFWthread ID )
|
140
|
+
{
|
141
|
+
_GLFWthread *t;
|
142
|
+
|
143
|
+
// Enter critical section
|
144
|
+
ENTER_THREAD_CRITICAL_SECTION
|
145
|
+
|
146
|
+
// Get thread information pointer
|
147
|
+
t = _glfwGetThreadPointer( ID );
|
148
|
+
if( t == NULL )
|
149
|
+
{
|
150
|
+
LEAVE_THREAD_CRITICAL_SECTION
|
151
|
+
return;
|
152
|
+
}
|
153
|
+
|
154
|
+
// Simply murder the process, no mercy!
|
155
|
+
pthread_kill( t->PosixID, SIGKILL );
|
156
|
+
|
157
|
+
// Remove thread from thread list
|
158
|
+
_glfwRemoveThread( t );
|
159
|
+
|
160
|
+
// Leave critical section
|
161
|
+
LEAVE_THREAD_CRITICAL_SECTION
|
162
|
+
}
|
163
|
+
|
164
|
+
|
165
|
+
//========================================================================
|
166
|
+
// _glfwPlatformWaitThread() - Wait for a thread to die
|
167
|
+
//========================================================================
|
168
|
+
|
169
|
+
int _glfwPlatformWaitThread( GLFWthread ID, int waitmode )
|
170
|
+
{
|
171
|
+
pthread_t thread;
|
172
|
+
_GLFWthread *t;
|
173
|
+
|
174
|
+
// Enter critical section
|
175
|
+
ENTER_THREAD_CRITICAL_SECTION
|
176
|
+
|
177
|
+
// Get thread information pointer
|
178
|
+
t = _glfwGetThreadPointer( ID );
|
179
|
+
|
180
|
+
// Is the thread already dead?
|
181
|
+
if( t == NULL )
|
182
|
+
{
|
183
|
+
LEAVE_THREAD_CRITICAL_SECTION
|
184
|
+
return GL_TRUE;
|
185
|
+
}
|
186
|
+
|
187
|
+
// If got this far, the thread is alive => polling returns FALSE
|
188
|
+
if( waitmode == GLFW_NOWAIT )
|
189
|
+
{
|
190
|
+
LEAVE_THREAD_CRITICAL_SECTION
|
191
|
+
return GL_FALSE;
|
192
|
+
}
|
193
|
+
|
194
|
+
// Get thread handle
|
195
|
+
thread = t->PosixID;
|
196
|
+
|
197
|
+
// Leave critical section
|
198
|
+
LEAVE_THREAD_CRITICAL_SECTION
|
199
|
+
|
200
|
+
// Wait for thread to die
|
201
|
+
(void) pthread_join( thread, NULL );
|
202
|
+
|
203
|
+
return GL_TRUE;
|
204
|
+
}
|
205
|
+
|
206
|
+
|
207
|
+
//========================================================================
|
208
|
+
// _glfwPlatformGetThreadID() - Return the thread ID for the current
|
209
|
+
// thread
|
210
|
+
//========================================================================
|
211
|
+
|
212
|
+
GLFWthread _glfwPlatformGetThreadID( void )
|
213
|
+
{
|
214
|
+
_GLFWthread *t;
|
215
|
+
GLFWthread ID = -1;
|
216
|
+
pthread_t posixID;
|
217
|
+
|
218
|
+
// Get current thread ID
|
219
|
+
posixID = pthread_self();
|
220
|
+
|
221
|
+
// Enter critical section
|
222
|
+
ENTER_THREAD_CRITICAL_SECTION
|
223
|
+
|
224
|
+
// Loop through entire list of threads to find the matching POSIX
|
225
|
+
// thread ID
|
226
|
+
for( t = &_glfwThrd.First; t != NULL; t = t->Next )
|
227
|
+
{
|
228
|
+
if( t->PosixID == posixID )
|
229
|
+
{
|
230
|
+
ID = t->ID;
|
231
|
+
break;
|
232
|
+
}
|
233
|
+
}
|
234
|
+
|
235
|
+
// Leave critical section
|
236
|
+
LEAVE_THREAD_CRITICAL_SECTION
|
237
|
+
|
238
|
+
// Return the found GLFW thread identifier
|
239
|
+
return ID;
|
240
|
+
}
|
241
|
+
|
242
|
+
|
243
|
+
//========================================================================
|
244
|
+
// _glfwPlatformCreateMutex() - Create a mutual exclusion object
|
245
|
+
//========================================================================
|
246
|
+
|
247
|
+
GLFWmutex _glfwPlatformCreateMutex( void )
|
248
|
+
{
|
249
|
+
pthread_mutex_t *mutex;
|
250
|
+
|
251
|
+
// Allocate memory for mutex
|
252
|
+
mutex = (pthread_mutex_t *) malloc( sizeof( pthread_mutex_t ) );
|
253
|
+
if( !mutex )
|
254
|
+
{
|
255
|
+
return NULL;
|
256
|
+
}
|
257
|
+
|
258
|
+
// Initialise a mutex object
|
259
|
+
(void) pthread_mutex_init( mutex, NULL );
|
260
|
+
|
261
|
+
// Cast to GLFWmutex and return
|
262
|
+
return (GLFWmutex) mutex;
|
263
|
+
}
|
264
|
+
|
265
|
+
|
266
|
+
//========================================================================
|
267
|
+
// _glfwPlatformDestroyMutex() - Destroy a mutual exclusion object
|
268
|
+
//========================================================================
|
269
|
+
|
270
|
+
void _glfwPlatformDestroyMutex( GLFWmutex mutex )
|
271
|
+
{
|
272
|
+
// Destroy the mutex object
|
273
|
+
pthread_mutex_destroy( (pthread_mutex_t *) mutex );
|
274
|
+
|
275
|
+
// Free memory for mutex object
|
276
|
+
free( (void *) mutex );
|
277
|
+
}
|
278
|
+
|
279
|
+
|
280
|
+
//========================================================================
|
281
|
+
// _glfwPlatformLockMutex() - Request access to a mutex
|
282
|
+
//========================================================================
|
283
|
+
|
284
|
+
void _glfwPlatformLockMutex( GLFWmutex mutex )
|
285
|
+
{
|
286
|
+
// Wait for mutex to be released
|
287
|
+
(void) pthread_mutex_lock( (pthread_mutex_t *) mutex );
|
288
|
+
}
|
289
|
+
|
290
|
+
|
291
|
+
//========================================================================
|
292
|
+
// _glfwPlatformUnlockMutex() - Release a mutex
|
293
|
+
//========================================================================
|
294
|
+
|
295
|
+
void _glfwPlatformUnlockMutex( GLFWmutex mutex )
|
296
|
+
{
|
297
|
+
// Release mutex
|
298
|
+
pthread_mutex_unlock( (pthread_mutex_t *) mutex );
|
299
|
+
}
|
300
|
+
|
301
|
+
|
302
|
+
//========================================================================
|
303
|
+
// _glfwPlatformCreateCond() - Create a new condition variable object
|
304
|
+
//========================================================================
|
305
|
+
|
306
|
+
GLFWcond _glfwPlatformCreateCond( void )
|
307
|
+
{
|
308
|
+
pthread_cond_t *cond;
|
309
|
+
|
310
|
+
// Allocate memory for condition variable
|
311
|
+
cond = (pthread_cond_t *) malloc( sizeof(pthread_cond_t) );
|
312
|
+
if( !cond )
|
313
|
+
{
|
314
|
+
return NULL;
|
315
|
+
}
|
316
|
+
|
317
|
+
// Initialise condition variable
|
318
|
+
(void) pthread_cond_init( cond, NULL );
|
319
|
+
|
320
|
+
// Cast to GLFWcond and return
|
321
|
+
return (GLFWcond) cond;
|
322
|
+
}
|
323
|
+
|
324
|
+
|
325
|
+
//========================================================================
|
326
|
+
// _glfwPlatformDestroyCond() - Destroy a condition variable object
|
327
|
+
//========================================================================
|
328
|
+
|
329
|
+
void _glfwPlatformDestroyCond( GLFWcond cond )
|
330
|
+
{
|
331
|
+
// Destroy the condition variable object
|
332
|
+
(void) pthread_cond_destroy( (pthread_cond_t *) cond );
|
333
|
+
|
334
|
+
// Free memory for condition variable object
|
335
|
+
free( (void *) cond );
|
336
|
+
}
|
337
|
+
|
338
|
+
|
339
|
+
//========================================================================
|
340
|
+
// _glfwPlatformWaitCond() - Wait for a condition to be raised
|
341
|
+
//========================================================================
|
342
|
+
|
343
|
+
void _glfwPlatformWaitCond( GLFWcond cond, GLFWmutex mutex,
|
344
|
+
double timeout )
|
345
|
+
{
|
346
|
+
struct timeval currenttime;
|
347
|
+
struct timespec wait;
|
348
|
+
long dt_sec, dt_usec;
|
349
|
+
|
350
|
+
// Select infinite or timed wait
|
351
|
+
if( timeout >= GLFW_INFINITY )
|
352
|
+
{
|
353
|
+
// Wait for condition (infinite wait)
|
354
|
+
(void) pthread_cond_wait( (pthread_cond_t *) cond,
|
355
|
+
(pthread_mutex_t *) mutex );
|
356
|
+
}
|
357
|
+
else
|
358
|
+
{
|
359
|
+
// Set timeout time, relatvie to current time
|
360
|
+
gettimeofday( ¤ttime, NULL );
|
361
|
+
dt_sec = (long) timeout;
|
362
|
+
dt_usec = (long) ((timeout - (double)dt_sec) * 1000000.0);
|
363
|
+
wait.tv_nsec = (currenttime.tv_usec + dt_usec) * 1000L;
|
364
|
+
if( wait.tv_nsec > 1000000000L )
|
365
|
+
{
|
366
|
+
wait.tv_nsec -= 1000000000L;
|
367
|
+
dt_sec ++;
|
368
|
+
}
|
369
|
+
wait.tv_sec = currenttime.tv_sec + dt_sec;
|
370
|
+
|
371
|
+
// Wait for condition (timed wait)
|
372
|
+
(void) pthread_cond_timedwait( (pthread_cond_t *) cond,
|
373
|
+
(pthread_mutex_t *) mutex, &wait );
|
374
|
+
}
|
375
|
+
}
|
376
|
+
|
377
|
+
|
378
|
+
//========================================================================
|
379
|
+
// _glfwPlatformSignalCond() - Signal a condition to one waiting thread
|
380
|
+
//========================================================================
|
381
|
+
|
382
|
+
void _glfwPlatformSignalCond( GLFWcond cond )
|
383
|
+
{
|
384
|
+
// Signal condition
|
385
|
+
(void) pthread_cond_signal( (pthread_cond_t *) cond );
|
386
|
+
}
|
387
|
+
|
388
|
+
|
389
|
+
//========================================================================
|
390
|
+
// _glfwPlatformBroadcastCond() - Broadcast a condition to all waiting
|
391
|
+
// threads
|
392
|
+
//========================================================================
|
393
|
+
|
394
|
+
void _glfwPlatformBroadcastCond( GLFWcond cond )
|
395
|
+
{
|
396
|
+
// Broadcast condition
|
397
|
+
(void) pthread_cond_broadcast( (pthread_cond_t *) cond );
|
398
|
+
}
|
399
|
+
|
400
|
+
|
401
|
+
//========================================================================
|
402
|
+
// _glfwPlatformGetNumberOfProcessors() - Return the number of processors
|
403
|
+
// in the system.
|
404
|
+
//========================================================================
|
405
|
+
|
406
|
+
int _glfwPlatformGetNumberOfProcessors( void )
|
407
|
+
{
|
408
|
+
int n;
|
409
|
+
|
410
|
+
// Get number of processors online
|
411
|
+
_glfw_numprocessors( n );
|
412
|
+
return n;
|
413
|
+
}
|
414
|
+
|
@@ -0,0 +1,112 @@
|
|
1
|
+
//========================================================================
|
2
|
+
// GLFW - An OpenGL framework
|
3
|
+
// File: macosx_time.c
|
4
|
+
// Platform: Mac OS X
|
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
|
+
//**** Platform implementation functions ****
|
35
|
+
//************************************************************************
|
36
|
+
|
37
|
+
//========================================================================
|
38
|
+
// Return timer value in seconds
|
39
|
+
//========================================================================
|
40
|
+
|
41
|
+
double _glfwPlatformGetTime( void )
|
42
|
+
{
|
43
|
+
struct timeval tv;
|
44
|
+
|
45
|
+
gettimeofday( &tv, NULL );
|
46
|
+
return tv.tv_sec + (double) tv.tv_usec / 1000000.0 - _glfwLibrary.Timer.t0;
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
//========================================================================
|
51
|
+
// Set timer value in seconds
|
52
|
+
//========================================================================
|
53
|
+
|
54
|
+
void _glfwPlatformSetTime( double time )
|
55
|
+
{
|
56
|
+
struct timeval tv;
|
57
|
+
|
58
|
+
gettimeofday( &tv, NULL );
|
59
|
+
_glfwLibrary.Timer.t0 = tv.tv_sec + (double) tv.tv_usec / 1000000.0 - time;
|
60
|
+
}
|
61
|
+
|
62
|
+
|
63
|
+
//========================================================================
|
64
|
+
// Put a thread to sleep for a specified amount of time
|
65
|
+
//========================================================================
|
66
|
+
|
67
|
+
void _glfwPlatformSleep( double time )
|
68
|
+
{
|
69
|
+
if( time == 0.0 )
|
70
|
+
{
|
71
|
+
sched_yield();
|
72
|
+
return;
|
73
|
+
}
|
74
|
+
|
75
|
+
struct timeval currenttime;
|
76
|
+
struct timespec wait;
|
77
|
+
pthread_mutex_t mutex;
|
78
|
+
pthread_cond_t cond;
|
79
|
+
long dt_sec, dt_usec;
|
80
|
+
|
81
|
+
// Not all pthread implementations have a pthread_sleep() function. We
|
82
|
+
// do it the portable way, using a timed wait for a condition that we
|
83
|
+
// will never signal. NOTE: The unistd functions sleep/usleep suspends
|
84
|
+
// the entire PROCESS, not a signle thread, which is why we can not
|
85
|
+
// use them to implement glfwSleep.
|
86
|
+
|
87
|
+
// Set timeout time, relatvie to current time
|
88
|
+
gettimeofday( ¤ttime, NULL );
|
89
|
+
dt_sec = (long) time;
|
90
|
+
dt_usec = (long) ((time - (double)dt_sec) * 1000000.0);
|
91
|
+
wait.tv_nsec = (currenttime.tv_usec + dt_usec) * 1000L;
|
92
|
+
if( wait.tv_nsec > 1000000000L )
|
93
|
+
{
|
94
|
+
wait.tv_nsec -= 1000000000L;
|
95
|
+
dt_sec ++;
|
96
|
+
}
|
97
|
+
wait.tv_sec = currenttime.tv_sec + dt_sec;
|
98
|
+
|
99
|
+
// Initialize condition and mutex objects
|
100
|
+
pthread_mutex_init( &mutex, NULL );
|
101
|
+
pthread_cond_init( &cond, NULL );
|
102
|
+
|
103
|
+
// Do a timed wait
|
104
|
+
pthread_mutex_lock( &mutex );
|
105
|
+
pthread_cond_timedwait( &cond, &mutex, &wait );
|
106
|
+
pthread_mutex_unlock( &mutex );
|
107
|
+
|
108
|
+
// Destroy condition and mutex objects
|
109
|
+
pthread_mutex_destroy( &mutex );
|
110
|
+
pthread_cond_destroy( &cond );
|
111
|
+
}
|
112
|
+
|