aboutsummaryrefslogtreecommitdiff
path: root/src/threading/thread.cpp
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2020-11-04 16:19:54 +0100
committerElias Fleckenstein <eliasfleckenstein@web.de>2020-11-04 16:19:54 +0100
commitad148587dcf5244c2d2011dba339786c765c54c4 (patch)
treebdd914121cd326da2ed26679838878e3edffc841 /src/threading/thread.cpp
parent1145b05ea0bda87dc0827821385810eced08f774 (diff)
downloaddragonfireclient-ad148587dcf5244c2d2011dba339786c765c54c4.tar.xz
Make Lint Happy
Diffstat (limited to 'src/threading/thread.cpp')
-rw-r--r--src/threading/thread.cpp86
1 files changed, 36 insertions, 50 deletions
diff --git a/src/threading/thread.cpp b/src/threading/thread.cpp
index e0f808c4d..1714f6e8e 100644
--- a/src/threading/thread.cpp
+++ b/src/threading/thread.cpp
@@ -30,45 +30,42 @@ DEALINGS IN THE SOFTWARE.
// for setName
#if defined(__linux__)
- #include <sys/prctl.h>
+#include <sys/prctl.h>
#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
- #include <pthread_np.h>
+#include <pthread_np.h>
#elif defined(_MSC_VER)
- struct THREADNAME_INFO {
- DWORD dwType; // Must be 0x1000
- LPCSTR szName; // Pointer to name (in user addr space)
- DWORD dwThreadID; // Thread ID (-1=caller thread)
- DWORD dwFlags; // Reserved for future use, must be zero
- };
+struct THREADNAME_INFO
+{
+ DWORD dwType; // Must be 0x1000
+ LPCSTR szName; // Pointer to name (in user addr space)
+ DWORD dwThreadID; // Thread ID (-1=caller thread)
+ DWORD dwFlags; // Reserved for future use, must be zero
+};
#endif
// for bindToProcessor
#if __FreeBSD_version >= 702106
- typedef cpuset_t cpu_set_t;
+typedef cpuset_t cpu_set_t;
#elif defined(__sun) || defined(sun)
- #include <sys/types.h>
- #include <sys/processor.h>
- #include <sys/procset.h>
+#include <sys/types.h>
+#include <sys/processor.h>
+#include <sys/procset.h>
#elif defined(_AIX)
- #include <sys/processor.h>
- #include <sys/thread.h>
+#include <sys/processor.h>
+#include <sys/thread.h>
#elif defined(__APPLE__)
- #include <mach/mach_init.h>
- #include <mach/thread_act.h>
+#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)
+ m_name(name), m_request_stop(false), m_running(false)
{
#ifdef _AIX
m_kernel_thread_id = -1;
#endif
}
-
Thread::~Thread()
{
kill();
@@ -76,10 +73,8 @@ Thread::~Thread()
// 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);
@@ -109,14 +104,12 @@ bool Thread::start()
return true;
}
-
bool Thread::stop()
{
m_request_stop = true;
return true;
}
-
bool Thread::wait()
{
MutexAutoLock lock(m_mutex);
@@ -124,7 +117,6 @@ bool Thread::wait()
if (!m_joinable)
return false;
-
m_thread_obj->join();
delete m_thread_obj;
@@ -135,7 +127,6 @@ bool Thread::wait()
return true;
}
-
bool Thread::kill()
{
if (!m_running) {
@@ -146,28 +137,28 @@ bool Thread::kill()
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());
+ // 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__
+#ifdef __ANDROID__
pthread_kill(getThreadHandle(), SIGKILL);
-# else
+#else
pthread_cancel(getThreadHandle());
-# endif
+#endif
wait();
#endif
- m_retval = nullptr;
- m_joinable = false;
+ m_retval = nullptr;
+ m_joinable = false;
m_request_stop = false;
return true;
}
-
bool Thread::getReturnValue(void **ret)
{
if (m_running)
@@ -177,7 +168,6 @@ bool Thread::getReturnValue(void **ret)
return true;
}
-
void Thread::threadProc(Thread *thr)
{
#ifdef _AIX
@@ -203,7 +193,6 @@ void Thread::threadProc(Thread *thr)
g_logger.deregisterThread();
}
-
void Thread::setName(const std::string &name)
{
#if defined(__linux__)
@@ -237,8 +226,8 @@ void Thread::setName(const std::string &name)
info.dwFlags = 0;
__try {
- RaiseException(0x406D1388, 0,
- sizeof(info) / sizeof(DWORD), (ULONG_PTR *)&info);
+ RaiseException(0x406D1388, 0, sizeof(info) / sizeof(DWORD),
+ (ULONG_PTR *)&info);
} __except (EXCEPTION_CONTINUE_EXECUTION) {
}
@@ -248,17 +237,15 @@ void Thread::setName(const std::string &name)
// Silently ignore the request.
#else
- #warning "Unrecognized platform, thread names will not be available."
+#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__)
@@ -271,7 +258,8 @@ bool Thread::bindToProcessor(unsigned int proc_number)
#elif __MINGW32__
- return SetThreadAffinityMask(pthread_gethandle(getThreadHandle()), 1 << proc_number);
+ return SetThreadAffinityMask(
+ pthread_gethandle(getThreadHandle()), 1 << proc_number);
#elif __FreeBSD_version >= 702106 || defined(__linux__) || defined(__DragonFly__)
@@ -294,8 +282,8 @@ bool Thread::bindToProcessor(unsigned int proc_number)
pthread_spu_t answer;
- return pthread_processor_bind_np(PTHREAD_BIND_ADVISORY_NP,
- &answer, proc_number, getThreadHandle()) == 0;
+ return pthread_processor_bind_np(PTHREAD_BIND_ADVISORY_NP, &answer, proc_number,
+ getThreadHandle()) == 0;
#elif defined(__APPLE__)
@@ -304,8 +292,8 @@ bool Thread::bindToProcessor(unsigned int proc_number)
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;
+ (thread_policy_t)&tapol,
+ THREAD_AFFINITY_POLICY_COUNT) == KERN_SUCCESS;
#else
@@ -314,7 +302,6 @@ bool Thread::bindToProcessor(unsigned int proc_number)
#endif
}
-
bool Thread::setPriority(int prio)
{
#ifdef _MSC_VER
@@ -341,4 +328,3 @@ bool Thread::setPriority(int prio)
#endif
}
-