diff options
author | ShadowNinja <shadowninja@minetest.net> | 2015-04-07 06:13:12 -0400 |
---|---|---|
committer | ShadowNinja <shadowninja@minetest.net> | 2015-08-23 22:04:06 -0400 |
commit | e4bff8be94c0db4f94e63ad448d0eeb869ccdbbd (patch) | |
tree | 7935586e79da5c8c7144e345a8c0fc1cda53beed /src/porting.cpp | |
parent | 6a1047d8c116f793890b63427d53f04ceca95d54 (diff) | |
download | minetest-e4bff8be94c0db4f94e63ad448d0eeb869ccdbbd.tar.gz minetest-e4bff8be94c0db4f94e63ad448d0eeb869ccdbbd.tar.bz2 minetest-e4bff8be94c0db4f94e63ad448d0eeb869ccdbbd.zip |
Clean up threading
* Rename everything.
* Strip J prefix.
* Change UpperCamelCase functions to lowerCamelCase.
* Remove global (!) semaphore count mutex on OSX.
* Remove semaphore count getter (unused, unsafe, depended on internal
API functions on Windows, and used a hack on OSX).
* Add `Atomic<type>`.
* Make `Thread` handle thread names.
* Add support for C++11 multi-threading.
* Combine pthread and win32 sources.
* Remove `ThreadStarted` (unused, unneeded).
* Move some includes from the headers to the sources.
* Move all of `Event` into its header (allows inlining with no new includes).
* Make `Event` use `Semaphore` (except on Windows).
* Move some porting functions into `Thread`.
* Integrate logging with `Thread`.
* Add threading test.
Diffstat (limited to 'src/porting.cpp')
-rw-r--r-- | src/porting.cpp | 124 |
1 files changed, 0 insertions, 124 deletions
diff --git a/src/porting.cpp b/src/porting.cpp index 44f1fcff1..cb9f3270b 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -130,130 +130,6 @@ void signal_handler_init(void) /* - Multithreading support -*/ -int getNumberOfProcessors() -{ -#if defined(_SC_NPROCESSORS_ONLN) - - return sysconf(_SC_NPROCESSORS_ONLN); - -#elif defined(__FreeBSD__) || defined(__APPLE__) - - unsigned int len, count; - len = sizeof(count); - return sysctlbyname("hw.ncpu", &count, &len, NULL, 0); - -#elif defined(_GNU_SOURCE) - - return get_nprocs(); - -#elif defined(_WIN32) - - SYSTEM_INFO sysinfo; - GetSystemInfo(&sysinfo); - return sysinfo.dwNumberOfProcessors; - -#elif defined(PTW32_VERSION) || defined(__hpux) - - return pthread_num_processors_np(); - -#else - - return 1; - -#endif -} - - -#ifndef __ANDROID__ -bool threadBindToProcessor(threadid_t tid, int pnumber) -{ -#if defined(_WIN32) - - HANDLE hThread = OpenThread(THREAD_ALL_ACCESS, 0, tid); - if (!hThread) - return false; - - bool success = SetThreadAffinityMask(hThread, 1 << pnumber) != 0; - - CloseHandle(hThread); - return success; - -#elif (defined(__FreeBSD__) && (__FreeBSD_version >= 702106)) \ - || defined(__linux) || defined(linux) - - cpu_set_t cpuset; - - CPU_ZERO(&cpuset); - CPU_SET(pnumber, &cpuset); - return pthread_setaffinity_np(tid, sizeof(cpuset), &cpuset) == 0; - -#elif defined(__sun) || defined(sun) - - return processor_bind(P_LWPID, MAKE_LWPID_PTHREAD(tid), - pnumber, NULL) == 0; - -#elif defined(_AIX) - - return bindprocessor(BINDTHREAD, (tid_t)tid, pnumber) == 0; - -#elif defined(__hpux) || defined(hpux) - - pthread_spu_t answer; - - return pthread_processor_bind_np(PTHREAD_BIND_ADVISORY_NP, - &answer, pnumber, tid) == 0; - -#elif defined(__APPLE__) - - struct thread_affinity_policy tapol; - - thread_port_t threadport = pthread_mach_thread_np(tid); - tapol.affinity_tag = pnumber + 1; - return thread_policy_set(threadport, THREAD_AFFINITY_POLICY, - (thread_policy_t)&tapol, THREAD_AFFINITY_POLICY_COUNT) == KERN_SUCCESS; - -#else - - return false; - -#endif -} -#endif - -bool threadSetPriority(threadid_t tid, int prio) -{ -#if defined(_WIN32) - - HANDLE hThread = OpenThread(THREAD_ALL_ACCESS, 0, tid); - if (!hThread) - return false; - - bool success = SetThreadPriority(hThread, prio) != 0; - - CloseHandle(hThread); - return success; - -#else - - struct sched_param sparam; - int policy; - - if (pthread_getschedparam(tid, &policy, &sparam) != 0) - return false; - - int min = sched_get_priority_min(policy); - int max = sched_get_priority_max(policy); - - sparam.sched_priority = min + prio * (max - min) / THREAD_PRIORITY_HIGHEST; - return pthread_setschedparam(tid, policy, &sparam) == 0; - -#endif -} - - -/* Path mangler */ |