]> git.lizzy.rs Git - minetest.git/blobdiff - src/porting.h
Merge remote branch 'origin/master'
[minetest.git] / src / porting.h
index 9ba3394bbc1d47bec2a0a891fd43c248c00aafc9..d7d1073406e69a558d1452aa29b1e42e5178e374 100644 (file)
@@ -1,6 +1,6 @@
 /*
-Minetest-c55
-Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
+Minetest
+Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
@@ -40,6 +40,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 //#define ALIGNOF(type) offsetof (alignment_trick<type>, member)
 
 #ifdef _WIN32
+       #ifndef _WIN32_WINNT
+               #define _WIN32_WINNT 0x0500
+       #endif
        #include <windows.h>
        
        #define sleep_ms(x) Sleep(x)
@@ -47,7 +50,32 @@ with this program; if not, write to the Free Software Foundation, Inc.,
        #include <unistd.h>
        #include <stdint.h> //for uintptr_t
        
+       #if (defined(linux) || defined(__linux)) && !defined(_GNU_SOURCE)
+               #define _GNU_SOURCE
+       #endif
+
+       #include <sched.h>
+
+       #ifdef __FreeBSD__
+               #include <pthread_np.h>
+               typedef cpuset_t cpu_set_t;
+       #elif defined(__sun) || defined(sun)
+               #include <sys/types.h>
+               #include <sys/processor.h>
+       #elif defined(_AIX)
+               #include <sys/processor.h>
+       #elif __APPLE__
+               #include <mach/mach_init.h>
+               #include <mach/thread_policy.h>
+       #endif
+
        #define sleep_ms(x) usleep(x*1000)
+       
+       #define THREAD_PRIORITY_LOWEST       0
+       #define THREAD_PRIORITY_BELOW_NORMAL 1
+       #define THREAD_PRIORITY_NORMAL       2
+       #define THREAD_PRIORITY_ABOVE_NORMAL 3
+       #define THREAD_PRIORITY_HIGHEST      4
 #endif
 
 #ifdef _MSC_VER
@@ -103,6 +131,21 @@ std::string getDataPath(const char *subpath);
 */
 void initializePaths();
 
+/*
+       Get number of online processors in the system.
+*/
+int getNumberOfProcessors();
+
+/*
+       Set a thread's affinity to a particular processor.
+*/
+bool threadBindToProcessor(threadid_t tid, int pnumber);
+
+/*
+       Set a thread's priority.
+*/
+bool threadSetPriority(threadid_t tid, int prio);
+
 /*
        Resolution is 10-20ms.
        Remember to check for overflows.