aboutsummaryrefslogtreecommitdiff
path: root/src/script
Commit message (Expand)AuthorAge
...
* Customizeable max breath for players (#6411)SmallJoker2017-09-15
* Object properties: Add 'glow', disables light's effect if negativeRob Blanckaert2017-09-14
* Network: Remove large parts of deprecated legacy code (#6404)SmallJoker2017-09-12
* Make INodeDefManager::getIds return a vector, not a setKahrl2017-09-12
* Implement client node dig predictionAuke Kok2017-09-11
* Object properties: Fix loss of custom selectionboxSmallJoker2017-09-10
* Schematic decorations: Add 'place_offset_y' placement parameterparamat2017-09-10
* Implement minetest.register_can_bypass_userlimit (#6369)Loïc Blot2017-09-04
* Ores: Add stratum ore (#6352)Paramat2017-09-03
* Remove nodeupdate completely (#6358)Rui2017-09-01
* Fix animation frame_speed and blend loosing precision due to incorrec… (#6357)sapier2017-09-01
* Zoom: Move enabling zoom to a new player object propertyparamat2017-08-30
* Clientevent refactor (#6320)Loïc Blot2017-08-28
* core.get_objects_inside_radius: Omit removed objects (#6318)you2017-08-27
* Overlays for wield and inventory images (#6107)Dániel Juhász2017-08-25
* Make entity selection and collision boxes independently settable (#6218)stujones112017-08-24
* Respect object property hp_max field for players (#6287)SmallJoker2017-08-23
* Minimap: Add new HUD flag for minimap radar modeparamat2017-08-20
* Modernize code: very last fixes (#6290)Loïc Blot2017-08-20
* Modernize source code: last part (#6285)Loïc Blot2017-08-20
* Code modernization: subfolders (#6283)Loïc Blot2017-08-19
* Optimize headers (part 2) (#6272)Loïc Blot2017-08-18
* C++ modernize: Pragma once (#6264)Loïc Blot2017-08-17
* l_server, clientenvironment, clientiface: code modernizationLoic Blot2017-08-17
* Cleanup various headers to reduce compilation times (#6255)Loïc Blot2017-08-16
* Sort box corners correctlyThomas--S2017-08-04
* Add LuaEntity on_death callback (#6177)Loïc Blot2017-07-27
* Clouds API: change speed from 'y' to 'z', ColorSpecs in Lua docs (#6164)Ben Deutsch2017-07-24
* [CSM] Add flavour limits controlled by server (#5930)Loïc Blot2017-07-18
* Chat protocol rewrite (#5117)Loïc Blot2017-07-16
* Revert "CSM: Revert "[CSM] Add send_chat_message and run_server_chatcommand""Loic Blot2017-07-15
* CSM: Revert "[CSM] Add send_chat_message and run_server_chatcommand"rubenwardy2017-07-15
* Remove remaining modstore code (#6120)Elijah Duffy2017-07-14
* Add 'plantlike_rooted' drawtypenumber Zero2017-07-11
* Expose getPointedThing to LuaDániel Juhász2017-07-07
* Main Menu: Allow copying directories from non-Minetest locations (#6095)Elijah Duffy2017-07-04
* Create a filesystem abstraction layer for CSM and only allow accessing files ...red-0012017-06-30
* Isolate irrlicht references and use a singleton (#6041)Loïc Blot2017-06-26
* Fix CSM crash caused by move to C++11. (#6027)red-0012017-06-22
* Automatic item and node colorization (#5640)Dániel Juhász2017-06-20
* Fix 2 warnings reported by GCCLoic Blot2017-06-20
* C++11 cleanup on constructors (#6000)Vincent Glize2017-06-19
* find_nodes_in_area: Extend maximal count to U32_MAX (#5277)SmallJoker2017-06-19
* Client::makeScreenshot: remove device paramLoic Blot2017-06-19
* Sound: Add pitch option (#5960)Rui2017-06-11
* Improve the path select GUI (#5852)red-0012017-06-11
* Remove threads.h and replace its definitions with their C++11 equivalents (#5...ShadowNinja2017-06-11
* C++11 patchset 6: forbid object copy using assigment/copy function deleters (...Loïc Blot2017-06-10
* Order es_DrawType exactly like enum NodeDrawType in nodedef.h (#5946)Thomas--S2017-06-10
* CSM: Fix documentation error for register_on_*_chat_messages (#5917)DS2017-06-09
l slc">// Reserved for future use, must be zero }; #endif // for bindToProcessor #if __FreeBSD_version >= 702106 typedef cpuset_t cpu_set_t; #elif defined(__sun) || defined(sun) #include <sys/types.h> #include <sys/processor.h> #include <sys/procset.h> #elif defined(_AIX) #include <sys/processor.h> #include <sys/thread.h> #elif defined(__APPLE__) #include <mach/mach_init.h> #include <mach/thread_act.h> #endif Thread::Thread(const std::string &name) : m_name(name), m_request_stop(false), m_running(false) { #ifdef _AIX m_kernel_thread_id = -1; #endif } Thread::~Thread() { // kill the thread if running if (!m_running) { wait(); } else { m_running = false; #if defined(_WIN32) // See https://msdn.microsoft.com/en-us/library/hh920601.aspx#thread__native_handle_method TerminateThread((HANDLE) m_thread_obj->native_handle(), 0); CloseHandle((HANDLE) m_thread_obj->native_handle()); #else // We need to pthread_kill instead on Android since NDKv5's pthread // implementation is incomplete. # ifdef __ANDROID__ pthread_kill(getThreadHandle(), SIGKILL); # else pthread_cancel(getThreadHandle()); # endif wait(); #endif } // Make sure start finished mutex is unlocked before it's destroyed if (m_start_finished_mutex.try_lock()) m_start_finished_mutex.unlock(); } bool Thread::start() { MutexAutoLock lock(m_mutex); if (m_running) return false; m_request_stop = false; // The mutex may already be locked if the thread is being restarted m_start_finished_mutex.try_lock(); try { m_thread_obj = new std::thread(threadProc, this); } catch (const std::system_error &e) { return false; } // Allow spawned thread to continue m_start_finished_mutex.unlock(); while (!m_running) sleep_ms(1); m_joinable = true; return true; } bool Thread::stop() { m_request_stop = true; return true; } bool Thread::wait() { MutexAutoLock lock(m_mutex); if (!m_joinable) return false; m_thread_obj->join(); delete m_thread_obj; m_thread_obj = nullptr; assert(m_running == false); m_joinable = false; return true; } bool Thread::getReturnValue(void **ret) { if (m_running) return false; *ret = m_retval; return true; } void Thread::threadProc(Thread *thr) { #ifdef _AIX thr->m_kernel_thread_id = thread_self(); #endif thr->setName(thr->m_name); g_logger.registerThread(thr->m_name); thr->m_running = true; // Wait for the thread that started this one to finish initializing the // thread handle so that getThreadId/getThreadHandle will work. thr->m_start_finished_mutex.lock(); thr->m_retval = thr->run(); thr->m_running = false; // Unlock m_start_finished_mutex to prevent data race condition on Windows. // On Windows with VS2017 build TerminateThread is called and this mutex is not // released. We try to unlock it from caller thread and it's refused by system. thr->m_start_finished_mutex.unlock(); g_logger.deregisterThread(); } void Thread::setName(const std::string &name) { #if defined(__linux__) // It would be cleaner to do this with pthread_setname_np, // which was added to glibc in version 2.12, but some major // distributions are still runing 2.11 and previous versions. prctl(PR_SET_NAME, name.c_str()); #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) pthread_set_name_np(pthread_self(), name.c_str()); #elif defined(__NetBSD__) pthread_setname_np(pthread_self(), "%s", const_cast<char*>(name.c_str())); #elif defined(__APPLE__) pthread_setname_np(name.c_str()); #elif defined(__HAIKU__) rename_thread(find_thread(NULL), name.c_str()); #elif defined(_MSC_VER) // Windows itself doesn't support thread names, // but the MSVC debugger does... THREADNAME_INFO info; info.dwType = 0x1000; info.szName = name.c_str(); info.dwThreadID = -1; info.dwFlags = 0; __try { RaiseException(0x406D1388, 0, sizeof(info) / sizeof(DWORD), (ULONG_PTR *)&info); } __except (EXCEPTION_CONTINUE_EXECUTION) { } #elif defined(_WIN32) || defined(__GNU__) // These platforms are known to not support thread names. // Silently ignore the request. #else #warning "Unrecognized platform, thread names will not be available." #endif } unsigned int Thread::getNumberOfProcessors() { return std::thread::hardware_concurrency(); } bool Thread::bindToProcessor(unsigned int proc_number) { #if defined(__ANDROID__) return false; #elif _MSC_VER return SetThreadAffinityMask(getThreadHandle(), 1 << proc_number); #elif __MINGW32__ return SetThreadAffinityMask(pthread_gethandle(getThreadHandle()), 1 << proc_number); #elif __FreeBSD_version >= 702106 || defined(__linux__) || defined(__DragonFly__) cpu_set_t cpuset; CPU_ZERO(&cpuset); CPU_SET(proc_number, &cpuset); return pthread_setaffinity_np(getThreadHandle(), sizeof(cpuset), &cpuset) == 0; #elif defined(__NetBSD__) cpuset_t *cpuset = cpuset_create(); if (cpuset == NULL) return false; int r = pthread_setaffinity_np(getThreadHandle(), cpuset_size(cpuset), cpuset); cpuset_destroy(cpuset); return r == 0; #elif defined(__sun) || defined(sun) return processor_bind(P_LWPID, P_MYID, proc_number, NULL) == 0 #elif defined(_AIX) return bindprocessor(BINDTHREAD, m_kernel_thread_id, proc_number) == 0; #elif defined(__hpux) || defined(hpux) pthread_spu_t answer; return pthread_processor_bind_np(PTHREAD_BIND_ADVISORY_NP, &answer, proc_number, getThreadHandle()) == 0; #elif defined(__APPLE__) struct thread_affinity_policy tapol; thread_port_t threadport = pthread_mach_thread_np(getThreadHandle()); tapol.affinity_tag = proc_number + 1; return thread_policy_set(threadport, THREAD_AFFINITY_POLICY, (thread_policy_t)&tapol, THREAD_AFFINITY_POLICY_COUNT) == KERN_SUCCESS; #else return false; #endif } bool Thread::setPriority(int prio) { #ifdef _MSC_VER return SetThreadPriority(getThreadHandle(), prio); #elif __MINGW32__ return SetThreadPriority(pthread_gethandle(getThreadHandle()), prio); #else struct sched_param sparam; int policy; if (pthread_getschedparam(getThreadHandle(), &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(getThreadHandle(), policy, &sparam) == 0; #endif }