Merge lp:~armagetronad-dev/armagetronad/trunk-armagetronad-boostthread into lp:~armagetronad-dev/armagetronad/trunk-armagetronad-work

Proposed by Manuel Moos
Status: Merged
Merged at revision: 1102
Proposed branch: lp:~armagetronad-dev/armagetronad/trunk-armagetronad-boostthread
Merge into: lp:~armagetronad-dev/armagetronad/trunk-armagetronad-work
Diff against target: 1487 lines (+519/-454)
22 files modified
MacOS/Armagetron Advanced.xcodeproj/project.pbxproj (+12/-0)
acinclude.m4 (+0/-224)
configure.ac (+8/-9)
src/Makefile.am (+3/-0)
src/macosx/config_common.h (+3/-0)
src/macosx/dedicated/aa_config.h (+1/-0)
src/network/nAuthentication.cpp (+37/-64)
src/tools/pthread-binding.h (+0/-82)
src/tools/tError.cpp (+1/-1)
src/tools/tLockedQueue.h (+74/-0)
src/tools/tMemManager.cpp (+7/-31)
src/tools/tMutex.cpp (+82/-0)
src/tools/tMutex.h (+150/-0)
src/tools/tSafePTR.h (+8/-8)
src/tools/tThread.h (+105/-0)
src/tools/tToDo.cpp (+8/-23)
src/win32/config_common.h (+4/-0)
src/win32_ded/aa_config.h (+0/-1)
win32/code_blocks/ArmagetronAd.cbp (+5/-3)
win32/code_blocks/ArmagetronAd.workspace (+1/-2)
win32/code_blocks/Dedicated.cbp (+5/-3)
win32/code_blocks/Master.cbp (+5/-3)
To merge this branch: bzr merge lp:~armagetronad-dev/armagetronad/trunk-armagetronad-boostthread
Reviewer Review Type Date Requested Status
dlh Approve
Review via email: mp+72885@code.launchpad.net

Description of the change

Switching from zthread to boost::thread which is better maintained and easier to install on Unix.
Windows is a little bit of a PITA, but only for the winlibs maintainer (the static library needs to be built with bjam, which first needs to be compiled itself), no change for the game builder, though.

