ruby-glfw 0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. data/README +1 -0
  2. data/README.API +73 -0
  3. data/Rakefile +120 -0
  4. data/examples/boing.rb +519 -0
  5. data/examples/gears.rb +327 -0
  6. data/examples/keytest.rb +117 -0
  7. data/examples/listmodes.rb +20 -0
  8. data/examples/mipmaps.rb +104 -0
  9. data/examples/mipmaps.tga +0 -0
  10. data/examples/particles.rb +837 -0
  11. data/examples/pong3d.rb +741 -0
  12. data/examples/pong3d_field.tga +0 -0
  13. data/examples/pong3d_instr.tga +0 -0
  14. data/examples/pong3d_menu.tga +0 -0
  15. data/examples/pong3d_title.tga +0 -0
  16. data/examples/pong3d_winner1.tga +0 -0
  17. data/examples/pong3d_winner2.tga +0 -0
  18. data/examples/splitview.rb +432 -0
  19. data/examples/triangle.rb +89 -0
  20. data/examples/wave.rb +294 -0
  21. data/ext/glfw/glfw.c +1094 -0
  22. data/ext/glfw/mkrf_conf.rb +70 -0
  23. data/glfw-src/Makefile +220 -0
  24. data/glfw-src/compile.ami +61 -0
  25. data/glfw-src/compile.bat +217 -0
  26. data/glfw-src/compile.sh +607 -0
  27. data/glfw-src/docs/Makefile +57 -0
  28. data/glfw-src/docs/Reference.pdf +0 -0
  29. data/glfw-src/docs/UsersGuide.pdf +0 -0
  30. data/glfw-src/docs/cleanup.bat +22 -0
  31. data/glfw-src/docs/glfwdoc.sty +80 -0
  32. data/glfw-src/docs/glfwrm.tex +3034 -0
  33. data/glfw-src/docs/glfwug.tex +2024 -0
  34. data/glfw-src/docs/readme.txt +80 -0
  35. data/glfw-src/examples/Makefile.amigaos.gcc +70 -0
  36. data/glfw-src/examples/Makefile.amigaos.vbcc +70 -0
  37. data/glfw-src/examples/Makefile.dos.djgpp +71 -0
  38. data/glfw-src/examples/Makefile.macosx.gcc +96 -0
  39. data/glfw-src/examples/Makefile.win32.bcc +75 -0
  40. data/glfw-src/examples/Makefile.win32.cross-mgw +79 -0
  41. data/glfw-src/examples/Makefile.win32.cygwin +79 -0
  42. data/glfw-src/examples/Makefile.win32.lcc +74 -0
  43. data/glfw-src/examples/Makefile.win32.mgw +75 -0
  44. data/glfw-src/examples/Makefile.win32.msvc +74 -0
  45. data/glfw-src/examples/Makefile.win32.ow +74 -0
  46. data/glfw-src/examples/Makefile.win32.pellesc +74 -0
  47. data/glfw-src/examples/Makefile.x11.in +54 -0
  48. data/glfw-src/examples/boing.c +606 -0
  49. data/glfw-src/examples/bundle.sh +46 -0
  50. data/glfw-src/examples/gears.c +382 -0
  51. data/glfw-src/examples/keytest.c +264 -0
  52. data/glfw-src/examples/listmodes.c +48 -0
  53. data/glfw-src/examples/mipmaps.c +126 -0
  54. data/glfw-src/examples/mipmaps.tga +0 -0
  55. data/glfw-src/examples/mtbench.c +301 -0
  56. data/glfw-src/examples/mthello.c +48 -0
  57. data/glfw-src/examples/particles.c +1148 -0
  58. data/glfw-src/examples/pong3d.c +839 -0
  59. data/glfw-src/examples/pong3d_field.tga +0 -0
  60. data/glfw-src/examples/pong3d_instr.tga +0 -0
  61. data/glfw-src/examples/pong3d_menu.tga +0 -0
  62. data/glfw-src/examples/pong3d_title.tga +0 -0
  63. data/glfw-src/examples/pong3d_winner1.tga +0 -0
  64. data/glfw-src/examples/pong3d_winner2.tga +0 -0
  65. data/glfw-src/examples/splitview.c +506 -0
  66. data/glfw-src/examples/triangle.c +108 -0
  67. data/glfw-src/examples/wave.c +397 -0
  68. data/glfw-src/images/opengl.gif +0 -0
  69. data/glfw-src/images/osicert.gif +0 -0
  70. data/glfw-src/include/GL/glfw.h +486 -0
  71. data/glfw-src/lib/amigaos/Makefile.amigaos.gcc +128 -0
  72. data/glfw-src/lib/amigaos/Makefile.amigaos.vbcc +128 -0
  73. data/glfw-src/lib/amigaos/SDI_compiler.h +94 -0
  74. data/glfw-src/lib/amigaos/amigaos_enable.c +51 -0
  75. data/glfw-src/lib/amigaos/amigaos_fullscreen.c +319 -0
  76. data/glfw-src/lib/amigaos/amigaos_glext.c +61 -0
  77. data/glfw-src/lib/amigaos/amigaos_init.c +284 -0
  78. data/glfw-src/lib/amigaos/amigaos_joystick.c +359 -0
  79. data/glfw-src/lib/amigaos/amigaos_thread.c +494 -0
  80. data/glfw-src/lib/amigaos/amigaos_time.c +206 -0
  81. data/glfw-src/lib/amigaos/amigaos_window.c +830 -0
  82. data/glfw-src/lib/amigaos/platform.h +337 -0
  83. data/glfw-src/lib/dos/Makefile.dos.djgpp +146 -0
  84. data/glfw-src/lib/dos/dos_enable.c +51 -0
  85. data/glfw-src/lib/dos/dos_events.c +173 -0
  86. data/glfw-src/lib/dos/dos_fullscreen.c +101 -0
  87. data/glfw-src/lib/dos/dos_glext.c +59 -0
  88. data/glfw-src/lib/dos/dos_init.c +105 -0
  89. data/glfw-src/lib/dos/dos_irq.s +246 -0
  90. data/glfw-src/lib/dos/dos_joystick.c +94 -0
  91. data/glfw-src/lib/dos/dos_keyboard.c +694 -0
  92. data/glfw-src/lib/dos/dos_mouse.c +337 -0
  93. data/glfw-src/lib/dos/dos_thread.c +267 -0
  94. data/glfw-src/lib/dos/dos_time.c +309 -0
  95. data/glfw-src/lib/dos/dos_window.c +563 -0
  96. data/glfw-src/lib/dos/platform.h +341 -0
  97. data/glfw-src/lib/enable.c +295 -0
  98. data/glfw-src/lib/fullscreen.c +95 -0
  99. data/glfw-src/lib/glext.c +201 -0
  100. data/glfw-src/lib/image.c +629 -0
  101. data/glfw-src/lib/init.c +108 -0
  102. data/glfw-src/lib/input.c +280 -0
  103. data/glfw-src/lib/internal.h +210 -0
  104. data/glfw-src/lib/joystick.c +101 -0
  105. data/glfw-src/lib/macosx/Makefile.macosx.gcc +172 -0
  106. data/glfw-src/lib/macosx/Makefile.macosx.gcc.universal +166 -0
  107. data/glfw-src/lib/macosx/libglfw.pc.in +11 -0
  108. data/glfw-src/lib/macosx/macosx_enable.c +42 -0
  109. data/glfw-src/lib/macosx/macosx_fullscreen.c +126 -0
  110. data/glfw-src/lib/macosx/macosx_glext.c +52 -0
  111. data/glfw-src/lib/macosx/macosx_init.c +194 -0
  112. data/glfw-src/lib/macosx/macosx_joystick.c +50 -0
  113. data/glfw-src/lib/macosx/macosx_thread.c +414 -0
  114. data/glfw-src/lib/macosx/macosx_time.c +112 -0
  115. data/glfw-src/lib/macosx/macosx_window.c +1279 -0
  116. data/glfw-src/lib/macosx/platform.h +349 -0
  117. data/glfw-src/lib/stream.c +194 -0
  118. data/glfw-src/lib/tga.c +405 -0
  119. data/glfw-src/lib/thread.c +340 -0
  120. data/glfw-src/lib/time.c +83 -0
  121. data/glfw-src/lib/win32/Makefile.win32.bcc +265 -0
  122. data/glfw-src/lib/win32/Makefile.win32.cross-mgw +274 -0
  123. data/glfw-src/lib/win32/Makefile.win32.cygwin +279 -0
  124. data/glfw-src/lib/win32/Makefile.win32.lcc +246 -0
  125. data/glfw-src/lib/win32/Makefile.win32.mgw +243 -0
  126. data/glfw-src/lib/win32/Makefile.win32.msvc +242 -0
  127. data/glfw-src/lib/win32/Makefile.win32.ow +242 -0
  128. data/glfw-src/lib/win32/Makefile.win32.pellesc +242 -0
  129. data/glfw-src/lib/win32/glfwdll.def +67 -0
  130. data/glfw-src/lib/win32/glfwdll_mgw1.def +67 -0
  131. data/glfw-src/lib/win32/glfwdll_mgw2.def +67 -0
  132. data/glfw-src/lib/win32/glfwdll_pellesc.def +65 -0
  133. data/glfw-src/lib/win32/libglfw.pc.in +11 -0
  134. data/glfw-src/lib/win32/platform.h +474 -0
  135. data/glfw-src/lib/win32/win32_dllmain.c +60 -0
  136. data/glfw-src/lib/win32/win32_enable.c +155 -0
  137. data/glfw-src/lib/win32/win32_fullscreen.c +317 -0
  138. data/glfw-src/lib/win32/win32_glext.c +85 -0
  139. data/glfw-src/lib/win32/win32_init.c +356 -0
  140. data/glfw-src/lib/win32/win32_joystick.c +234 -0
  141. data/glfw-src/lib/win32/win32_thread.c +511 -0
  142. data/glfw-src/lib/win32/win32_time.c +146 -0
  143. data/glfw-src/lib/win32/win32_window.c +1714 -0
  144. data/glfw-src/lib/window.c +727 -0
  145. data/glfw-src/lib/x11/Makefile.x11.in +243 -0
  146. data/glfw-src/lib/x11/platform.h +415 -0
  147. data/glfw-src/lib/x11/x11_enable.c +51 -0
  148. data/glfw-src/lib/x11/x11_fullscreen.c +524 -0
  149. data/glfw-src/lib/x11/x11_glext.c +69 -0
  150. data/glfw-src/lib/x11/x11_init.c +275 -0
  151. data/glfw-src/lib/x11/x11_joystick.c +371 -0
  152. data/glfw-src/lib/x11/x11_keysym2unicode.c +902 -0
  153. data/glfw-src/lib/x11/x11_thread.c +507 -0
  154. data/glfw-src/lib/x11/x11_time.c +154 -0
  155. data/glfw-src/lib/x11/x11_window.c +1746 -0
  156. data/glfw-src/license.txt +21 -0
  157. data/glfw-src/readme.html +927 -0
  158. data/glfw-src/support/d/examples/Makefile +59 -0
  159. data/glfw-src/support/d/examples/boing.d +610 -0
  160. data/glfw-src/support/d/examples/gears.d +379 -0
  161. data/glfw-src/support/d/examples/keytest.d +272 -0
  162. data/glfw-src/support/d/examples/listmodes.d +48 -0
  163. data/glfw-src/support/d/examples/mipmaps.d +126 -0
  164. data/glfw-src/support/d/examples/mtbench.d +304 -0
  165. data/glfw-src/support/d/examples/mthello.d +54 -0
  166. data/glfw-src/support/d/examples/particles.d +1150 -0
  167. data/glfw-src/support/d/examples/pong3d.d +840 -0
  168. data/glfw-src/support/d/examples/splitview.d +486 -0
  169. data/glfw-src/support/d/examples/triangle.d +108 -0
  170. data/glfw-src/support/d/examples/wave.d +400 -0
  171. data/glfw-src/support/d/imports/gl.d +4539 -0
  172. data/glfw-src/support/d/imports/glfw.d +349 -0
  173. data/glfw-src/support/d/imports/glu.d +328 -0
  174. data/glfw-src/support/d/lib/glfwdll.def +64 -0
  175. data/glfw-src/support/d/lib/glu32.def +56 -0
  176. data/glfw-src/support/d/lib/makefile +12 -0
  177. data/glfw-src/support/d/lib/opengl32.def +372 -0
  178. data/glfw-src/support/d/readme.html +83 -0
  179. data/glfw-src/support/delphi/examples/Triangle.dpr +105 -0
  180. data/glfw-src/support/delphi/lib/glfw.pas +437 -0
  181. data/glfw-src/support/delphi/readme.html +97 -0
  182. data/glfw-src/support/lua/examples/gears.lua +383 -0
  183. data/glfw-src/support/lua/examples/test1.lua +68 -0
  184. data/glfw-src/support/lua/readme.html +128 -0
  185. data/glfw-src/support/lua/src/luaglfw.c +1179 -0
  186. data/glfw-src/support/lua/src/luaglfw.h +48 -0
  187. data/glfw-src/support/lua/src/runlua.c +82 -0
  188. data/glfw-src/support/masm/examples/fpc.mac +47 -0
  189. data/glfw-src/support/masm/examples/makeit.bat +66 -0
  190. data/glfw-src/support/masm/examples/triangle.asm +232 -0
  191. data/glfw-src/support/masm/include/glfw.inc +326 -0
  192. data/glfw-src/support/masm/include/glu32.inc +55 -0
  193. data/glfw-src/support/masm/include/opengl32.inc +372 -0
  194. data/glfw-src/support/masm/lib/glfwdll.lib +0 -0
  195. data/glfw-src/support/masm/readme.html +170 -0
  196. data/glfw-src/support/msvc80/GLFW.sln +26 -0
  197. data/glfw-src/support/msvc80/GLFW.vcproj +257 -0
  198. data/glfw-src/support/msvc80/GLFWDLL.vcproj +287 -0
  199. data/glfw-src/support/visualbasic/bindings/glfw.bas +320 -0
  200. data/glfw-src/support/visualbasic/bindings/glu32.bas +284 -0
  201. data/glfw-src/support/visualbasic/bindings/opengl32.bas +999 -0
  202. data/glfw-src/support/visualbasic/examples/Triangle.bas +101 -0
  203. data/glfw-src/support/visualbasic/readme.html +164 -0
  204. data/website/index.html +84 -0
  205. data/website/style.css +110 -0
  206. metadata +301 -0
