Remove unused Thread.{cpp,h}

This commit is contained in:
Sacha 2013-11-13 02:50:35 +10:00
parent cf15ec8a53
commit 91ddddc2ef
11 changed files with 26 additions and 369 deletions

View File

@ -270,8 +270,6 @@ add_library(Common STATIC
Common/MsgHandler.h
Common/StringUtils.cpp
Common/StringUtils.h
Common/Thread.cpp
Common/Thread.h
Common/ThreadPools.cpp
Common/ThreadPools.h
Common/Timer.cpp

View File

@ -19,11 +19,11 @@
#include "Log.h"
#include "StringUtils.h"
#include "Thread.h"
#include "FileUtil.h"
#include "file/ini_file.h"
#include <set>
#include "Common/StdMutex.h"
#define MAX_MESSAGES 8000
#define MAX_MSGLEN 1024

View File

@ -1,214 +0,0 @@
// Copyright (C) 2003 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include "Thread.h"
#include "Common.h"
#ifdef __APPLE__
#include <mach/mach.h>
#elif defined(ANDROID)
#include <sys/syscall.h>
#elif defined BSD4_4
#include <pthread_np.h>
#endif
#ifdef BLACKBERRY
#include <sys/neutrino.h>
#endif
#ifdef USE_BEGINTHREADEX
#include <process.h>
#endif
namespace Common
{
int CurrentThreadId()
{
#ifdef _WIN32
return GetCurrentThreadId();
#elif defined __APPLE__
return mach_thread_self();
#else
return pthread_self();
#endif
}
#ifdef _WIN32
bool SetThreadAffinity(std::thread::native_handle_type thread, u32 mask)
{
return SetThreadAffinityMask(thread, mask) != 0;
}
bool SetCurrentThreadAffinity(u32 mask)
{
return SetThreadAffinityMask(GetCurrentThread(), mask) != 0;
}
// Supporting functions
void SleepCurrentThread(int ms)
{
Sleep(ms);
}
void SwitchCurrentThread()
{
SwitchToThread();
}
// Sets the debugger-visible name of the current thread.
// Uses undocumented (actually, it is now documented) trick.
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsdebug/html/vxtsksettingthreadname.asp
// This is implemented much nicer in upcoming msvc++, see:
// http://msdn.microsoft.com/en-us/library/xcb2z8hs(VS.100).aspx
void SetCurrentThreadName(const char* szThreadName)
{
static const DWORD MS_VC_EXCEPTION = 0x406D1388;
#pragma pack(push,8)
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
} info;
#pragma pack(pop)
info.dwType = 0x1000;
info.szName = szThreadName;
info.dwThreadID = -1; //dwThreadID;
info.dwFlags = 0;
__try
{
RaiseException(MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info);
}
__except(EXCEPTION_CONTINUE_EXECUTION)
{}
}
void EnableCrashingOnCrashes()
{
typedef BOOL (WINAPI *tGetPolicy)(LPDWORD lpFlags);
typedef BOOL (WINAPI *tSetPolicy)(DWORD dwFlags);
const DWORD EXCEPTION_SWALLOWING = 0x1;
HMODULE kernel32 = LoadLibraryA("kernel32.dll");
tGetPolicy pGetPolicy = (tGetPolicy)GetProcAddress(kernel32,
"GetProcessUserModeExceptionPolicy");
tSetPolicy pSetPolicy = (tSetPolicy)GetProcAddress(kernel32,
"SetProcessUserModeExceptionPolicy");
if (pGetPolicy && pSetPolicy)
{
DWORD dwFlags;
if (pGetPolicy(&dwFlags))
{
// Turn off the filter
pSetPolicy(dwFlags & ~EXCEPTION_SWALLOWING);
}
}
}
#else // !WIN32, so must be POSIX threads
bool SetThreadAffinity(std::thread::native_handle_type thread, u32 mask)
{
#ifdef __APPLE__
return thread_policy_set(pthread_mach_thread_np(thread),
THREAD_AFFINITY_POLICY, (integer_t *)&mask, 1) == 0;
#elif defined(ANDROID) || defined(BLACKBERRY)
return false;
#elif (defined __linux__ || defined BSD4_4)
cpu_set_t cpu_set;
CPU_ZERO(&cpu_set);
for (int i = 0; i != sizeof(mask) * 8; ++i) {
if ((mask >> i) & 1)
CPU_SET(i, &cpu_set);
}
return pthread_setaffinity_np(thread, sizeof(cpu_set), &cpu_set) == 0;
#endif
return false;
}
bool SetCurrentThreadAffinity(u32 mask)
{
#ifdef BLACKBERRY
return ThreadCtl(_NTO_TCTL_RUNMASK, &mask) != -1;
#elif defined(ANDROID)
return syscall(__NR_sched_setaffinity, gettid(), sizeof(mask), &mask) == 0;
#else
return SetThreadAffinity(pthread_self(), mask);
#endif
}
static pthread_key_t threadname_key;
static pthread_once_t threadname_key_once = PTHREAD_ONCE_INIT;
void SleepCurrentThread(int ms)
{
usleep(1000 * ms);
}
void SwitchCurrentThread()
{
usleep(1000 * 1);
}
static void FreeThreadName(void* threadname)
{
free(threadname);
}
static void ThreadnameKeyAlloc()
{
pthread_key_create(&threadname_key, FreeThreadName);
}
void SetCurrentThreadName(const char* szThreadName)
{
#ifdef APPLE
pthread_setname_np(szThreadName);
#elif defined(BLACKBERRY)
pthread_setname_np(pthread_self(), szThreadName);
#else
pthread_once(&threadname_key_once, ThreadnameKeyAlloc);
void* threadname;
if ((threadname = pthread_getspecific(threadname_key)) != NULL)
free(threadname);
pthread_setspecific(threadname_key, strdup(szThreadName));
#endif
INFO_LOG(COMMON, "%s(%s)\n", __FUNCTION__, szThreadName);
}
void EnableCrashingOnCrashes()
{
}
#endif
} // namespace Common

View File

@ -1,144 +0,0 @@
// Copyright (C) 2003 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef _THREAD_H_
#define _THREAD_H_
#include "thread/thread.h"
#include "StdConditionVariable.h"
// Don't include common.h here as it will break LogManager
#include "CommonTypes.h"
#include <stdio.h>
#include <string.h>
// This may not be defined outside _WIN32
#ifndef _WIN32
#ifndef INFINITE
#define INFINITE 0xffffffff
#endif
// Assume !ARM && !MIPS = x86
#if !defined(ARM) && !defined(MIPS)
#include <xmmintrin.h>
#endif
//for gettimeofday and struct time(spec|val)
#include <time.h>
#include <sys/time.h>
#endif
namespace Common
{
int CurrentThreadId();
// In Windows 7 SP1 or later, stops Windows from swallowing crashes in WndProcs and other callbacks.
void EnableCrashingOnCrashes();
bool SetThreadAffinity(std::thread::native_handle_type thread, u32 mask);
bool SetCurrentThreadAffinity(u32 mask);
class Event
{
public:
Event()
: is_set(false)
{};
void Set()
{
std::lock_guard<std::mutex> lk(m_mutex);
if (!is_set)
{
is_set = true;
m_condvar.notify_one();
}
}
void Wait()
{
std::unique_lock<std::mutex> lk(m_mutex);
m_condvar.wait(lk, [&]{ return is_set; });
is_set = false;
}
void Reset()
{
std::unique_lock<std::mutex> lk(m_mutex);
// no other action required, since wait loops on the predicate and any lingering signal will get cleared on the first iteration
is_set = false;
}
private:
volatile bool is_set;
std::condition_variable m_condvar;
std::mutex m_mutex;
};
// TODO: doesn't work on windows with (count > 2)
class Barrier
{
public:
Barrier(size_t count)
: m_count(count), m_waiting(0)
{}
// block until "count" threads call Sync()
bool Sync()
{
std::unique_lock<std::mutex> lk(m_mutex);
// TODO: broken when next round of Sync()s
// is entered before all waiting threads return from the notify_all
if (m_count == ++m_waiting)
{
m_waiting = 0;
m_condvar.notify_all();
return true;
}
else
{
m_condvar.wait(lk, [&]{ return (0 == m_waiting); });
return false;
}
}
private:
std::condition_variable m_condvar;
std::mutex m_mutex;
const size_t m_count;
volatile size_t m_waiting;
};
void SleepCurrentThread(int ms);
void SwitchCurrentThread(); // On Linux, this is equal to sleep 1ms
// Use this function during a spin-wait to make the current thread
// relax while another thread is working. This may be more efficient
// than using events because event functions use kernel calls.
inline void YieldCPU()
{
std::this_thread::yield();
}
void SetCurrentThreadName(const char *name);
} // namespace Common
#endif // _THREAD_H_

View File

@ -27,7 +27,6 @@
#include "../Config.h"
#include "ChunkFile.h"
#include "FixedSizeQueue.h"
#include "Common/Thread.h"
#include "Common/Atomics.h"
#include "../../native/base/mutex.h"

View File

@ -29,7 +29,6 @@
#include "gfx_es2/gl_state.h"
#endif
#include "Common/Thread.h"
#include "Core/CoreTiming.h"
#include "Core/CoreParameter.h"
#include "Core/Reporting.h"
@ -464,7 +463,7 @@ void DoFrameTiming(bool &throttle, bool &skipFrame, float timestep) {
} else {
// Wait until we've caught up.
while (time_now_d() < nextFrameTime) {
Common::SleepCurrentThread(1);
sleep_ms(1); // Sleep for 1ms on this thread
time_update();
}
}

View File

@ -40,7 +40,6 @@ SOURCES += ../Common/ChunkFile.cpp \
../Common/Misc.cpp \
../Common/MsgHandler.cpp \
../Common/StringUtils.cpp \
../Common/Thread.cpp \
../Common/ThreadPools.cpp \
../Common/Timer.cpp \
../Common/Crypto/*.cpp
@ -54,7 +53,6 @@ HEADERS += ../Common/ChunkFile.h \
../Common/MemoryUtil.h \
../Common/MsgHandler.h \
../Common/StringUtils.h \
../Common/Thread.h \
../Common/ThreadPools.h \
../Common/Timer.h \
../Common/Crypto/*.h

View File

@ -249,7 +249,6 @@ void QtHost::NextGPUStep()
void NativeInit(int argc, const char *argv[], const char *savegame_directory, const char *external_directory, const char *installID)
{
Common::EnableCrashingOnCrashes();
isMessagePending = false;
std::string user_data_path = savegame_directory;

View File

@ -37,6 +37,7 @@
#include "native/ext/stb_image_write/stb_image_writer.h"
#include "native/ext/jpge/jpge.h"
#include "native/util/text/utf8.h"
#include "native/thread/thread.h"
#include "gfx_es2/gl_state.h"
#include "gfx_es2/draw_text.h"
#include "gfx_es2/draw_buffer.h"

View File

@ -156,9 +156,31 @@ std::string System_GetProperty(SystemProperty prop) {
}
}
void EnableCrashingOnCrashes()
{
typedef BOOL (WINAPI *tGetPolicy)(LPDWORD lpFlags);
typedef BOOL (WINAPI *tSetPolicy)(DWORD dwFlags);
const DWORD EXCEPTION_SWALLOWING = 0x1;
HMODULE kernel32 = LoadLibraryA("kernel32.dll");
tGetPolicy pGetPolicy = (tGetPolicy)GetProcAddress(kernel32,
"GetProcessUserModeExceptionPolicy");
tSetPolicy pSetPolicy = (tSetPolicy)GetProcAddress(kernel32,
"SetProcessUserModeExceptionPolicy");
if (pGetPolicy && pSetPolicy)
{
DWORD dwFlags;
if (pGetPolicy(&dwFlags))
{
// Turn off the filter
pSetPolicy(dwFlags & ~EXCEPTION_SWALLOWING);
}
}
}
int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow)
{
Common::EnableCrashingOnCrashes();
EnableCrashingOnCrashes();
wchar_t modulePath[MAX_PATH];
GetModuleFileName(NULL, modulePath, MAX_PATH);

View File

@ -119,7 +119,6 @@ EXEC_AND_LIB_FILES := \
$(SRC)/Common/MsgHandler.cpp \
$(SRC)/Common/FileUtil.cpp \
$(SRC)/Common/StringUtils.cpp \
$(SRC)/Common/Thread.cpp \
$(SRC)/Common/ThreadPools.cpp \
$(SRC)/Common/Timer.cpp \
$(SRC)/Common/Misc.cpp \