]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake2/qdata_heretic2/common/threads.c
Merge branch 'quake2' into 'master'
[xonotic/netradiant.git] / tools / quake2 / qdata_heretic2 / common / threads.c
index 31a6ca9f6faf0357ef387cebc7b40678db2cddf0..239226b776f454f7054e39bc4ce314a2efec4fc8 100644 (file)
@@ -1,5 +1,5 @@
 /*
-   Copyright (C) 1999-2006 Id Software, Inc. and contributors.
+   Copyright (C) 1999-2007 id Software, Inc. and contributors.
    For a list of contributors, see the accompanying CONTRIBUTORS file.
 
    This file is part of GtkRadiant.
@@ -25,8 +25,7 @@
 // The below define is necessary to use
 // pthreads extensions like pthread_mutexattr_settype
 #define _GNU_SOURCE
-#include <pthread.h>
-#endif
+#endif // !GDEF_OS_WINDOWS
 
 #include "cmdlib.h"
 #include "mathlib.h"
@@ -87,7 +86,7 @@ void ThreadWorkerFunction( int threadnum ){
                if ( work == -1 ) {
                        break;
                }
-//Sys_Printf ("thread %i, work %i\n", threadnum, work);
+               //Sys_Printf ("thread %i, work %i\n", threadnum, work);
                workfunction( work );
        }
 }
@@ -101,6 +100,8 @@ void RunThreadsOnIndividual( int workcnt, qboolean showpacifier, void ( *func )(
 }
 
 
+#if GDEF_OS_WINDOWS
+
 /*
    ===================================================================
 
@@ -108,13 +109,11 @@ void RunThreadsOnIndividual( int workcnt, qboolean showpacifier, void ( *func )(
 
    ===================================================================
  */
-#if GDEF_OS_WINDOWS
-
-#define USED
 
 #include <windows.h>
 
-int numthreads = -1;
+// Setting default Threads to 1
+int numthreads = 1;
 CRITICAL_SECTION crit;
 static int enter;
 
@@ -211,7 +210,7 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){
 }
 
 
-#endif
+#elif GDEF_OS_OSF1
 
 /*
    ===================================================================
@@ -221,9 +220,6 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){
    ===================================================================
  */
 
-#ifdef __osf__
-#define USED
-
 int numthreads = 4;
 
 void ThreadSetDefault( void ){
@@ -318,7 +314,7 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){
 }
 
 
-#endif
+#elif GDEF_OS_IRIX
 
 /*
    ===================================================================
@@ -328,15 +324,11 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){
    ===================================================================
  */
 
-#ifdef _MIPS_ISA
-#define USED
-
 #include <task.h>
 #include <abi_mutex.h>
 #include <sys/types.h>
 #include <sys/prctl.h>
 
-
 int numthreads = -1;
 abilock_t lck;
 
@@ -405,8 +397,7 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){
 }
 
 
-#endif
-
+#elif GDEF_OS_LINUX || GDEF_OS_BSD || GDEF_OS_MACOS
 
 /*
    =======================================================================
@@ -416,10 +407,8 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){
    =======================================================================
  */
 
-#if GDEF_OS_LINUX
-#define USED
-
-int numthreads = 4;
+// Setting default Threads to 1
+int numthreads = 1;
 
 void ThreadSetDefault( void ){
        if ( numthreads == -1 ) { // not set manually
@@ -541,12 +530,9 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){
                if ( pthread_mutexattr_init( &mattrib ) != 0 ) {
                        Error( "pthread_mutexattr_init failed" );
                }
-#if __GLIBC_MINOR__ == 1
-               if ( pthread_mutexattr_settype( &mattrib, PTHREAD_MUTEX_FAST_NP ) != 0 )
-#else
-               if ( pthread_mutexattr_settype( &mattrib, PTHREAD_MUTEX_ADAPTIVE_NP ) != 0 )
-#endif
-               { Error( "pthread_mutexattr_settype failed" ); }
+               if ( pthread_mutexattr_settype( &mattrib, PTHREAD_MUTEX_ERRORCHECK ) != 0 ) {
+                       Error( "pthread_mutexattr_settype failed" );
+               }
                recursive_mutex_init( mattrib );
 
                for ( i = 0 ; i < numthreads ; i++ )
@@ -571,9 +557,10 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){
                Sys_Printf( " (%i)\n", end - start );
        }
 }
-#endif // ifdef __linux__
 
 
+#else // UNKNOWN OS
+
 /*
    =======================================================================
 
@@ -582,8 +569,6 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){
    =======================================================================
  */
 
-#ifndef USED
-
 int numthreads = 1;
 
 void ThreadSetDefault( void ){
@@ -618,4 +603,4 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){
        }
 }
 
-#endif
+#endif // UNKNOWN OS