@@ -0,0 +1,507 @@
1
+ //========================================================================
2
+ // GLFW - An OpenGL framework
3
+ // File: x11_thread.c
4
+ // Platform: X11 (Unix)
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
+ #ifdef _GLFW_HAS_PTHREAD
40
+
41
+ //========================================================================
42
+ // _glfwNewThread() - This is simply a "wrapper" for calling the user
43
+ // thread function.
44
+ //========================================================================
45
+
46
+ void * _glfwNewThread( void * arg )
47
+ {
48
+ GLFWthreadfun threadfun;
49
+ _GLFWthread *t;
50
+ pthread_t posixID;
51
+
52
+ // Get current thread ID
53
+ posixID = pthread_self();
54
+
55
+ // Enter critical section
56
+ ENTER_THREAD_CRITICAL_SECTION
57
+
58
+ // Loop through entire list of threads to find the matching POSIX
59
+ // thread ID
60
+ for( t = &_glfwThrd.First; t != NULL; t = t->Next )
61
+ {
62
+ if( t->PosixID == posixID )
63
+ {
64
+ break;
65
+ }
66
+ }
67
+ if( t == NULL )
68
+ {
69
+ LEAVE_THREAD_CRITICAL_SECTION
70
+ return NULL;
71
+ }
72
+
73
+ // Get user thread function pointer
74
+ threadfun = t->Function;
75
+
76
+ // Leave critical section
77
+ LEAVE_THREAD_CRITICAL_SECTION
78
+
79
+ // Call the user thread function
80
+ threadfun( arg );
81
+
82
+ // Remove thread from thread list
83
+ ENTER_THREAD_CRITICAL_SECTION
84
+ _glfwRemoveThread( t );
85
+ LEAVE_THREAD_CRITICAL_SECTION
86
+
87
+ // When the thread function returns, the thread will die...
88
+ return NULL;
89
+ }
90
+
91
+ #endif // _GLFW_HAS_PTHREAD
92
+
93
+
94
+
95
+ //************************************************************************
96
+ //**** Platform implementation functions ****
97
+ //************************************************************************
98
+
99
+ //========================================================================
100
+ // _glfwPlatformCreateThread() - Create a new thread
101
+ //========================================================================
102
+
103
+ GLFWthread _glfwPlatformCreateThread( GLFWthreadfun fun, void *arg )
104
+ {
105
+ #ifdef _GLFW_HAS_PTHREAD
106
+
107
+ GLFWthread ID;
108
+ _GLFWthread *t;
109
+ int result;
110
+
111
+ // Enter critical section
112
+ ENTER_THREAD_CRITICAL_SECTION
113
+
114
+ // Create a new thread information memory area
115
+ t = (_GLFWthread *) malloc( sizeof(_GLFWthread) );
116
+ if( t == NULL )
117
+ {
118
+ // Leave critical section
119
+ LEAVE_THREAD_CRITICAL_SECTION
120
+ return -1;
121
+ }
122
+
123
+ // Get a new unique thread id
124
+ ID = _glfwThrd.NextID ++;
125
+
126
+ // Store thread information in the thread list
127
+ t->Function = fun;
128
+ t->ID = ID;
129
+
130
+ // Create thread
131
+ result = pthread_create(
132
+ &t->PosixID, // Thread handle
133
+ NULL, // Default thread attributes
134
+ _glfwNewThread, // Thread function (a wrapper function)
135
+ (void *)arg // Argument to thread is user argument
136
+ );
137
+
138
+ // Did the thread creation fail?
139
+ if( result != 0 )
140
+ {
141
+ free( (void *) t );
142
+ LEAVE_THREAD_CRITICAL_SECTION
143
+ return -1;
144
+ }
145
+
146
+ // Append thread to thread list
147
+ _glfwAppendThread( t );
148
+
149
+ // Leave critical section
150
+ LEAVE_THREAD_CRITICAL_SECTION
151
+
152
+ // Return the GLFW thread ID
153
+ return ID;
154
+
155
+ #else
156
+
157
+ return -1;
158
+
159
+ #endif // _GLFW_HAS_PTHREAD
160
+ }
161
+
162
+
163
+ //========================================================================
164
+ // _glfwPlatformDestroyThread() - Kill a thread. NOTE: THIS IS A VERY
165
+ // DANGEROUS OPERATION, AND SHOULD NOT BE USED EXCEPT IN EXTREME
166
+ // SITUATIONS!
167
+ //========================================================================
168
+
169
+ void _glfwPlatformDestroyThread( GLFWthread ID )
170
+ {
171
+ #ifdef _GLFW_HAS_PTHREAD
172
+
173
+ _GLFWthread *t;
174
+
175
+ // Enter critical section
176
+ ENTER_THREAD_CRITICAL_SECTION
177
+
178
+ // Get thread information pointer
179
+ t = _glfwGetThreadPointer( ID );
180
+ if( t == NULL )
181
+ {
182
+ LEAVE_THREAD_CRITICAL_SECTION
183
+ return;
184
+ }
185
+
186
+ // Simply murder the process, no mercy!
187
+ pthread_kill( t->PosixID, SIGKILL );
188
+
189
+ // Remove thread from thread list
190
+ _glfwRemoveThread( t );
191
+
192
+ // Leave critical section
193
+ LEAVE_THREAD_CRITICAL_SECTION
194
+
195
+ #endif // _GLFW_HAS_PTHREAD
196
+ }
197
+
198
+
199
+ //========================================================================
200
+ // _glfwPlatformWaitThread() - Wait for a thread to die
201
+ //========================================================================
202
+
203
+ int _glfwPlatformWaitThread( GLFWthread ID, int waitmode )
204
+ {
205
+ #ifdef _GLFW_HAS_PTHREAD
206
+
207
+ pthread_t thread;
208
+ _GLFWthread *t;
209
+
210
+ // Enter critical section
211
+ ENTER_THREAD_CRITICAL_SECTION
212
+
213
+ // Get thread information pointer
214
+ t = _glfwGetThreadPointer( ID );
215
+
216
+ // Is the thread already dead?
217
+ if( t == NULL )
218
+ {
219
+ LEAVE_THREAD_CRITICAL_SECTION
220
+ return GL_TRUE;
221
+ }
222
+
223
+ // If got this far, the thread is alive => polling returns FALSE
224
+ if( waitmode == GLFW_NOWAIT )
225
+ {
226
+ LEAVE_THREAD_CRITICAL_SECTION
227
+ return GL_FALSE;
228
+ }
229
+
230
+ // Get thread handle
231
+ thread = t->PosixID;
232
+
233
+ // Leave critical section
234
+ LEAVE_THREAD_CRITICAL_SECTION
235
+
236
+ // Wait for thread to die
237
+ (void) pthread_join( thread, NULL );
238
+
239
+ return GL_TRUE;
240
+
241
+ #else
242
+
243
+ return GL_TRUE;
244
+
245
+ #endif // _GLFW_HAS_PTHREAD
246
+ }
247
+
248
+
249
+ //========================================================================
250
+ // _glfwPlatformGetThreadID() - Return the thread ID for the current
251
+ // thread
252
+ //========================================================================
253
+
254
+ GLFWthread _glfwPlatformGetThreadID( void )
255
+ {
256
+ #ifdef _GLFW_HAS_PTHREAD
257
+
258
+ _GLFWthread *t;
259
+ GLFWthread ID = -1;
260
+ pthread_t posixID;
261
+
262
+ // Get current thread ID
263
+ posixID = pthread_self();
264
+
265
+ // Enter critical section
266
+ ENTER_THREAD_CRITICAL_SECTION
267
+
268
+ // Loop through entire list of threads to find the matching POSIX
269
+ // thread ID
270
+ for( t = &_glfwThrd.First; t != NULL; t = t->Next )
271
+ {
272
+ if( t->PosixID == posixID )
273
+ {
274
+ ID = t->ID;
275
+ break;
276
+ }
277
+ }
278
+
279
+ // Leave critical section
280
+ LEAVE_THREAD_CRITICAL_SECTION
281
+
282
+ // Return the found GLFW thread identifier
283
+ return ID;
284
+
285
+ #else
286
+
287
+ return 0;
288
+
289
+ #endif // _GLFW_HAS_PTHREAD
290
+ }
291
+
292
+
293
+ //========================================================================
294
+ // _glfwPlatformCreateMutex() - Create a mutual exclusion object
295
+ //========================================================================
296
+
297
+ GLFWmutex _glfwPlatformCreateMutex( void )
298
+ {
299
+ #ifdef _GLFW_HAS_PTHREAD
300
+
301
+ pthread_mutex_t *mutex;
302
+
303
+ // Allocate memory for mutex
304
+ mutex = (pthread_mutex_t *) malloc( sizeof( pthread_mutex_t ) );
305
+ if( !mutex )
306
+ {
307
+ return NULL;
308
+ }
309
+
310
+ // Initialise a mutex object
311
+ (void) pthread_mutex_init( mutex, NULL );
312
+
313
+ // Cast to GLFWmutex and return
314
+ return (GLFWmutex) mutex;
315
+
316
+ #else
317
+
318
+ return (GLFWmutex) 0;
319
+
320
+ #endif // _GLFW_HAS_PTHREAD
321
+ }
322
+
323
+
324
+ //========================================================================
325
+ // _glfwPlatformDestroyMutex() - Destroy a mutual exclusion object
326
+ //========================================================================
327
+
328
+ void _glfwPlatformDestroyMutex( GLFWmutex mutex )
329
+ {
330
+ #ifdef _GLFW_HAS_PTHREAD
331
+
332
+ // Destroy the mutex object
333
+ pthread_mutex_destroy( (pthread_mutex_t *) mutex );
334
+
335
+ // Free memory for mutex object
336
+ free( (void *) mutex );
337
+
338
+ #endif // _GLFW_HAS_PTHREAD
339
+ }
340
+
341
+
342
+ //========================================================================
343
+ // _glfwPlatformLockMutex() - Request access to a mutex
344
+ //========================================================================
345
+
346
+ void _glfwPlatformLockMutex( GLFWmutex mutex )
347
+ {
348
+ #ifdef _GLFW_HAS_PTHREAD
349
+
350
+ // Wait for mutex to be released
351
+ (void) pthread_mutex_lock( (pthread_mutex_t *) mutex );
352
+
353
+ #endif // _GLFW_HAS_PTHREAD
354
+ }
355
+
356
+
357
+ //========================================================================
358
+ // _glfwPlatformUnlockMutex() - Release a mutex
359
+ //========================================================================
360
+
361
+ void _glfwPlatformUnlockMutex( GLFWmutex mutex )
362
+ {
363
+ #ifdef _GLFW_HAS_PTHREAD
364
+
365
+ // Release mutex
366
+ pthread_mutex_unlock( (pthread_mutex_t *) mutex );
367
+
368
+ #endif // _GLFW_HAS_PTHREAD
369
+ }
370
+
371
+
372
+ //========================================================================
373
+ // _glfwPlatformCreateCond() - Create a new condition variable object
374
+ //========================================================================
375
+
376
+ GLFWcond _glfwPlatformCreateCond( void )
377
+ {
378
+ #ifdef _GLFW_HAS_PTHREAD
379
+
380
+ pthread_cond_t *cond;
381
+
382
+ // Allocate memory for condition variable
383
+ cond = (pthread_cond_t *) malloc( sizeof(pthread_cond_t) );
384
+ if( !cond )
385
+ {
386
+ return NULL;
387
+ }
388
+
389
+ // Initialise condition variable
390
+ (void) pthread_cond_init( cond, NULL );
391
+
392
+ // Cast to GLFWcond and return
393
+ return (GLFWcond) cond;
394
+
395
+ #else
396
+
397
+ return (GLFWcond) 0;
398
+
399
+ #endif // _GLFW_HAS_PTHREAD
400
+ }
401
+
402
+
403
+ //========================================================================
404
+ // _glfwPlatformDestroyCond() - Destroy a condition variable object
405
+ //========================================================================
406
+
407
+ void _glfwPlatformDestroyCond( GLFWcond cond )
408
+ {
409
+ #ifdef _GLFW_HAS_PTHREAD
410
+
411
+ // Destroy the condition variable object
412
+ (void) pthread_cond_destroy( (pthread_cond_t *) cond );
413
+
414
+ // Free memory for condition variable object
415
+ free( (void *) cond );
416
+
417
+ #endif // _GLFW_HAS_PTHREAD
418
+ }
419
+
420
+
421
+ //========================================================================
422
+ // _glfwPlatformWaitCond() - Wait for a condition to be raised
423
+ //========================================================================
424
+
425
+ void _glfwPlatformWaitCond( GLFWcond cond, GLFWmutex mutex,
426
+ double timeout )
427
+ {
428
+ #ifdef _GLFW_HAS_PTHREAD
429
+
430
+ struct timeval currenttime;
431
+ struct timespec wait;
432
+ long dt_sec, dt_usec;
433
+
434
+ // Select infinite or timed wait
435
+ if( timeout >= GLFW_INFINITY )
436
+ {
437
+ // Wait for condition (infinite wait)
438
+ (void) pthread_cond_wait( (pthread_cond_t *) cond,
439
+ (pthread_mutex_t *) mutex );
440
+ }
441
+ else
442
+ {
443
+ // Set timeout time, relatvie to current time
444
+ gettimeofday( &currenttime, NULL );
445
+ dt_sec = (long) timeout;
446
+ dt_usec = (long) ((timeout - (double)dt_sec) * 1000000.0);
447
+ wait.tv_nsec = (currenttime.tv_usec + dt_usec) * 1000L;
448
+ if( wait.tv_nsec > 1000000000L )
449
+ {
450
+ wait.tv_nsec -= 1000000000L;
451
+ dt_sec ++;
452
+ }
453
+ wait.tv_sec = currenttime.tv_sec + dt_sec;
454
+
455
+ // Wait for condition (timed wait)
456
+ (void) pthread_cond_timedwait( (pthread_cond_t *) cond,
457
+ (pthread_mutex_t *) mutex, &wait );
458
+ }
459
+
460
+ #endif // _GLFW_HAS_PTHREAD
461
+ }
462
+
463
+
464
+ //========================================================================
465
+ // _glfwPlatformSignalCond() - Signal a condition to one waiting thread
466
+ //========================================================================
467
+
468
+ void _glfwPlatformSignalCond( GLFWcond cond )
469
+ {
470
+ #ifdef _GLFW_HAS_PTHREAD
471
+
472
+ // Signal condition
473
+ (void) pthread_cond_signal( (pthread_cond_t *) cond );
474
+
475
+ #endif // _GLFW_HAS_PTHREAD
476
+ }
477
+
478
+
479
+ //========================================================================
480
+ // _glfwPlatformBroadcastCond() - Broadcast a condition to all waiting
481
+ // threads
482
+ //========================================================================
483
+
484
+ void _glfwPlatformBroadcastCond( GLFWcond cond )
485
+ {
486
+ #ifdef _GLFW_HAS_PTHREAD
487
+
488
+ // Broadcast condition
489
+ (void) pthread_cond_broadcast( (pthread_cond_t *) cond );
490
+
491
+ #endif // _GLFW_HAS_PTHREAD
492
+ }
493
+
494
+
495
+ //========================================================================
496
+ // _glfwPlatformGetNumberOfProcessors() - Return the number of processors
497
+ // in the system.
498
+ //========================================================================
499
+
500
+ int _glfwPlatformGetNumberOfProcessors( void )
501
+ {
502
+ int n;
503
+
504
+ // Get number of processors online
505
+ _glfw_numprocessors( n );
506
+ return n;
507
+ }