forked from vmangos/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MaxSessionDuration to realmd (vmangos#2687)
* Make m_ServiceStatus volatile * Add type size to eAuthCmd and AuthResult * NativeIO: Realmd: First impl of `LogonChallenge` just like cMangos Currently only windows support. Using legacy `::select` function. Must use IOCTL in the future. * Add "Network" to log type string * Make m_ServiceStatus volatile (again) * SRP6 add const to parameter * Database add DbExecMode to force sync statements (prevent race condition) * Reimplement most AuthSocket handers async (like cMangos) * Use high performance winsock2 async sockets The implementation is inspired by Boost::ASIO and Nginx * Async networking: Split declaration and definition inside header * Async networking: Move implementation into own folder * Fix ATTR_PRINTF on PExecute with DbExecMode * Add function IO::Multithreading::CreateThread with nameable threads * Add IO::Timer::AsyncSystemTimer * Change RunEventLoop error handling * Remove Timer was already removed error log * Add comment explaining why we cant use `SetThreadDescription` * Remove `MaNGOS::` prefix from `IO::` namespace
- Loading branch information
Showing
20 changed files
with
378 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "CreateThread.h" | ||
|
||
#if defined(WIN32) | ||
#include <Windows.h> | ||
#elif defined(__linux__) | ||
#include <pthread.h> | ||
#endif | ||
|
||
std::thread IO::Multithreading::CreateThread(std::string const& name, std::function<void()> entryFunction) | ||
{ | ||
return std::thread([name, entryFunction = std::move(entryFunction)]() | ||
{ | ||
IO::Multithreading::RenameCurrentThread(name); | ||
entryFunction(); | ||
}); | ||
} | ||
|
||
void IO::Multithreading::RenameCurrentThread(std::string const& name) | ||
{ | ||
#if defined(WIN32) | ||
// Windows part taken from https://stackoverflow.com/a/23899379 | ||
// SetThreadDescription is only supported on >= Win10, that's why we are using this approach | ||
|
||
const DWORD MS_VC_EXCEPTION=0x406D1388; | ||
#pragma pack(push,8) | ||
typedef struct tagTHREADNAME_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. | ||
} THREADNAME_INFO; | ||
#pragma pack(pop) | ||
|
||
THREADNAME_INFO info; | ||
info.dwType = 0x1000; | ||
info.szName = name.c_str(); | ||
info.dwThreadID = GetCurrentThreadId(); | ||
info.dwFlags = 0; | ||
|
||
__try | ||
{ | ||
RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info ); | ||
} | ||
__except(EXCEPTION_EXECUTE_HANDLER) | ||
{ | ||
} | ||
#elif defined(__linux__) | ||
pthread_setname_np(pthread_self(), name.c_str()); | ||
#else | ||
// It's not too serisous if we cant rename a thread | ||
#warning "IO::Multithreading::_renameThisThread not supported on your platform" | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef MANGOS_CREATETHREAD_H | ||
#define MANGOS_CREATETHREAD_H | ||
|
||
#include <thread> | ||
#include <functional> | ||
|
||
namespace IO { namespace Multithreading { | ||
/// Creates a new system thread that has a name attached to it. | ||
/// Names are super useful when monitoring the utilization of each thread. | ||
[[nodiscard("Use this return value to at least .join() or .detach() the thread")]] | ||
std::thread CreateThread(std::string const& name, std::function<void()> entryFunction); | ||
|
||
/// Will rename your current thread. | ||
/// Names are super useful when monitoring the utilization of each thread. | ||
void RenameCurrentThread(std::string const& name); | ||
}} // namespace IO::Multithreading | ||
|
||
#endif //MANGOS_CREATETHREAD_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.