Left todo: the mac side. For the time being, the bits we use can be emulated by a tiny pthread wrapper in the main source which should work fine (we're just using threads, two mutex types and two lock types), but it's only a matter of time before someone gets the idea to use futures and whatnot.

To post a comment you must log in.
1076. By dlh

Add new thread files to Mac OS X project.

1077. By dlh

Use pthreads. Building the boost thread library as a universal binary supporting Mac OS X 10.4 is tricky...

1078. By dlh

Enable authentication for Mac OS X dedicated servers

Revision history for this message
dlh (dlh) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'MacOS/Armagetron Advanced.xcodeproj/project.pbxproj'
2--- MacOS/Armagetron Advanced.xcodeproj/project.pbxproj 2011-08-01 00:57:22 +0000
3+++ MacOS/Armagetron Advanced.xcodeproj/project.pbxproj 2011-09-11 04:47:25 +0000
4@@ -136,6 +136,8 @@
5 9B9755160F44B0DE00E41662 /* nBinary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9B9755140F44B0DE00E41662 /* nBinary.cpp */; };
6 9B9755170F44B0DE00E41662 /* nBinary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9B9755140F44B0DE00E41662 /* nBinary.cpp */; };
7 9B97553D0F44B3EC00E41662 /* libarmaprotobuf.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9B97546A0F44AA2700E41662 /* libarmaprotobuf.a */; };
8+ 9BB084E4141C5FED009B30D0 /* tMutex.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9BB084E1141C5FED009B30D0 /* tMutex.cpp */; };
9+ 9BB084E5141C5FED009B30D0 /* tMutex.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9BB084E1141C5FED009B30D0 /* tMutex.cpp */; };
10 9BB7B4000D8246A2004FE8C3 /* config in CopyFiles */ = {isa = PBXBuildFile; fileRef = 9BD7DAE20A2CAE0700D7033C /* config */; };
11 9BB7B4010D8246A2004FE8C3 /* language in CopyFiles */ = {isa = PBXBuildFile; fileRef = 9BD7DAFE0A2CAE1D00D7033C /* language */; };
12 9BB7B5E10D8302FA004FE8C3 /* eAdvWall.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9BB7B5A60D8302FA004FE8C3 /* eAdvWall.cpp */; };
13@@ -631,6 +633,10 @@
14 9B9755140F44B0DE00E41662 /* nBinary.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = nBinary.cpp; sourceTree = "<group>"; };
15 9B9755150F44B0DE00E41662 /* nBinary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nBinary.h; sourceTree = "<group>"; };
16 9B9E56300D81D962008DD17D /* shared.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = shared.xcconfig; sourceTree = "<group>"; };
17+ 9BB084E0141C5FED009B30D0 /* tLockedQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tLockedQueue.h; sourceTree = "<group>"; };
18+ 9BB084E1141C5FED009B30D0 /* tMutex.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = tMutex.cpp; sourceTree = "<group>"; };
19+ 9BB084E2141C5FED009B30D0 /* tMutex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tMutex.h; sourceTree = "<group>"; };
20+ 9BB084E3141C5FED009B30D0 /* tThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tThread.h; sourceTree = "<group>"; };
21 9BB5B9240D84604400BF5F1C /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = ../src/macosx/Info.plist; sourceTree = SOURCE_ROOT; };
22 9BB5B9270D84605700BF5F1C /* English */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = English; path = InfoPlist.strings.in; sourceTree = "<group>"; };
23 9BB7B5A60D8302FA004FE8C3 /* eAdvWall.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = eAdvWall.cpp; sourceTree = "<group>"; };
24@@ -1421,11 +1427,14 @@
25 9BB7B7C50D830422004FE8C3 /* tList.h */,
26 9BB7B7C60D830422004FE8C3 /* tLocale.cpp */,
27 9BB7B7C70D830422004FE8C3 /* tLocale.h */,
28+ 9BB084E0141C5FED009B30D0 /* tLockedQueue.h */,
29 9BB7B7C80D830422004FE8C3 /* tMath.h */,
30 9BB7B7C90D830422004FE8C3 /* tMemManager.cpp */,
31 9BB7B7CA0D830422004FE8C3 /* tMemManager.h */,
32 9BB7B7CB0D830422004FE8C3 /* tMemStack.cpp */,
33 9BB7B7CC0D830422004FE8C3 /* tMemStack.h */,
34+ 9BB084E1141C5FED009B30D0 /* tMutex.cpp */,
35+ 9BB084E2141C5FED009B30D0 /* tMutex.h */,
36 9BB7B7CD0D830422004FE8C3 /* tPlayList.cpp */,
37 9BB7B7CE0D830422004FE8C3 /* tPlayList.h */,
38 9B9754D90F44AFB700E41662 /* tPolynomial.cpp */,
39@@ -1457,6 +1466,7 @@
40 9BB7B7EA0D830422004FE8C3 /* tString.h */,
41 9BB7B7EB0D830422004FE8C3 /* tSysTime.cpp */,
42 9BB7B7EC0D830422004FE8C3 /* tSysTime.h */,
43+ 9BB084E3141C5FED009B30D0 /* tThread.h */,
44 9BB7B7ED0D830422004FE8C3 /* tToDo.cpp */,
45 9BB7B7EE0D830422004FE8C3 /* tToDo.h */,
46 9BB7B7EF0D830422004FE8C3 /* tValue.h */,
47@@ -2035,6 +2045,7 @@
48 9B62588C0F5865410083C429 /* zFortress.cpp in Sources */,
49 9B62588D0F5865410083C429 /* zTimedZone.cpp in Sources */,
50 9B0C8B3E0F7EBA78001802CD /* eChat.cpp in Sources */,
51+ 9BB084E5141C5FED009B30D0 /* tMutex.cpp in Sources */,
52 );
53 runOnlyForDeploymentPostprocessing = 0;
54 };
55@@ -2202,6 +2213,7 @@
56 9B62588A0F5865410083C429 /* zFortress.cpp in Sources */,
57 9B62588B0F5865410083C429 /* zTimedZone.cpp in Sources */,
58 9B0C8B3D0F7EBA78001802CD /* eChat.cpp in Sources */,
59+ 9BB084E4141C5FED009B30D0 /* tMutex.cpp in Sources */,
60 );
61 runOnlyForDeploymentPostprocessing = 0;
62 };
63
64=== modified file 'acinclude.m4'
65--- acinclude.m4 2009-07-15 07:17:41 +0000
66+++ acinclude.m4 2011-09-11 04:47:25 +0000
67@@ -555,230 +555,6 @@
68 fi
69 ])
70
71-dnl Modified ZThread test follows. This one works, AM_PATH_ZTHREAD alone does not.
72-dnl Changes: hacked compiler temporarily to use CXX instead of CC
73-dnl added zthread/ to include path
74-dnl added #include "zthread/Task.h" and #include "zthread/Thread.h"
75-dnl added HAVE_LIBZTHREAD define
76-
77-dnl Copyright (c) 2005, Eric Crahen
78-dnl
79-dnl Permission is hereby granted, free of charge, to any person obtaining a copy
80-dnl of this software and associated documentation files (the "Software"), to deal
81-dnl in the Software without restriction, including without limitation the rights
82-dnl to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
83-dnl copies of the Software, and to permit persons to whom the Software is furnished
84-dnl to do so, subject to the following conditions:
85-dnl
86-dnl The above copyright notice and this permission notice shall be included in all
87-dnl copies or substantial portions of the Software.
88-dnl
89-dnl THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
90-dnl IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
91-dnl FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
92-dnl AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
93-dnl WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
94-dnl CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
95-
96-dnl Detect the library and include paths for ZThreads, perform some test
97-dnl compilations.
98-dnl
99-dnl Should be used in AC_PROG_CC mode before the swtich to C++ if any is made
100-dnl (eg before AC_LANG_CPLUSPLUS)
101-dnl
102-dnl --with-zthread-prefix : Skip detection, use this general path
103-dnl --with-zthread-exec-prefix : Skip detecting the zthread-config tool
104-dnl
105-dnl Sets the following variables.
106-dnl
107-dnl ZTHREAD_CXXFLAGS
108-dnl ZTHREAD_LIBS
109-dnl
110-AC_DEFUN([AM_PATH_ZTHREAD_AA],
111-[
112-
113-
114-AC_ARG_WITH(zthread-prefix,[ --with-zthread-prefix=PFX Prefix where ZTHREAD is installed (optional)],
115- zthread_prefix="$withval", zthread_prefix="")
116-AC_ARG_WITH(zthread-exec-prefix,[ --with-zthread-exec-prefix=PFX Exec prefix where ZTHREAD is installed (optional)],
117- zthread_exec_prefix="$withval", zthread_exec_prefix="")
118-AC_ARG_ENABLE(zthreadtest, [ --disable-zthreadtest Do not try to compile and run a test ZTHREAD program],
119- , enable_zthreadtest=yes)
120-
121- if test x$zthread_exec_prefix != x ; then
122- zthread_args="$zthread_args --exec-prefix=$zthread_exec_prefix"
123- if test x${ZTHREAD_CONFIG+set} != xset ; then
124- ZTHREAD_CONFIG=$zthread_exec_prefix/bin/zthread-config
125- fi
126- fi
127- if test x$zthread_prefix != x ; then
128- zthread_args="$zthread_args --prefix=$zthread_prefix"
129- if test x${ZTHREAD_CONFIG+set} != xset ; then
130- ZTHREAD_CONFIG=$zthread_prefix/bin/zthread-config
131- fi
132- fi
133-
134- AC_PATH_PROG(ZTHREAD_CONFIG, zthread-config, no)
135- min_zthread_version=ifelse([$1], ,0.11.0,$1)
136- AC_MSG_CHECKING(for ZTHREAD - version >= $min_zthread_version)
137- no_zthread=""
138- if test "$ZTHREAD_CONFIG" = "no" ; then
139- no_zthread=yes
140- else
141- ZTHREAD_CXXFLAGS=`$ZTHREAD_CONFIG $zthreadconf_args --cflags`
142- ZTHREAD_LIBS=`$ZTHREAD_CONFIG $zthreadconf_args --libs`
143-
144- zthread_major_version=`$ZTHREAD_CONFIG $zthread_args --version | \
145- sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
146- zthread_minor_version=`$ZTHREAD_CONFIG $zthread_args --version | \
147- sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
148- zthread_micro_version=`$ZTHREAD_CONFIG $zthread_config_args --version | \
149- sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
150- if test "x$enable_zthreadtest" = "xyes" ; then
151- ac_save_CXXFLAGS="$CXXFLAGS"
152- ac_save_CFLAGS="$CFLAGS"
153- ac_save_LIBS="$LIBS"
154- CXXFLAGS="$CXXFLAGS $ZTHREAD_CXXFLAGS"
155- CFLAGS="$CFLAGS $ZTHREAD_CXXFLAGS"
156- LIBS="$LIBS $ZTHREAD_LIBS"
157-
158-dnl
159-dnl Now check if the installed ZTHREAD is sufficiently new. (Also sanity
160-dnl checks the results of zthread-config to some extent
161-dnl
162- rm -f conf.zthreadtest
163- CC_OLD=${CC}
164- CC=${CXX}
165- for extra_flags in "NONE" "-fpermissive"; do
166- if test NONE != ${extra_flags}; then
167- ZTHREAD_CXXFLAGS="$ZTHREAD_CXXFLAGS ${extra_flags}"
168- CXXFLAGS="$CXXFLAGS ${extra_flags}"
169- CFLAGS="$CFLAGS ${extra_flags}"
170- fi
171- if test "x$no_zthread" = xyes || test NONE = ${extra_flags} ; then
172- no_zthread=""
173- AC_TRY_RUN([
174-
175-
176-#include <stdio.h>
177-#include <string.h>
178-#include <unistd.h>
179-#include "zthread/Task.h"
180-#include "zthread/Thread.h"
181-#include "zthread/ZThread.h"
182-
183-int main (int argc, char *argv[]) {
184-
185- int major, minor, micro;
186- char tmp_version[256];
187-
188- { FILE *fp = fopen("conf.zthreadtest", "a"); if ( fp ) fclose(fp); }
189-
190-
191- /* HP/UX 9 (%@#!) writes to sscanf strings */
192- strcpy(tmp_version, "$min_zthread_version");
193-
194- if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
195-
196- printf("%s, bad version string\n", "$min_zthread_version");
197- return 1;
198-
199- }
200-
201- if (($zthread_major_version > major) ||
202- (($zthread_major_version == major) && ($zthread_minor_version > minor)) ||
203- (($zthread_major_version == major) && ($zthread_minor_version == minor) &&
204- ($zthread_micro_version >= micro))) {
205- return 0;
206- } else {
207-
208- printf("\n*** 'zthread-config --version' returned %d.%d.%d, but the minimum version\n", $zthread_major_version, $zthread_minor_version, $zthread_micro_version);
209- printf("*** of ZThread required is %d.%d.%d. If zthread-config is correct, then it is\n", major, minor, micro);
210- printf("*** best to upgrade to the required version.\n");
211- printf("*** If zthread-config was wrong, set the environment variable ZTHREAD_CONFIG\n");
212- printf("*** to point to the correct copy of zthread-config, and remove the file\n");
213- printf("*** config.cache before re-running configure\n");
214-
215- return 1;
216- }
217-
218-}
219-
220-],, no_zthread=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
221- fi
222- done
223- CC=${CC_OLD}
224- CXXFLAGS="$ac_save_CXXFLAGS"
225- LIBS="$ac_save_LIBS"
226- fi
227- fi
228-
229- if test "x$no_zthread" = x ; then
230-
231- AC_DEFINE(HAVE_LIBZTHREAD,[], [Define if you have the library ZThread.])
232- AC_MSG_RESULT(yes)
233- ifelse([$2], , :, [$2])
234-
235- else
236-
237- AC_MSG_RESULT(no)
238-
239- if test "$ZTHREAD_CONFIG" = "no" ; then
240-
241- echo "*** The zthread-config script installed by ZThread could not be found"
242- echo "*** If ZThread was installed in PREFIX, make sure PREFIX/bin is in"
243- echo "*** your path, or set the ZTHREAD_CONFIG environment variable to the"
244- echo "*** full path to zthread-config."
245-
246- else
247- if test -f conf.zthreadtest ; then
248- :
249- else
250-
251- echo "*** Could not run ZThread test program, checking why..."
252- CC_OLD=${CC}
253- CC=${CXX}
254- CXXFLAGS="$CXXFLAGS $ZTHREAD_CXXFLAGS"
255- LIBS="$LIBS $ZTHREAD_LIBS"
256-
257- echo $LIBS;
258-
259- AC_TRY_LINK([#include "zthread/Task.h"],
260- [ return 0; ], [
261- echo "*** The test program compiled, but did not run. This usually means"
262- echo "*** that the run-time linker is not finding ZThread or finding the wrong"
263- echo "*** version of ZThread. If it is not finding ZThread, you'll need to set your"
264- echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
265- echo "*** to the installed location Also, make sure you have run ldconfig if that"
266- echo "*** is required on your system"
267- echo "***"
268- echo "*** If you have an old version installed, it is best to remove it, although"
269- echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
270- [ echo "*** The test program failed to compile or link. See the file config.log for the"
271- echo "*** exact error that occured. This usually means ZThread was incorrectly installed"
272- echo "*** or that you have moved ZThread since it was installed. In the latter case, you"
273- echo "*** may want to edit the zthread-config script: $ZTHREAD_CONFIG" ])
274-
275- CC=${CC_OLD}
276- CFLAGS="$ac_save_CFLAGS"
277- CXXFLAGS="$ac_save_CXXFLAGS"
278- LIBS="$ac_save_LIBS"
279- fi
280- fi
281-
282- ZTHREAD_CXXFLAGS=""
283- ZTHREAD_LIBS=""
284- ifelse([$3], , :, [$3])
285-
286- fi
287-
288- AC_SUBST(ZTHREAD_CXXFLAGS)
289- AC_SUBST(ZTHREAD_LIBS)
290-
291- rm -f conf.zthreadtest
292-
293-])
294-
295 dnl Copyright © 2008 Steven G. Johnson <stevenj@alum.mit.edu>
296 dnl This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
297 dnl This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
298
299=== modified file 'configure.ac'
300--- configure.ac 2011-08-26 15:34:37 +0000
301+++ configure.ac 2011-09-11 04:47:25 +0000
302@@ -670,26 +670,25 @@
303
304 AC_LANG([C++])
305
306+AC_CHECK_LIB([boost_thread],_ZNK5boost6thread6get_idEv,,[
307+
308 ACX_PTHREAD([
309
310 LIBS="${PTHREAD_LIBS} ${LIBS}"
311 CXXFLAGS="${CXXFLAGS} ${PTHREAD_CFLAGS}"
312 CC="${PTHREAD_CC}"
313-dnl AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.])
314-
315-],[
316-
317-AM_PATH_ZTHREAD_AA(2.3.2)
318-CXXFLAGS="${CXXFLAGS} ${ZTHREAD_CXXFLAGS}"
319-LIBS="${LIBS} ${ZTHREAD_LIBS}"
320+AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.])
321+
322+],)
323
324 ])
325
326-fi # krawall
327+
328+fi # armathentication
329
330
331 dnl *************************************************
332-dnl pattern buffers
333+dnl protocol buffers
334 dnl *************************************************
335
336 dnl check for compiler
337
338=== modified file 'src/Makefile.am'
339--- src/Makefile.am 2011-08-26 13:48:33 +0000
340+++ src/Makefile.am 2011-09-11 04:47:25 +0000
341@@ -89,6 +89,9 @@
342 tools/tRectangle.h tools/tRectangle.cpp \
343 tools/tPlayList.h tools/tPlayList.cpp\
344 tools/tDecorator.h tools/tDecorator.cpp\
345+ tools/tMutex.h tools/tMutex.cpp\
346+ tools/tThread.h\
347+ tools/tLockedQueue.h\
348 tools/tCoord.h tools/tCoord.cpp\
349 tools/tValue.h tools/tValueParser.h\
350 tools/tFunction.h tools/tFunction.cpp\
351
352=== modified file 'src/macosx/config_common.h'
353--- src/macosx/config_common.h 2008-03-09 18:02:20 +0000
354+++ src/macosx/config_common.h 2011-09-11 04:47:25 +0000
355@@ -174,3 +174,6 @@
356
357 /* Define to empty if `const' does not conform to ANSI C. */
358 /* #undef const */
359+
360+//#define HAVE_LIBBOOST_THREAD 1
361+#define HAVE_PTHREAD 1
362
363=== modified file 'src/macosx/dedicated/aa_config.h'
364--- src/macosx/dedicated/aa_config.h 2006-11-11 13:12:48 +0000
365+++ src/macosx/dedicated/aa_config.h 2011-09-11 04:47:25 +0000
366@@ -2,3 +2,4 @@
367
368 #define USER_DATA_DIR "~/Library/Application Support/Armagetron Advanced Dedicated"
369 #define DEDICATED 1
370+#define KRAWALL_SERVER 1
371
372=== modified file 'src/network/nAuthentication.cpp'
373--- src/network/nAuthentication.cpp 2011-01-01 18:14:12 +0000
374+++ src/network/nAuthentication.cpp 2011-09-11 04:47:25 +0000
375@@ -46,26 +46,10 @@
376
377 #include <deque>
378
379-#ifdef HAVE_LIBZTHREAD
380-#include <zthread/Thread.h>
381-#include <zthread/LockedQueue.h>
382-//#include <zthread/ClassLockable.h>
383-#include <zthread/FastMutex.h>
384-#include <zthread/FastRecursiveMutex.h>
385-#include <zthread/Guard.h>
386-// #include <zthread/SynchronousExecutor.h>
387-#include <zthread/ThreadedExecutor.h>
388-typedef ZThread::ThreadedExecutor nExecutor;
389-//typedef ZThread::SynchronousExecutor nExecutor;
390-typedef ZThread::FastMutex nMutex;
391-#define nQueue ZThread::LockedQueue
392-#elif defined(HAVE_PTHREAD)
393-#include "pthread-binding.h"
394-typedef tPThreadMutex nMutex;
395-#define nQueue tPThreadQueue
396-#else
397-typedef tNonMutex nMutex;
398-#endif
399+#include "tLockedQueue.h"
400+
401+#include "tThread.h"
402+#include "tMutex.h"
403
404 bool sn_supportRemoteLogins = false;
405
406@@ -216,17 +200,8 @@
407
408 //! template that runs void member functions of reference countable objects
409 template< class T > class nMemberFunctionRunnerTemplate
410-#ifdef HAVE_LIBZTHREAD
411- : public ZThread::Runnable
412-#endif
413 {
414 private:
415-#if defined(HAVE_PTHREAD) && !defined(HAVE_LIBZTHREAD)
416- static void* DoCall( void *o ) {
417- nMemberFunctionRunnerTemplate * functionRunner = (nMemberFunctionRunnerTemplate*) o;
418- ( (functionRunner->object_)->*(functionRunner->function_) )();
419- }
420-#endif
421 public:
422 nMemberFunctionRunnerTemplate( T & object, void (T::*function)() )
423 : object_( &object ), function_( function )
424@@ -239,6 +214,11 @@
425 (object_->*function_)();
426 }
427
428+ void operator () ()
429+ {
430+ run();
431+ }
432+
433 //! schedule a task for execution at the next convenient break, between game rounds for example
434 static void ScheduleBreak( T & object, void (T::*function)() )
435 {
436@@ -248,19 +228,15 @@
437 //! schedule a task for execution in a background thread
438 static void ScheduleBackground( T & object, void (T::*function)() )
439 {
440-#if defined(HAVE_LIBZTHREAD) || defined(HAVE_PTHREAD)
441+ bool delays = true;
442+#ifdef HAVE_THREADS
443+ delays = tRecorder::IsRunning();
444+#endif
445+
446 // schedule the task into a background thread
447- if ( !tRecorder::IsRunning() )
448+ if ( !delays )
449 {
450-#if !defined(HAVE_LIBZTHREAD)
451- nMemberFunctionRunnerTemplate<T> * runner = new nMemberFunctionRunnerTemplate<T>( object, function );
452-
453- pthread_t thread;
454- pthread_create(&thread, NULL, (nMemberFunctionRunnerTemplate::DoCall), (void*) runner);
455-#else
456- static nExecutor executor;
457- executor.execute( ZThread::Task( new nMemberFunctionRunnerTemplate( object, function ) ) );
458-#endif
459+ boost::thread(nMemberFunctionRunnerTemplate<T>( object, function ) );
460 }
461 else
462 {
463@@ -268,23 +244,13 @@
464 ScheduleBreak( object, function );
465
466 }
467-#else
468- // do it when you can without getting interrupted.
469- ScheduleBreak( object, function );
470-#endif
471 }
472
473 //! schedule a task for execution in the next tToDo call
474 static void ScheduleForeground( T & object, void (T::*function)() )
475 {
476-#if defined(HAVE_LIBZTHREAD) || defined(HAVE_PTHREAD)
477 Pending().add( nMemberFunctionRunnerTemplate( object, function ) );
478 st_ToDo( FinishAll );
479-#else
480- // execute it immedeately
481- (object.*function)();
482-#endif
483-
484 }
485
486 // function that calls tasks scheduled for the next break
487@@ -314,25 +280,32 @@
488 // taks for the break
489 static std::deque< nMemberFunctionRunnerTemplate > pendingForBreak_;
490
491-#if defined(HAVE_LIBZTHREAD) || defined(HAVE_PTHREAD)
492+ typedef tLockedQueue< nMemberFunctionRunnerTemplate, boost::mutex > LockedQueue;
493+
494 // queue of foreground tasks
495- static nQueue< nMemberFunctionRunnerTemplate, nMutex > & Pending()
496+ static LockedQueue & Pending()
497 {
498- static nQueue< nMemberFunctionRunnerTemplate, nMutex > pending;
499+ static LockedQueue pending;
500 return pending;
501 }
502
503 // function that calls them
504 static void FinishAll()
505 {
506- // finish all pending tasks
507- while( Pending().size() > 0 )
508- {
509- nMemberFunctionRunnerTemplate next = Pending().next();
510- next.run();
511+ try
512+ {
513+ // finish all pending tasks
514+ while( Pending().size() > 0 )
515+ {
516+ nMemberFunctionRunnerTemplate next = Pending().next();
517+ next.run();
518+ }
519+ }
520+ catch( typename LockedQueue::Empty const & e )
521+ {
522+ // ignore, we just read over the end. No biggie.
523 }
524 }
525-#endif
526 };
527
528 template< class T >
529@@ -369,7 +342,7 @@
530 {
531 if ( block )
532 {
533-#if defined(HAVE_LIBZTHREAD) || defined(HAVE_PTHREAD)
534+#ifdef HAVE_THREADS
535 ScheduleBackground( object, function );
536 #else
537 ScheduleBreak( object, function );
538@@ -388,7 +361,7 @@
539 public nMachineDecorator,
540 public nKrawall::nCheckResult,
541 public nKrawall::nPasswordCheckData,
542- public tReferencable< nLoginProcess, nMutex >
543+ public tReferencable< nLoginProcess, boost::mutex >
544 {
545 // reference counting pointer
546 typedef tJUST_CONTROLLED_PTR< nLoginProcess > SelfPointer;
547@@ -400,9 +373,9 @@
548 // install self reference to keep this object alive
549 selfReference_ = this;
550
551- // inform the user about delays
552- bool delays = false;
553-#if defined(HAVE_LIBZTHREAD) || defined(HAVE_PTHREAD)
554+ // inform the user about delays
555+ bool delays = true;
556+#ifdef HAVE_THREADS
557 delays = tRecorder::IsRunning();
558 #endif
559 if ( delays )
560
561=== removed file 'src/tools/pthread-binding.h'
562--- src/tools/pthread-binding.h 2008-12-29 17:15:32 +0000
563+++ src/tools/pthread-binding.h 1970-01-01 00:00:00 +0000
564@@ -1,82 +0,0 @@
565-#include <deque>
566-#include <pthread.h>
567-#include <stdexcept>
568-
569-class tPThreadMutex
570-{
571-private:
572- pthread_mutex_t mutex;
573-public:
574- tPThreadMutex() {
575- // TODO: error checking
576- pthread_mutex_init(&mutex, NULL);
577- }
578- void acquire() {
579- pthread_mutex_lock(&mutex);
580- };
581- void release() {
582- pthread_mutex_unlock(&mutex);
583- };
584-};
585-
586-class tPThreadRecursiveMutex
587- : public tPThreadMutex
588-{
589-private:
590- pthread_mutex_t mutex;
591-public:
592- tPThreadRecursiveMutex() {
593- // TODO: error checking
594- pthread_mutexattr_t mta;
595-
596- pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE);
597- pthread_mutex_init(&mutex, &mta);
598- }
599-};
600-
601-template <class T>
602-class tPThreadGuard
603-{
604-private:
605- T*mutex;
606-public:
607- tPThreadGuard(T*m) {
608- mutex = m;
609- mutex->acquire();
610- };
611- ~tPThreadGuard() {
612- mutex->release();
613- };
614-};
615-
616-template <class T, class MutexT>
617-class tPThreadQueue
618-{
619- MutexT mutex;
620- std::deque<T> q;
621-public:
622- virtual void add(const T& item) {
623- tPThreadGuard<MutexT> mL(&mutex);
624-
625- q.push_back(item);
626- }
627-
628- virtual size_t size() {
629- tPThreadGuard<MutexT> mL(&mutex);
630-
631- return q.size();
632- }
633-
634- virtual T next() {
635- tPThreadGuard<MutexT> mL(&mutex);
636-
637- if(q.size() == 0)
638- // TODO: throw a specific exception?
639- throw std::exception();
640-
641- T item = q.front();
642- q.pop_front();
643-
644- return item;
645- }
646-};
647
648=== modified file 'src/tools/tError.cpp'
649--- src/tools/tError.cpp 2011-07-26 19:11:38 +0000
650+++ src/tools/tError.cpp 2011-09-11 04:47:25 +0000
651@@ -57,7 +57,7 @@
652 {
653 std::cerr << caption << ": " << message << "\n";
654 st_Breakpoint();
655- static bool error = false; // to disable the error if it is inconvenient right now and you think it may not be fatal
656+ static bool error = true; // to disable the error if it is inconvenient right now and you think it may not be fatal
657 if ( error )
658 {
659 // throw 1; //tSimpleException( message, caption );
660
661=== added file 'src/tools/tLockedQueue.h'
662--- src/tools/tLockedQueue.h 1970-01-01 00:00:00 +0000
663+++ src/tools/tLockedQueue.h 2011-09-11 04:47:25 +0000
664@@ -0,0 +1,74 @@
665+/*
666+
667+*************************************************************************
668+
669+ArmageTron -- Just another Tron Lightcycle Game in 3D.
670+Copyright (C) 2011 Armagetron Advanced Development Team
671+
672+**************************************************************************
673+
674+This program is free software; you can redistribute it and/or
675+modify it under the terms of the GNU General Public License
676+as published by the Free Software Foundation; either version 2
677+of the License, or (at your option) any later version.
678+
679+This program is distributed in the hope that it will be useful,
680+but WITHOUT ANY WARRANTY; without even the implied warranty of
681+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
682+GNU General Public License for more details.
683+
684+You should have received a copy of the GNU General Public License
685+along with this program; if not, write to the Free Software
686+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
687+
688+***************************************************************************
689+
690+*/
691+
692+#ifndef ArmageTron_LOCKED_QUEUE_H
693+#define ArmageTron_LOCKED_QUEUE_H
694+
695+#include "tMutex.h"
696+
697+#include <deque>
698+
699+//! thread safe queue
700+template< typename T, typename MUTEX >
701+class tLockedQueue
702+{
703+public:
704+ //! exception thrown if next() is called on an empty queue
705+ class Empty: public std::exception{};
706+
707+ void add(const T& item)
708+ {
709+ boost::lock_guard< MUTEX > lock(mutex_);
710+
711+ queue_.push_back(item);
712+ }
713+
714+ virtual size_t size()
715+ {
716+ boost::lock_guard< MUTEX > lock(mutex_);
717+
718+ return queue_.size();
719+ }
720+
721+ T next()
722+ {
723+ boost::lock_guard< MUTEX > lock(mutex_);
724+
725+ if(queue_.size() == 0)
726+ throw Empty();
727+
728+ T item = queue_.front();
729+ queue_.pop_front();
730+
731+ return item;
732+ }
733+private:
734+ std::deque<T> queue_;
735+ MUTEX mutex_;
736+};
737+
738+#endif
739
740=== modified file 'src/tools/tMemManager.cpp'
741--- src/tools/tMemManager.cpp 2011-07-10 18:22:34 +0000
742+++ src/tools/tMemManager.cpp 2011-09-11 04:47:25 +0000
743@@ -88,23 +88,9 @@
744
745 static bool reported=false;
746
747-#ifdef HAVE_LIBZTHREAD
748-#include <zthread/FastRecursiveMutex.h>
749-
750-static ZThread::FastRecursiveMutex st_mutex;
751-#elif defined(HAVE_PTHREAD)
752-#include "pthread-binding.h"
753-static tPThreadRecursiveMutex st_mutex;
754-#else
755-class tMockMutex
756-{
757-public:
758- void acquire(){}
759- void release(){}
760-};
761-
762-static tMockMutex st_mutex;
763-#endif
764+#include "tMutex.h"
765+
766+static boost::recursive_mutex st_mutex;
767
768 // create an object of this class while calling external functions
769 // that are known to have (harmless!) leaks
770@@ -122,15 +108,12 @@
771
772 class tBottleNeck
773 {
774+private:
775+ boost::lock_guard< boost::recursive_mutex > lock_;
776 public:
777 tBottleNeck()
778- {
779- st_mutex.acquire();
780- }
781-
782- ~tBottleNeck()
783- {
784- st_mutex.release();
785+ :lock_(st_mutex)
786+ {
787 }
788 };
789
790@@ -644,9 +627,6 @@
791 tMemManager::~tMemManager(){
792 #ifdef LEAKFINDER
793 static bool warn = true;
794-#ifdef HAVE_LIBZTHREAD
795- warn = false;
796-#endif
797
798 if (inited){
799 // l???sche das ding
800@@ -1306,10 +1286,8 @@
801 tAllocationInfo info( false );
802
803 #ifdef LEAKFINDER
804-#ifndef HAVE_LIBZTHREAD
805 info.checksum = size;
806 #endif
807-#endif
808 return tMemMan::Alloc(info, size);
809 }
810
811@@ -1377,10 +1355,8 @@
812 void* operator new[] (size_t size) THROW_BADALLOC{
813 tAllocationInfo info( true );
814 #ifdef LEAKFINDER
815-#ifndef HAVE_LIBZTHREAD
816 info.checksum = size % MAXCHECKSUM;
817 #endif
818-#endif
819 return tMemMan::Alloc(info, size);
820 }
821
822
823=== added file 'src/tools/tMutex.cpp'
824--- src/tools/tMutex.cpp 1970-01-01 00:00:00 +0000
825+++ src/tools/tMutex.cpp 2011-09-11 04:47:25 +0000
826@@ -0,0 +1,82 @@
827+/*
828+
829+*************************************************************************
830+
831+ArmageTron -- Just another Tron Lightcycle Game in 3D.
832+Copyright (C) 2005 by
833+the AA DevTeam (see the file AUTHORS(.txt) in the main source directory)
834+
835+**************************************************************************
836+
837+This program is free software; you can redistribute it and/or
838+modify it under the terms of the GNU General Public License
839+as published by the Free Software Foundation; either version 2
840+of the License, or (at your option) any later version.
841+
842+This program is distributed in the hope that it will be useful,
843+but WITHOUT ANY WARRANTY; without even the implied warranty of
844+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
845+GNU General Public License for more details.
846+
847+You should have received a copy of the GNU General Public License
848+along with this program; if not, write to the Free Software
849+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
850+
851+***************************************************************************
852+
853+*/
854+
855+#include "tMutex.h"
856+
857+#ifndef HAVE_LIBBOOST_THREAD
858+
859+namespace boost
860+{
861+ // special constructor, do not initialize mutex
862+ mutex::mutex( int )
863+ {
864+ }
865+
866+ mutex::mutex()
867+ {
868+#ifdef HAVE_REAL_MUTEX
869+ // TODO: error checking
870+ pthread_mutex_init(&mutex_, NULL);
871+#endif
872+ }
873+
874+ mutex::~mutex()
875+ {
876+#ifdef HAVE_REAL_MUTEX
877+ pthread_mutex_destroy(&mutex_);
878+#endif
879+ }
880+
881+ void mutex::lock()
882+ {
883+#ifdef HAVE_REAL_MUTEX
884+ pthread_mutex_lock(&mutex_);
885+#endif
886+ }
887+
888+ void mutex::unlock()
889+ {
890+#ifdef HAVE_REAL_MUTEX
891+ pthread_mutex_unlock(&mutex_);
892+#endif
893+ }
894+
895+ recursive_mutex::recursive_mutex()
896+ : mutex(5)
897+ {
898+#ifdef HAVE_REAL_MUTEX
899+ // TODO: error checking
900+ pthread_mutexattr_t mta;
901+
902+ pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE);
903+ pthread_mutex_init(&mutex_, &mta);
904+#endif
905+ }
906+}
907+
908+#endif
909
910=== added file 'src/tools/tMutex.h'
911--- src/tools/tMutex.h 1970-01-01 00:00:00 +0000
912+++ src/tools/tMutex.h 2011-09-11 04:47:25 +0000
913@@ -0,0 +1,150 @@
914+/*
915+
916+*************************************************************************
917+
918+ArmageTron -- Just another Tron Lightcycle Game in 3D.
919+Copyright (C) 2011 Armagetron Advanced Development Team
920+
921+**************************************************************************
922+
923+This program is free software; you can redistribute it and/or
924+modify it under the terms of the GNU General Public License
925+as published by the Free Software Foundation; either version 2
926+of the License, or (at your option) any later version.
927+
928+This program is distributed in the hope that it will be useful,
929+but WITHOUT ANY WARRANTY; without even the implied warranty of
930+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
931+GNU General Public License for more details.
932+
933+You should have received a copy of the GNU General Public License
934+along with this program; if not, write to the Free Software
935+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
936+
937+***************************************************************************
938+
939+*/
940+
941+#ifndef ArmageTron_TMUTEX_H
942+#define ArmageTron_TMUTEX_H
943+
944+#include "defs.h"
945+
946+#ifdef HAVE_LIBBOOST_THREAD
947+
948+#include <boost/thread/recursive_mutex.hpp>
949+#include <boost/thread/mutex.hpp>
950+#include <boost/thread/locks.hpp>
951+
952+#else // HAVE_LIBBOOST_THREAD
953+
954+namespace boost
955+{
956+// replicate the little we actually use with PThreads; for documentation, see boost.
957+class mutex
958+{
959+private:
960+ mutex( mutex const & );
961+ mutex & operator = ( mutex const & );
962+protected:
963+#ifdef HAVE_PTHREAD
964+#define HAVE_REAL_MUTEX
965+ pthread_mutex_t mutex_;
966+#endif
967+
968+ // special constructor, do not initialize mutex
969+ explicit mutex( int );
970+public:
971+ mutex();
972+ ~mutex();
973+ void lock();
974+ void unlock();
975+};
976+
977+class recursive_mutex
978+ : public mutex
979+{
980+public:
981+ recursive_mutex();
982+};
983+
984+template <class T>
985+class lock_base
986+{
987+private:
988+ T & mutex_;
989+ lock_base( lock_base const & );
990+ lock_base & operator = ( lock_base const & );
991+protected:
992+lock_base(T & m)
993+ : mutex_(m)
994+ {}
995+
996+ void lock_()
997+ {
998+ mutex_.lock();
999+ };
1000+
1001+ void unlock_()
1002+ {
1003+ mutex_.unlock();
1004+ }
1005+};
1006+
1007+template <class T>
1008+class lock_guard: public lock_base<T>
1009+{
1010+public:
1011+ lock_guard(T & m)
1012+ : lock_base<T>(m)
1013+ {
1014+ this->lock_();
1015+ };
1016+
1017+ ~lock_guard()
1018+ {
1019+ this->unlock_();
1020+ };
1021+};
1022+
1023+template <class T>
1024+class unique_lock: public lock_base<T>
1025+{
1026+private:
1027+ bool locked_;
1028+public:
1029+ unique_lock(T & m)
1030+ : lock_base<T>(m), locked_(false)
1031+ {
1032+ this->lock();
1033+ };
1034+
1035+ ~unique_lock()
1036+ {
1037+ this->unlock();
1038+ };
1039+
1040+ void lock()
1041+ {
1042+ if( !locked_ )
1043+ {
1044+ locked_ = true;
1045+ this->lock_();
1046+ }
1047+ }
1048+
1049+ void unlock()
1050+ {
1051+ if( locked_ )
1052+ {
1053+ locked_ = false;
1054+ this->unlock_();
1055+ }
1056+ }
1057+};
1058+
1059+}
1060+
1061+#endif // HAVE_LIBBOOST_THREAD
1062+
1063+#endif
1064
1065=== modified file 'src/tools/tSafePTR.h'
1066--- src/tools/tSafePTR.h 2011-08-25 11:47:18 +0000
1067+++ src/tools/tSafePTR.h 2011-09-11 04:47:25 +0000
1068@@ -36,6 +36,8 @@
1069
1070 #include "tError.h"
1071
1072+#include "tMutex.h"
1073+
1074 class tCheckedPTRBase{
1075 friend class tPTRList;
1076 int id;
1077@@ -424,8 +426,8 @@
1078 // not thread-safe mutex
1079 struct tNonMutex
1080 {
1081- void acquire(){}
1082- void release(){}
1083+ void lock(){}
1084+ void unlock(){}
1085 };
1086
1087 template< class T, class MUTEX = tNonMutex > class tReferencable
1088@@ -443,9 +445,8 @@
1089 st_AddRefBreakpint( this );
1090 #endif
1091 tASSERT( this && refCtr_ >= 0 );
1092- mutex_.acquire();
1093+ boost::lock_guard< MUTEX > lock( mutex_ );
1094 ++refCtr_;
1095- mutex_.release();
1096 tASSERT( this && refCtr_ >= 0 );
1097 }
1098
1099@@ -456,14 +457,13 @@
1100 #endif
1101
1102 tASSERT ( this && refCtr_ >= 0 );
1103- mutex_.acquire();
1104+ boost::unique_lock< MUTEX > lock( mutex_ );
1105 --refCtr_;
1106- bool kill = (refCtr_ <= 0);
1107- mutex_.release();
1108
1109- if ( kill )
1110+ if ( refCtr_ <= 0 )
1111 {
1112 refCtr_ = -1000;
1113+ lock.unlock();
1114 delete static_cast< const T* >( this );
1115 }
1116 }
1117
1118=== added file 'src/tools/tThread.h'
1119--- src/tools/tThread.h 1970-01-01 00:00:00 +0000
1120+++ src/tools/tThread.h 2011-09-11 04:47:25 +0000
1121@@ -0,0 +1,105 @@
1122+/*
1123+
1124+*************************************************************************
1125+
1126+ArmageTron -- Just another Tron Lightcycle Game in 3D.
1127+Copyright (C) 2011 Armagetron Advanced Development Team
1128+
1129+**************************************************************************
1130+
1131+This program is free software; you can redistribute it and/or
1132+modify it under the terms of the GNU General Public License
1133+as published by the Free Software Foundation; either version 2
1134+of the License, or (at your option) any later version.
1135+
1136+This program is distributed in the hope that it will be useful,
1137+but WITHOUT ANY WARRANTY; without even the implied warranty of
1138+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1139+GNU General Public License for more details.
1140+
1141+You should have received a copy of the GNU General Public License
1142+along with this program; if not, write to the Free Software
1143+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1144+
1145+***************************************************************************
1146+
1147+*/
1148+
1149+#ifndef ArmageTron_THREAD_H
1150+#define ArmageTron_THREAD_H
1151+
1152+#include "defs.h"
1153+
1154+#ifdef HAVE_LIBBOOST_THREAD
1155+
1156+#include <boost/thread/thread.hpp>
1157+
1158+#define HAVE_THREADS
1159+
1160+#else // HAVE_LIBBOOST_THREAD
1161+
1162+#ifdef HAVE_PTHREAD
1163+
1164+#define HAVE_THREADS
1165+
1166+#include <pthread.h>
1167+
1168+// replicate the little we actually use with PThreads
1169+namespace boost
1170+{
1171+class thread
1172+{
1173+public:
1174+ template< class T>
1175+ thread( T const & t )
1176+ {
1177+ // we don't currently hang on to thread objects, so no need to store handles
1178+ pthread_t thread;
1179+
1180+ // make a copy of the object to call
1181+ T * o = new T(t);
1182+
1183+ pthread_create(&thread, NULL, &run<T>, (void*) o);
1184+ }
1185+private:
1186+ // worker function
1187+ template< class T >
1188+ static void * run( void * o )
1189+ {
1190+ T * t = static_cast< T * >(o);
1191+
1192+ // do the actual call
1193+ (*t)();
1194+
1195+ // clean up
1196+ delete t;
1197+
1198+ return NULL;
1199+ }
1200+};
1201+}
1202+
1203+#else // HAVE_LIBPTHREAD
1204+
1205+#include "tError.h"
1206+
1207+// replicate the little we actually use with PThreads
1208+namespace boost
1209+{
1210+class thread
1211+{
1212+public:
1213+ template< class T>
1214+ thread( T const & t )
1215+ {
1216+ // should never be called, then
1217+ tVERIFY(0);
1218+ }
1219+};
1220+}
1221+
1222+#endif // HAVE_LIBPTHREAD
1223+
1224+#endif // HAVE_LIBBOOST_THREAD
1225+
1226+#endif
1227
1228=== modified file 'src/tools/tToDo.cpp'
1229--- src/tools/tToDo.cpp 2011-07-10 18:22:34 +0000
1230+++ src/tools/tToDo.cpp 2011-09-11 04:47:25 +0000
1231@@ -28,37 +28,24 @@
1232 #include "tToDo.h"
1233 #include "tArray.h"
1234
1235-#ifdef HAVE_LIBZTHREAD
1236-#include <zthread/FastRecursiveMutex.h>
1237-
1238-static ZThread::FastRecursiveMutex st_mutex;
1239-#elif defined(HAVE_PTHREAD)
1240-#include "pthread-binding.h"
1241-static tPThreadRecursiveMutex st_mutex;
1242-#else
1243-class tMockMutex
1244-{
1245-public:
1246- void acquire(){}
1247- void release(){}
1248-};
1249-
1250-static tMockMutex st_mutex;
1251-#endif
1252+#include "tMutex.h"
1253+
1254+static boost::recursive_mutex st_mutex;
1255
1256 tArray<tTODO_FUNC *> tToDos;
1257
1258 void st_ToDo(tTODO_FUNC *td){ // postpone something
1259- st_mutex.acquire();
1260+ boost::lock_guard< boost::recursive_mutex > lock( st_mutex );
1261+
1262 tToDos[tToDos.Len()]=td;
1263- st_mutex.release();
1264 }
1265
1266 // the function currently in execution
1267 static tTODO_FUNC * st_toDoCurrent = 0;
1268
1269 void st_ToDoOnce(tTODO_FUNC *td){ // postpone something, avoid double entries
1270- st_mutex.acquire();
1271+ boost::lock_guard< boost::recursive_mutex > lock( st_mutex );
1272+
1273 if( st_toDoCurrent == td )
1274 {
1275 return;
1276@@ -71,7 +58,6 @@
1277 }
1278 }
1279 tToDos[tToDos.Len()]=td;
1280- st_mutex.release();
1281 }
1282
1283 // a lone (but relatively safe) function pointer for things to do triggered by signals.
1284@@ -83,7 +69,7 @@
1285 st_ToDo( st_toDoFromSignal );
1286 st_toDoFromSignal = 0;
1287 }
1288- st_mutex.acquire();
1289+ boost::lock_guard< boost::recursive_mutex > lock( st_mutex );
1290 while (tToDos.Len()){
1291 tTODO_FUNC *last = st_toDoCurrent;
1292 tTODO_FUNC *td = tToDos[tToDos.Len()-1];
1293@@ -92,7 +78,6 @@
1294 (*td)();
1295 st_toDoCurrent = last;
1296 }
1297- st_mutex.release();
1298 }
1299
1300 void st_ToDo_Signal(tTODO_FUNC *td){ // postpone something
1301
1302=== modified file 'src/win32/config_common.h'
1303--- src/win32/config_common.h 2011-07-30 23:11:58 +0000
1304+++ src/win32/config_common.h 2011-09-11 04:47:25 +0000
1305@@ -11,6 +11,10 @@
1306 // is now defined for code::blocks > 8 or so
1307 #define HAVE_ISBLANK
1308
1309+// this one is included in winlibs as static library
1310+#define HAVE_LIBBOOST_THREAD
1311+#define BOOST_THREAD_USE_LIB
1312+
1313 // and disable warnings about those calls that can't be converted. We may want to look at
1314 // them later, though.
1315 #define _CRT_SECURE_NO_DEPRECATE 1
1316
1317=== modified file 'src/win32_ded/aa_config.h'
1318--- src/win32_ded/aa_config.h 2011-07-30 23:11:58 +0000
1319+++ src/win32_ded/aa_config.h 2011-09-11 04:47:25 +0000
1320@@ -7,7 +7,6 @@
1321 #define DEDICATED 1
1322
1323 // activate armathentication support
1324-#define HAVE_LIBZTHREAD 1
1325 #define KRAWALL_SERVER 1
1326
1327 // include common Windows header
1328
1329=== modified file 'win32/code_blocks/ArmagetronAd.cbp'
1330--- win32/code_blocks/ArmagetronAd.cbp 2011-08-10 12:53:41 +0000
1331+++ win32/code_blocks/ArmagetronAd.cbp 2011-09-11 04:47:25 +0000
1332@@ -26,7 +26,7 @@
1333 <Add library="..\..\..\winlibs\build\dist\SDL.dll" />
1334 <Add library="..\..\..\winlibs\build\dist\FTGL.dll" />
1335 <Add library="..\..\..\winlibs\protobuf\vsprojects\libprotobuf.a" />
1336- <Add library="..\..\..\winlibs\build\dist\libZThread.a" />
1337+ <Add library="..\..\..\winlibs\win32\boost_libs\libboost_thread-mgw44-mt-1_47.a" />
1338 </Linker>
1339 </Target>
1340 <Target title="Win32 Debug">
1341@@ -47,7 +47,7 @@
1342 <Add library="..\..\..\winlibs\build\debug\SDL.dll" />
1343 <Add library="..\..\..\winlibs\build\debug\FTGL.dll" />
1344 <Add library="..\..\..\winlibs\protobuf\vsprojects\libprotobuf_debug.a" />
1345- <Add library="..\..\..\winlibs\build\debug\libZThread.a" />
1346+ <Add library="..\..\..\winlibs\win32\boost_libs\libboost_thread-mgw44-mt-d-1_47.a" />
1347 </Linker>
1348 </Target>
1349 </Build>
1350@@ -90,7 +90,6 @@
1351 <Add directory="..\..\..\winlibs\FTGL\win32\freetype\include\freetype2" />
1352 <Add directory="..\..\..\winlibs\boost\includes" />
1353 <Add directory="..\..\src\thirdparty\scrap" />
1354- <Add directory="..\..\..\winlibs\ZThread\include" />
1355 <Add directory="..\..\..\winlibs\protobuf\src" />
1356 <Add directory="..\..\src\protobuf" />
1357 <Add directory="..\..\src\thirdparty\utf8" />
1358@@ -463,6 +462,8 @@
1359 <Unit filename="..\..\src\tools\tMemManager.h" />
1360 <Unit filename="..\..\src\tools\tMemStack.cpp" />
1361 <Unit filename="..\..\src\tools\tMemStack.h" />
1362+ <Unit filename="..\..\src\tools\tMutex.cpp" />
1363+ <Unit filename="..\..\src\tools\tMutex.h" />
1364 <Unit filename="..\..\src\tools\tPlayList.cpp" />
1365 <Unit filename="..\..\src\tools\tPlayList.h" />
1366 <Unit filename="..\..\src\tools\tPolynomial.cpp" />
1367@@ -498,6 +499,7 @@
1368 <Unit filename="..\..\src\tools\tString.h" />
1369 <Unit filename="..\..\src\tools\tSysTime.cpp" />
1370 <Unit filename="..\..\src\tools\tSysTime.h" />
1371+ <Unit filename="..\..\src\tools\tThread.h" />
1372 <Unit filename="..\..\src\tools\tToDo.cpp" />
1373 <Unit filename="..\..\src\tools\tToDo.h" />
1374 <Unit filename="..\..\src\tools\tValue.h" />
1375
1376=== modified file 'win32/code_blocks/ArmagetronAd.workspace'
1377--- win32/code_blocks/ArmagetronAd.workspace 2011-08-10 12:53:41 +0000
1378+++ win32/code_blocks/ArmagetronAd.workspace 2011-09-11 04:47:25 +0000
1379@@ -1,9 +1,8 @@
1380 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
1381 <CodeBlocks_workspace_file>
1382 <Workspace title="Armagetron Advanced workspace">
1383- <Project filename="../../../winlibs/win32/code_blocks/ZThread.cbp" active="1" />
1384 <Project filename="../../../winlibs/protobuf/vsprojects/libprotobuf.cbp" />
1385- <Project filename="Dedicated.cbp" />
1386+ <Project filename="Dedicated.cbp" active="1" />
1387 <Project filename="Master.cbp" />
1388 <Project filename="../../../winlibs/win32/code_blocks/SDL.cbp" />
1389 <Project filename="../../../winlibs/win32/code_blocks/SDL_image.cbp" />
1390
1391=== modified file 'win32/code_blocks/Dedicated.cbp'
1392--- win32/code_blocks/Dedicated.cbp 2011-08-10 12:53:41 +0000
1393+++ win32/code_blocks/Dedicated.cbp 2011-09-11 04:47:25 +0000
1394@@ -20,8 +20,8 @@
1395 </Compiler>
1396 <Linker>
1397 <Add option="-s" />
1398- <Add library="..\..\..\winlibs\build\dist\libZThread.a" />
1399 <Add library="..\..\..\winlibs\protobuf\vsprojects\libprotobuf.a" />
1400+ <Add library="..\..\..\winlibs\win32\boost_libs\libboost_thread-mgw44-mt-1_47.a" />
1401 </Linker>
1402 </Target>
1403 <Target title="Win32 Debug">
1404@@ -38,8 +38,8 @@
1405 <Add option="-DDEBUG" />
1406 </Compiler>
1407 <Linker>
1408- <Add library="..\..\..\winlibs\build\debug\libZThread.a" />
1409 <Add library="..\..\..\winlibs\protobuf\vsprojects\libprotobuf_debug.a" />
1410+ <Add library="..\..\..\winlibs\win32\boost_libs\libboost_thread-mgw44-mt-d-1_47.a" />
1411 </Linker>
1412 </Target>
1413 </Build>
1414@@ -71,7 +71,6 @@
1415 <Add directory="..\..\..\winlibs\iconv\include" />
1416 <Add directory="..\..\..\winlibs\boost\includes" />
1417 <Add directory="..\..\src\resource" />
1418- <Add directory="..\..\..\winlibs\ZThread\include" />
1419 <Add directory="..\..\src\protobuf" />
1420 <Add directory="..\..\..\winlibs\protobuf\src" />
1421 <Add directory="..\..\src\thirdparty\utf8" />
1422@@ -370,6 +369,8 @@
1423 <Unit filename="..\..\src\tools\tMemManager.h" />
1424 <Unit filename="..\..\src\tools\tMemStack.cpp" />
1425 <Unit filename="..\..\src\tools\tMemStack.h" />
1426+ <Unit filename="..\..\src\tools\tMutex.cpp" />
1427+ <Unit filename="..\..\src\tools\tMutex.h" />
1428 <Unit filename="..\..\src\tools\tPlayList.cpp" />
1429 <Unit filename="..\..\src\tools\tPlayList.h" />
1430 <Unit filename="..\..\src\tools\tPolynomial.cpp" />
1431@@ -400,6 +401,7 @@
1432 <Unit filename="..\..\src\tools\tString.h" />
1433 <Unit filename="..\..\src\tools\tSysTime.cpp" />
1434 <Unit filename="..\..\src\tools\tSysTime.h" />
1435+ <Unit filename="..\..\src\tools\tThread.h" />
1436 <Unit filename="..\..\src\tools\tToDo.cpp" />
1437 <Unit filename="..\..\src\tools\tToDo.h" />
1438 <Unit filename="..\..\src\tools\tVersion.cpp" />
1439
1440=== modified file 'win32/code_blocks/Master.cbp'
1441--- win32/code_blocks/Master.cbp 2011-08-10 12:53:41 +0000
1442+++ win32/code_blocks/Master.cbp 2011-09-11 04:47:25 +0000
1443@@ -20,8 +20,8 @@
1444 </Compiler>
1445 <Linker>
1446 <Add option="-s" />
1447- <Add library="..\..\..\winlibs\build\dist\libZThread.a" />
1448 <Add library="..\..\..\winlibs\protobuf\vsprojects\libprotobuf.a" />
1449+ <Add library="..\..\..\winlibs\win32\boost_libs\libboost_thread-mgw44-mt-1_47.a" />
1450 </Linker>
1451 </Target>
1452 <Target title="Win32 Debug">
1453@@ -38,8 +38,8 @@
1454 <Add option="-DDEBUG" />
1455 </Compiler>
1456 <Linker>
1457- <Add library="..\..\..\winlibs\build\debug\libZThread.a" />
1458 <Add library="..\..\..\winlibs\protobuf\vsprojects\libprotobuf_debug.a" />
1459+ <Add library="..\..\..\winlibs\win32\boost_libs\libboost_thread-mgw44-mt-d-1_47.a" />
1460 </Linker>
1461 </Target>
1462 </Build>
1463@@ -59,7 +59,6 @@
1464 <Add directory="..\..\src\tools" />
1465 <Add directory="..\..\src\ui" />
1466 <Add directory="..\..\src\win32_ded" />
1467- <Add directory="..\..\..\winlibs\ZThread\include" />
1468 <Add directory="..\..\..\winlibs\libxml2\include" />
1469 <Add directory="..\..\src\resource" />
1470 <Add directory="..\..\..\winlibs\boost\includes" />
1471@@ -269,6 +268,8 @@
1472 <Unit filename="..\..\src\tools\tMemManager.h" />
1473 <Unit filename="..\..\src\tools\tMemStack.cpp" />
1474 <Unit filename="..\..\src\tools\tMemStack.h" />
1475+ <Unit filename="..\..\src\tools\tMutex.cpp" />
1476+ <Unit filename="..\..\src\tools\tMutex.h" />
1477 <Unit filename="..\..\src\tools\tRandom.cpp" />
1478 <Unit filename="..\..\src\tools\tRandom.h" />
1479 <Unit filename="..\..\src\tools\tRecorder.cpp" />
1480@@ -284,6 +285,7 @@
1481 <Unit filename="..\..\src\tools\tString.h" />
1482 <Unit filename="..\..\src\tools\tSysTime.cpp" />
1483 <Unit filename="..\..\src\tools\tSysTime.h" />
1484+ <Unit filename="..\..\src\tools\tThread.h" />
1485 <Unit filename="..\..\src\tools\tToDo.cpp" />
1486 <Unit filename="..\..\src\tools\tToDo.h" />
1487 <Unit filename="..\..\src\tools\tVersion.cpp" />

Subscribers

People subscribed via source and target branches

to status/vote changes: