From 497ff1ecd64c8908f988e15ca879824f2781e3fd Mon Sep 17 00:00:00 2001 From: PilzAdam Date: Sun, 24 Feb 2013 18:40:43 +0100 Subject: Change Minetest-c55 to Minetest --- src/porting.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/porting.cpp') diff --git a/src/porting.cpp b/src/porting.cpp index f8a2cca5c..0f702810d 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -1,5 +1,5 @@ /* -Minetest-c55 +Minetest Copyright (C) 2010 celeron55, Perttu Ahola This program is free software; you can redistribute it and/or modify -- cgit v1.2.3 From 6d0ea26c2d62c3774ff384cf1bfc2a3372b49a3b Mon Sep 17 00:00:00 2001 From: Sfan5 Date: Sun, 24 Feb 2013 19:38:45 +0100 Subject: Update Copyright Years --- src/porting.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/porting.cpp') diff --git a/src/porting.cpp b/src/porting.cpp index 0f702810d..7ad557833 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -1,6 +1,6 @@ /* Minetest -Copyright (C) 2010 celeron55, Perttu Ahola +Copyright (C) 2013 celeron55, Perttu Ahola 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 -- cgit v1.2.3 From 5ec5b1cbd64a22e628be2cf03391883c44074811 Mon Sep 17 00:00:00 2001 From: kwolekr Date: Sun, 17 Feb 2013 01:47:49 -0500 Subject: Add multi-Emerge thread support --- src/porting.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/porting.cpp') diff --git a/src/porting.cpp b/src/porting.cpp index 7ad557833..58d71e4aa 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -131,6 +131,29 @@ void signal_handler_init(void) #endif +/* + 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 +} + /* Path mangler */ -- cgit v1.2.3 From 60e6284f30d31e11c1a464d9a8b3c5c392ceb3f0 Mon Sep 17 00:00:00 2001 From: kwolekr Date: Thu, 21 Feb 2013 17:44:14 -0500 Subject: Tune queue limits, some other adjustments --- src/porting.cpp | 132 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 115 insertions(+), 17 deletions(-) (limited to 'src/porting.cpp') diff --git a/src/porting.cpp b/src/porting.cpp index 58d71e4aa..84df15b30 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -131,29 +131,127 @@ void signal_handler_init(void) #endif + /* 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 +#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 } + +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 +} + + +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 */ -- cgit v1.2.3