本文整理汇总了C++中GetProcessAffinityMask函数的典型用法代码示例。如果您正苦于以下问题:C++ GetProcessAffinityMask函数的具体用法?C++ GetProcessAffinityMask怎么用?C++ GetProcessAffinityMask使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetProcessAffinityMask函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: __
int Master::Run()
{
sLog.outString(" ___ _ _ ___ ");
sLog.outString(" / _ \\ | |_ ___ _ __ (_) __ / __| ___ _ _ ___ ");
sLog.outString(" / /_\\ \\ | _| / _ \\ | ' \\ | | / _| | (__ / _ \\ | '_| / -_)");
sLog.outString("/_/ \\_\\ \\__| \\___/ |_|_|_| |_| \\__| \\___| \\___/ |_| \\___|");
sLog.outString("");
std::string pidfile = sConfig.GetStringDefault("PidFile", "");
if (!pidfile.empty())
{
uint32 pid = CreatePIDFile(pidfile);
if (!pid)
{
sLog.outError("Cannot create PID file %s.\n", pidfile.c_str());
return 1;
}
sLog.outString("Daemon PID: %u\n", pid);
}
if (!_StartDB())
return 1;
sWorld.SetInitialWorldSettings();
_HookSignals();
ACE_Based::Thread world_thread(new WorldRunnable);
world_thread.setPriority(ACE_Based::Highest);
std::string builds = AcceptableClientBuildsListStr();
LoginDatabase.escape_string(builds);
LoginDatabase.PExecute("UPDATE realmlist SET flag = flag & ~(%u), population = 0, gamebuild = '%s' WHERE id = '%d'", REALM_FLAG_OFFLINE, builds.c_str(), realmID);
ACE_Based::Thread* cliThread = NULL;
#ifdef _WIN32
if (sConfig.GetBoolDefault("Console.Enable", true) && (m_ServiceStatus == -1))
#else
if (sConfig.GetBoolDefault("Console.Enable", true))
#endif
{
cliThread = new ACE_Based::Thread(new CliRunnable);
}
ACE_Based::Thread rar_thread(new RARunnable);
#ifdef _WIN32
{
HANDLE hProcess = GetCurrentProcess();
uint32 Aff = sConfig.GetIntDefault("UseProcessors", 0);
if (Aff > 0)
{
ULONG_PTR appAff;
ULONG_PTR sysAff;
if (GetProcessAffinityMask(hProcess,&appAff,&sysAff))
{
ULONG_PTR curAff = Aff & appAff;
if (!curAff)
{
sLog.outError("Processors marked in UseProcessors bitmask (hex) %x not accessible for OregonCore. Accessible processors bitmask (hex): %x",Aff,appAff);
}
else
{
if (SetProcessAffinityMask(hProcess,curAff))
sLog.outString("Using processors (bitmask, hex): %x", curAff);
else
sLog.outError("Can't set used processors (hex): %x",curAff);
}
}
sLog.outString();
}
bool Prio = sConfig.GetBoolDefault("ProcessPriority", false);
if (Prio)
{
if (SetPriorityClass(hProcess,HIGH_PRIORITY_CLASS))
sLog.outString("OregonCore process priority class set to HIGH");
else
sLog.outError("ERROR: Can't set OregonCore process priority class.");
sLog.outString();
}
}
#endif
ACE_Based::Thread* soap_thread = NULL;
if (sConfig.GetBoolDefault("SOAP.Enabled", false))
{
OCSoapRunnable* soapconnectector = new OCSoapRunnable();
soapconnectector->setListenArguments(sConfig.GetStringDefault("SOAP.IP", "127.0.0.1"), uint16(sConfig.GetIntDefault("SOAP.Port", 7878)));
soap_thread = new ACE_Based::Thread(soapconnectector);
}
ACE_Based::Thread* freeze_thread = NULL;
if (uint32 freeze_delay = sConfig.GetIntDefault("MaxCoreStuckTime", 0))
{
FreezeDetectorRunnable *fdr = new FreezeDetectorRunnable();
fdr->SetDelayTime(freeze_delay*1000);
//.........这里部分代码省略.........
示例2: main
//.........这里部分代码省略.........
}
// Launch the listening network socket
RealmAcceptor acceptor;
uint16 rmport = ConfigMgr::GetIntDefault("RealmServerPort", 3724);
std::string bind_ip = ConfigMgr::GetStringDefault("BindIP", "0.0.0.0");
ACE_INET_Addr bind_addr(rmport, bind_ip.c_str());
if (acceptor.open(bind_addr, ACE_Reactor::instance(), ACE_NONBLOCK) == -1)
{
sLog->outError("Auth server can not bind to %s:%d", bind_ip.c_str(), rmport);
return 1;
}
// Initialize the signal handlers
AuthServerSignalHandler SignalINT, SignalTERM;
// Register authservers's signal handlers
ACE_Sig_Handler Handler;
Handler.register_handler(SIGINT, &SignalINT);
Handler.register_handler(SIGTERM, &SignalTERM);
///- Handle affinity for multiple processors and process priority on Windows
#ifdef _WIN32
{
HANDLE hProcess = GetCurrentProcess();
uint32 Aff = ConfigMgr::GetIntDefault("UseProcessors", 0);
if (Aff > 0)
{
ULONG_PTR appAff;
ULONG_PTR sysAff;
if (GetProcessAffinityMask(hProcess, &appAff, &sysAff))
{
ULONG_PTR curAff = Aff & appAff; // remove non accessible processors
if (!curAff)
sLog->outError("Processors marked in UseProcessors bitmask (hex) %x not accessible for authserver. Accessible processors bitmask (hex): %x", Aff, appAff);
else if (SetProcessAffinityMask(hProcess, curAff))
sLog->outString("Using processors (bitmask, hex): %x", curAff);
else
sLog->outError("Can't set used processors (hex): %x", curAff);
}
sLog->outString();
}
bool Prio = ConfigMgr::GetBoolDefault("ProcessPriority", false);
if (Prio)
{
if (SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS))
sLog->outString("The auth server process priority class has been set to HIGH");
else
sLog->outError("Can't set auth server process priority class.");
sLog->outString();
}
}
#endif
// maximum counter for next ping
uint32 numLoops = (ConfigMgr::GetIntDefault("MaxPingTime", 30) * (MINUTE * 1000000 / 100000));
uint32 loopCounter = 0;
// possibly enable db logging; avoid massive startup spam by doing it here.
if (sLog->GetLogDBLater())
{
sLog->outString("Enabling database logging...");
sLog->SetLogDBLater(false);
// login db needs thread for logging
sLog->SetLogDB(true);
}
else
sLog->SetLogDB(false);
// Wait for termination signal
while (!stopEvent)
{
// dont move this outside the loop, the reactor will modify it
ACE_Time_Value interval(0, 100000);
if (ACE_Reactor::instance()->run_reactor_event_loop(interval) == -1)
break;
if ((++loopCounter) == numLoops)
{
loopCounter = 0;
sLog->outDetail("Ping MySQL to keep connection alive");
LoginDatabase.KeepAlive();
}
}
// Close the Database Pool and library
StopDB();
sLog->outString("Halting process...");
return 0;
}
示例3: main
//.........这里部分代码省略.........
ACE_INET_Addr bind_addr(rmport, bind_ip.c_str());
if (acceptor.open(bind_addr, ACE_Reactor::instance(), ACE_NONBLOCK) == -1)
{
sLog->outError("ArkCORE Auth can not bind to %s:%d", bind_ip.c_str(), rmport);
return 1;
}
// Initialise the signal handlers
RealmdSignalHandler SignalINT, SignalTERM;
#ifdef _WIN32
RealmdSignalHandler SignalBREAK;
#endif /* _WIN32 */
// Register realmd's signal handlers
ACE_Sig_Handler Handler;
Handler.register_handler(SIGINT, &SignalINT);
Handler.register_handler(SIGTERM, &SignalTERM);
#ifdef _WIN32
Handler.register_handler(SIGBREAK, &SignalBREAK);
#endif /* _WIN32 */
///- Handle affinity for multiple processors and process priority on Windows
#ifdef _WIN32
{
HANDLE hProcess = GetCurrentProcess();
uint32 Aff = sConfig->GetIntDefault("UseProcessors", 0);
if (Aff > 0)
{
ULONG_PTR appAff;
ULONG_PTR sysAff;
if (GetProcessAffinityMask(hProcess, &appAff, &sysAff))
{
ULONG_PTR curAff = Aff & appAff; // remove non accessible processors
if (!curAff)
sLog->outError("Processors marked in UseProcessors bitmask (hex) %x not accessible for realmd. Accessible processors bitmask (hex): %x", Aff, appAff);
else if (SetProcessAffinityMask(hProcess, curAff))
sLog->outString("Using processors (bitmask, hex): %x", curAff);
else
sLog->outError("Can't set used processors (hex): %x", curAff);
}
sLog->outString();
}
bool Prio = sConfig->GetBoolDefault("ProcessPriority", false);
if (Prio)
{
if (SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS))
sLog->outString("ArkCORE Auth process priority class set to HIGH");
else
sLog->outError("Can't set realmd process priority class.");
sLog->outString();
}
}
#endif
// maximum counter for next ping
uint32 numLoops = (sConfig->GetIntDefault("MaxPingTime", 30) * (MINUTE * 1000000 / 100000));
uint32 loopCounter = 0;
// possibly enable db logging; avoid massive startup spam by doing it here.
if (sLog->GetLogDBLater())
示例4: CreatePIDFile
/// Main function
int Master::Run()
{
/// worldd PID file creation
std::string pidfile = sConfig.GetStringDefault("PidFile", "");
if (!pidfile.empty())
{
uint32 pid = CreatePIDFile(pidfile);
if (!pid)
{
sLog.outError("Cannot create PID file %s.\n", pidfile.c_str());
Log::WaitBeforeContinueIfNeed();
return 1;
}
sLog.outString("Daemon PID: %u\n", pid);
}
///- Start the databases
if (!_StartDB())
{
Log::WaitBeforeContinueIfNeed();
return 1;
}
///- Initialize the World
sWorld.SetInitialWorldSettings();
#ifndef WIN32
detachDaemon();
#endif
// server loaded successfully => enable async DB requests
// this is done to forbid any async transactions during server startup!
CharacterDatabase.AllowAsyncTransactions();
WorldDatabase.AllowAsyncTransactions();
LoginDatabase.AllowAsyncTransactions();
///- Catch termination signals
_HookSignals();
///- Launch WorldRunnable thread
ACE_Based::Thread world_thread(new WorldRunnable);
world_thread.setPriority(ACE_Based::Highest);
// set realmbuilds depend on worldserver expected builds, and set server online
{
std::string builds = AcceptableClientBuildsListStr();
LoginDatabase.escape_string(builds);
LoginDatabase.DirectPExecute("UPDATE realmlist SET realmflags = realmflags & ~(%u), population = 0, realmbuilds = '%s' WHERE id = '%u'", REALM_FLAG_OFFLINE, builds.c_str(), realmID);
}
ACE_Based::Thread* cliThread = NULL;
#ifdef WIN32
if (sConfig.GetBoolDefault("Console.Enable", true) && (m_ServiceStatus == -1)/* need disable console in service mode*/)
#else
if (sConfig.GetBoolDefault("Console.Enable", true))
#endif
{
///- Launch CliRunnable thread
cliThread = new ACE_Based::Thread(new CliRunnable);
}
ACE_Based::Thread* rar_thread = NULL;
if (sConfig.GetBoolDefault("Ra.Enable", false))
{
rar_thread = new ACE_Based::Thread(new RARunnable);
}
///- Handle affinity for multiple processors and process priority on Windows
#ifdef WIN32
{
HANDLE hProcess = GetCurrentProcess();
uint32 Aff = sConfig.GetIntDefault("UseProcessors", 0);
if (Aff > 0)
{
ULONG_PTR appAff;
ULONG_PTR sysAff;
if (GetProcessAffinityMask(hProcess, &appAff, &sysAff))
{
ULONG_PTR curAff = Aff & appAff; // remove non accessible processors
if (!curAff)
{
sLog.outError("Processors marked in UseProcessors bitmask (hex) %x not accessible for worldserver. Accessible processors bitmask (hex): %x", Aff, appAff);
}
else
{
if (SetProcessAffinityMask(hProcess, curAff))
sLog.outString("Using processors (bitmask, hex): %x", curAff);
else
sLog.outError("Can't set used processors (hex): %x", curAff);
}
}
sLog.outString();
}
bool Prio = sConfig.GetBoolDefault("ProcessPriority", false);
//.........这里部分代码省略.........
示例5: TC_LOG_INFO
/// Main function
int Master::Run()
{
OpenSSLCrypto::threadsSetup();
BigNumber seed1;
seed1.SetRand(16 * 8);
TC_LOG_INFO("server.worldserver", "%s (worldserver-daemon)", _FULLVERSION);
TC_LOG_INFO("server.worldserver", "<Ctrl-C> to stop.\n");
TC_LOG_INFO("server.worldserver", " ______ __");
TC_LOG_INFO("server.worldserver", "/\\__ _\\ __ __/\\ \\__");
TC_LOG_INFO("server.worldserver", "\\/_/\\ \\/ _ __ /\\_\\ ___ /\\_\\ \\, _\\ __ __");
TC_LOG_INFO("server.worldserver", " \\ \\ \\/\\`'__\\/\\ \\ /' _ `\\/\\ \\ \\ \\/ /\\ \\/\\ \\");
TC_LOG_INFO("server.worldserver", " \\ \\ \\ \\ \\/ \\ \\ \\/\\ \\/\\ \\ \\ \\ \\ \\_\\ \\ \\_\\ \\");
TC_LOG_INFO("server.worldserver", " \\ \\_\\ \\_\\ \\ \\_\\ \\_\\ \\_\\ \\_\\ \\__\\\\/`____ \\");
TC_LOG_INFO("server.worldserver", " \\/_/\\/_/ \\/_/\\/_/\\/_/\\/_/\\/__/ `/___/> \\");
TC_LOG_INFO("server.worldserver", " C O R E /\\___/");
TC_LOG_INFO("server.worldserver", "http://TrinityCore.org \\/__/\n");
/// worldserver PID file creation
std::string pidFile = sConfigMgr->GetStringDefault("PidFile", "");
if (!pidFile.empty())
{
if (uint32 pid = CreatePIDFile(pidFile))
TC_LOG_INFO("server.worldserver", "Daemon PID: %u\n", pid);
else
{
TC_LOG_ERROR("server.worldserver", "Cannot create PID file %s.\n", pidFile.c_str());
return 1;
}
}
///- Start the databases
if (!_StartDB())
return 1;
// set server offline (not connectable)
LoginDatabase.DirectPExecute("UPDATE realmlist SET flag = (flag & ~%u) | %u WHERE id = '%d'", REALM_FLAG_OFFLINE, REALM_FLAG_INVALID, realmID);
///- Initialize the World
sWorld->SetInitialWorldSettings();
///- Initialize the signal handlers
WorldServerSignalHandler signalINT, signalTERM;
#ifdef _WIN32
WorldServerSignalHandler signalBREAK;
#endif /* _WIN32 */
///- Register worldserver's signal handlers
ACE_Sig_Handler handle;
handle.register_handler(SIGINT, &signalINT);
handle.register_handler(SIGTERM, &signalTERM);
#ifdef _WIN32
handle.register_handler(SIGBREAK, &signalBREAK);
#endif
///- Launch WorldRunnable thread
ACE_Based::Thread worldThread(new WorldRunnable);
worldThread.setPriority(ACE_Based::Highest);
ACE_Based::Thread* cliThread = NULL;
#ifdef _WIN32
if (sConfigMgr->GetBoolDefault("Console.Enable", true) && (m_ServiceStatus == -1)/* need disable console in service mode*/)
#else
if (sConfigMgr->GetBoolDefault("Console.Enable", true))
#endif
{
///- Launch CliRunnable thread
cliThread = new ACE_Based::Thread(new CliRunnable);
}
ACE_Based::Thread rarThread(new RARunnable);
#if defined(_WIN32) || defined(__linux__)
///- Handle affinity for multiple processors and process priority
uint32 affinity = sConfigMgr->GetIntDefault("UseProcessors", 0);
bool highPriority = sConfigMgr->GetBoolDefault("ProcessPriority", false);
#ifdef _WIN32 // Windows
HANDLE hProcess = GetCurrentProcess();
if (affinity > 0)
{
ULONG_PTR appAff;
ULONG_PTR sysAff;
if (GetProcessAffinityMask(hProcess, &appAff, &sysAff))
{
ULONG_PTR currentAffinity = affinity & appAff; // remove non accessible processors
if (!currentAffinity)
TC_LOG_ERROR("server.worldserver", "Processors marked in UseProcessors bitmask (hex) %x are not accessible for the worldserver. Accessible processors bitmask (hex): %x", affinity, appAff);
else if (SetProcessAffinityMask(hProcess, currentAffinity))
TC_LOG_INFO("server.worldserver", "Using processors (bitmask, hex): %x", currentAffinity);
else
TC_LOG_ERROR("server.worldserver", "Can't set used processors (hex): %x", currentAffinity);
//.........这里部分代码省略.........
示例6: main
//.........这里部分代码省略.........
LoginDatabase.Execute("UPDATE account_banned SET active = 0 WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
LoginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
LoginDatabase.CommitTransaction();
///- Launch the listening network socket
ACE_Acceptor<AuthSocket, ACE_SOCK_Acceptor> acceptor;
uint16 rmport = sConfig.GetIntDefault("RealmServerPort", DEFAULT_REALMSERVER_PORT);
std::string bind_ip = sConfig.GetStringDefault("BindIP", "0.0.0.0");
ACE_INET_Addr bind_addr(rmport, bind_ip.c_str());
if (acceptor.open(bind_addr, ACE_Reactor::instance(), ACE_NONBLOCK) == -1)
{
sLog.outError("MaNGOS realmd can not bind to %s:%d", bind_ip.c_str(), rmport);
Log::WaitBeforeContinueIfNeed();
return 1;
}
///- Catch termination signals
HookSignals();
///- Handle affinity for multiple processors and process priority on Windows
#ifdef WIN32
{
HANDLE hProcess = GetCurrentProcess();
uint32 Aff = sConfig.GetIntDefault("UseProcessors", 0);
if (Aff > 0)
{
ULONG_PTR appAff;
ULONG_PTR sysAff;
if (GetProcessAffinityMask(hProcess, &appAff, &sysAff))
{
ULONG_PTR curAff = Aff & appAff; // remove non accessible processors
if (!curAff)
{
sLog.outError("Processors marked in UseProcessors bitmask (hex) %x not accessible for realmd. Accessible processors bitmask (hex): %x", Aff, appAff);
}
else
{
if (SetProcessAffinityMask(hProcess, curAff))
sLog.outString("Using processors (bitmask, hex): %x", curAff);
else
sLog.outError("Can't set used processors (hex): %x", curAff);
}
}
sLog.outString();
}
bool Prio = sConfig.GetBoolDefault("ProcessPriority", false);
if (Prio)
{
if (SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS))
sLog.outString("realmd process priority class set to HIGH");
else
sLog.outError("Can't set realmd process priority class.");
sLog.outString();
}
}
#endif
// server has started up successfully => enable async DB requests
示例7: defined
RakNetTimeUS RakNet::GetTimeNS( void )
{
#if defined(_PS3) || defined(__PS3__) || defined(SN_TARGET_PS3)
uint64_t curTime;
if ( initialized == false)
{
ticksPerSecond = _PS3_GetTicksPerSecond();
// Use the function to get elapsed ticks, this is a macro.
_PS3_GetElapsedTicks(curTime);
uint64_t quotient, remainder;
quotient=(curTime / ticksPerSecond);
remainder=(curTime % ticksPerSecond);
initialTime = (RakNetTimeUS) quotient*(RakNetTimeUS)1000000 + (remainder*(RakNetTimeUS)1000000 / ticksPerSecond);
initialized = true;
}
#elif defined(_WIN32)
// Win32
if ( initialized == false)
{
initialized = true;
#if !defined(_WIN32_WCE) && !defined(_XBOX) && !defined(X360)
// Save the current process
HANDLE mProc = GetCurrentProcess();
// Get the current Affinity
#if _MSC_VER >= 1400 && defined (_M_X64)
GetProcessAffinityMask(mProc, (PDWORD_PTR)&mProcMask, (PDWORD_PTR)&mSysMask);
#else
GetProcessAffinityMask(mProc, &mProcMask, &mSysMask);
#endif
mThread = GetCurrentThread();
#endif // !defined(_WIN32_WCE)
QueryPerformanceFrequency( &yo );
}
// 01/12/08 - According to the docs "The frequency cannot change while the system is running." so this shouldn't be necessary
/*
if (++queryCount==200)
{
// Set affinity to the first core
SetThreadAffinityMask(mThread, 1);
QueryPerformanceFrequency( &yo );
// Reset affinity
SetThreadAffinityMask(mThread, mProcMask);
queryCount=0;
}
*/
#elif (defined(__GNUC__) || defined(__GCCXML__))
if ( initialized == false)
{
gettimeofday( &tp, 0 );
initialized=true;
// I do this because otherwise RakNetTime in milliseconds won't work as it will underflow when dividing by 1000 to do the conversion
initialTime = ( tp.tv_sec ) * (RakNetTimeUS) 1000000 + ( tp.tv_usec );
}
#endif
#if defined(_PS3) || defined(__PS3__) || defined(SN_TARGET_PS3)
// Use the function to get elapsed ticks, this is a macro.
_PS3_GetElapsedTicks(curTime);
uint64_t quotient, remainder;
quotient=(curTime / ticksPerSecond);
remainder=(curTime % ticksPerSecond);
curTime = (RakNetTimeUS) quotient*(RakNetTimeUS)1000000 + (remainder*(RakNetTimeUS)1000000 / ticksPerSecond);
// Subtract from initialTime so the millisecond conversion does not underflow
return curTime - initialTime;
#elif defined(_WIN32)
RakNetTimeUS curTime;
static RakNetTimeUS lastQueryVal=(RakNetTimeUS)0;
// static unsigned long lastTickCountVal = GetTickCount();
LARGE_INTEGER PerfVal;
#if !defined(_WIN32_WCE) && !defined(_XBOX) && !defined(X360)
// Set affinity to the first core
SetThreadAffinityMask(mThread, 1);
#endif // !defined(_WIN32_WCE)
// Docs: On a multiprocessor computer, it should not matter which processor is called.
// However, you can get different results on different processors due to bugs in the basic input/output system (BIOS) or the hardware abstraction layer (HAL). To specify processor affinity for a thread, use the SetThreadAffinityMask function.
// Query the timer
QueryPerformanceCounter( &PerfVal );
#if !defined(_WIN32_WCE) && !defined(_XBOX) && !defined(X360)
// Reset affinity
SetThreadAffinityMask(mThread, mProcMask);
#endif // !defined(_WIN32_WCE)
__int64 quotient, remainder;
quotient=((PerfVal.QuadPart) / yo.QuadPart);
remainder=((PerfVal.QuadPart) % yo.QuadPart);
curTime = (RakNetTimeUS) quotient*(RakNetTimeUS)1000000 + (remainder*(RakNetTimeUS)1000000 / yo.QuadPart);
//.........这里部分代码省略.........
示例8: windows_init_clock
static bool windows_init_clock(struct libusb_context *ctx)
{
DWORD_PTR affinity, dummy;
HANDLE event = NULL;
LARGE_INTEGER li_frequency;
int i;
if (QueryPerformanceFrequency(&li_frequency)) {
// Load DLL imports
if (windows_init_dlls() != LIBUSB_SUCCESS) {
usbi_err(ctx, "could not resolve DLL functions");
return false;
}
// The hires frequency can go as high as 4 GHz, so we'll use a conversion
// to picoseconds to compute the tv_nsecs part in clock_gettime
hires_frequency = li_frequency.QuadPart;
hires_ticks_to_ps = UINT64_C(1000000000000) / hires_frequency;
usbi_dbg("hires timer available (Frequency: %"PRIu64" Hz)", hires_frequency);
// Because QueryPerformanceCounter might report different values when
// running on different cores, we create a separate thread for the timer
// calls, which we glue to the first available core always to prevent timing discrepancies.
if (!GetProcessAffinityMask(GetCurrentProcess(), &affinity, &dummy) || (affinity == 0)) {
usbi_err(ctx, "could not get process affinity: %s", windows_error_str(0));
return false;
}
// The process affinity mask is a bitmask where each set bit represents a core on
// which this process is allowed to run, so we find the first set bit
for (i = 0; !(affinity & (DWORD_PTR)(1 << i)); i++);
affinity = (DWORD_PTR)(1 << i);
usbi_dbg("timer thread will run on core #%d", i);
event = CreateEvent(NULL, FALSE, FALSE, NULL);
if (event == NULL) {
usbi_err(ctx, "could not create event: %s", windows_error_str(0));
return false;
}
timer_thread = (HANDLE)_beginthreadex(NULL, 0, windows_clock_gettime_threaded, (void *)event,
0, (unsigned int *)&timer_thread_id);
if (timer_thread == NULL) {
usbi_err(ctx, "unable to create timer thread - aborting");
CloseHandle(event);
return false;
}
if (!SetThreadAffinityMask(timer_thread, affinity))
usbi_warn(ctx, "unable to set timer thread affinity, timer discrepancies may arise");
// Wait for timer thread to init before continuing.
if (WaitForSingleObject(event, INFINITE) != WAIT_OBJECT_0) {
usbi_err(ctx, "failed to wait for timer thread to become ready - aborting");
CloseHandle(event);
return false;
}
CloseHandle(event);
} else {
usbi_dbg("no hires timer available on this platform");
hires_frequency = 0;
hires_ticks_to_ps = UINT64_C(0);
}
return true;
}
示例9: main
//.........这里部分代码省略.........
{
sLog.outError("No valid realms specified.");
Log::WaitBeforeContinueIfNeed();
return 1;
}
// cleanup query
// set expired bans to inactive
LoginDatabase.BeginTransaction();
LoginDatabase.Execute("UPDATE account_banned SET active = 0 WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
LoginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
LoginDatabase.CommitTransaction();
auto rmport = sConfig.GetIntDefault("RealmServerPort", DEFAULT_REALMSERVER_PORT);
std::string bind_ip = sConfig.GetStringDefault("BindIP", "0.0.0.0");
// FIXME - more intelligent selection of thread count is needed here. config option?
MaNGOS::Listener<AuthSocket> listener(rmport, 1);
///- Catch termination signals
HookSignals();
///- Handle affinity for multiple processors and process priority on Windows
#ifdef _WIN32
{
HANDLE hProcess = GetCurrentProcess();
uint32 Aff = sConfig.GetIntDefault("UseProcessors", 0);
if (Aff > 0)
{
ULONG_PTR appAff;
ULONG_PTR sysAff;
if (GetProcessAffinityMask(hProcess, &appAff, &sysAff))
{
ULONG_PTR curAff = Aff & appAff; // remove non accessible processors
if (!curAff)
{
sLog.outError("Processors marked in UseProcessors bitmask (hex) %x not accessible for realmd. Accessible processors bitmask (hex): %x", Aff, appAff);
}
else
{
if (SetProcessAffinityMask(hProcess, curAff))
sLog.outString("Using processors (bitmask, hex): %x", curAff);
else
sLog.outError("Can't set used processors (hex): %x", curAff);
}
}
sLog.outString();
}
bool Prio = sConfig.GetBoolDefault("ProcessPriority", false);
if (Prio)
{
if (SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS))
sLog.outString("realmd process priority class set to HIGH");
else
sLog.outError("Can't set realmd process priority class.");
sLog.outString();
}
}
#endif
// server has started up successfully => enable async DB requests
示例10: sysVisibleConsole
int WindowProfiler::run
(
const std::string& title,
int argc, const char** argv,
int width, int height,
int Major, int Minor
)
{
s_project = this;
sysVisibleConsole();
#if _WIN32
if (m_singleThreaded)
{
HANDLE proc = GetCurrentProcess();
size_t procmask;
size_t sysmask;
// pin to one physical cpu for smoother timings, disable hyperthreading
GetProcessAffinityMask(proc,(PDWORD_PTR)&procmask,(PDWORD_PTR)&sysmask);
if (sysmask & 8){
// quadcore, use last core
procmask = 8;
}
else if (sysmask & 2){
// dualcore, use last core
procmask = 2;
}
SetProcessAffinityMask(proc,(DWORD_PTR)procmask);
}
#endif
bool vsyncstate = true;
unsigned int intervalSeconds = 2;
unsigned int frameLimit = 0;
unsigned int timerLimit = 0;
const char* dumpatexit = NULL;
for (int i = 0; i < argc; i++){
if (strcmp(argv[i],"-winsize") == 0 && i + 2 < argc){
width = atoi(argv[i+1]);
height = atoi(argv[i+2]);
i+=2;
}
if (strcmp(argv[i],"-vsync") == 0 && i + 1 < argc){
vsyncstate = atoi(argv[i+1]) ? true : false;
i+=1;
}
if (strcmp(argv[i],"-frames")==0 && i+1<argc){
frameLimit = atoi(argv[i+1]);
i++;
}
if (strcmp(argv[i],"-timerprints")==0 && i+1<argc){
timerLimit = atoi(argv[i+1]);
i++;
}
if (strcmp(argv[i],"-timerinterval")==0 && i+1<argc){
intervalSeconds = atoi(argv[i+1]);
i++;
}
if (strcmp(argv[i],"-bmpatexit")==0 && i+1<argc){
dumpatexit = argv[i+1];
i++;
}
}
ContextFlags flags;
flags.major = Major;
flags.minor = Minor;
flags.robust = 0;
flags.core = 0;
#ifdef NDEBUG
flags.debug = 0;
#else
flags.debug = 1;
#endif
flags.share = NULL;
if (!activate(width,height,title.c_str(), &flags)){
printf("Could not create GL context: %d.%d\n",flags.major,flags.minor);
return EXIT_FAILURE;
}
vsync( vsyncstate );
m_window.m_viewsize[0] = width;
m_window.m_viewsize[1] = height;
m_profiler.init();
m_gltimers.init(m_profiler.getRequiredTimers());
m_profiler.setDefaultGPUInterface(&m_gltimers);
bool Run = begin();
m_active = true;
double timeStart = sysGetTime();
double timeBegin = sysGetTime();
double frames = 0;
bool lastVsync = m_vsync;
//.........这里部分代码省略.........
示例11: main
void main(int argc, char *argv[])
{
clock_t startCPU;
time_t startTime;
double elapsedTime, cpuTime;
uint64_t clock_reg;
int pf0 = getPagefault();
#ifdef SMARTHEAP
MemRegisterTask();
#endif
setbuf(stdout, NULL); /* turn off buffering for output */
if (argc > 1)
fin = fopen(argv[1], "r");
else
fin = stdin;
if (argc > 2)
fout = fopen(argv[2], "w");
else
fout = stdout;
if(fin == NULL || fout == NULL) {
fprintf(stderr, "Could not open file(s): ");
int i=1;
for(i=1; i<argc;i++) {
fprintf(stderr, "%s ", argv[i]);
}
fprintf(stderr, "\n");
exit(-1);
}
ulCallCount = promptAndRead("call count", ulCallCount, 'u');
uMinBlockSize = (unsigned)promptAndRead("min block size",uMinBlockSize,'u');
uMaxBlockSize = (unsigned)promptAndRead("max block size",uMaxBlockSize,'u');
#ifdef HEAPALLOC_WRAPPER
LoadLibrary("shsmpsys.dll");
#endif
#ifdef SYS_MULTI_THREAD
{
unsigned i;
void *threadArg = NULL;
ThreadID *tids;
#ifdef WIN32
//unsigned uCPUs = promptAndRead("CPUs (0 for all)", 0, 'u');
if (uCPUs)
{
DWORD m1, m2;
if (GetProcessAffinityMask(GetCurrentProcess(), &m1, &m2))
{
i = 0;
m1 = 1;
/*
* iterate through process affinity mask m2, counting CPUs up to
* the limit specified in uCPUs
*/
do
if (m2 & m1)
i++;
while ((m1 <<= 1) && i < uCPUs);
/* clear any extra CPUs in affinity mask */
do
if (m2 & m1)
m2 &= ~m1;
while (m1 <<= 1);
if (SetProcessAffinityMask(GetCurrentProcess(), m2))
fprintf(fout,
"\nThreads in benchmark will run on max of %u CPUs", i);
}
}
#endif /* WIN32 */
uThreadCount = uCPUs;//(int)promptAndRead("threads", GetNumProcessors(), 'u');
if (uThreadCount < 1)
uThreadCount = 1;
ulCallCount /= uThreadCount;
if ((tids = malloc(sizeof(ThreadID) * uThreadCount)) != NULL)
{
startCPU = clock();
startTime = time(NULL);
clock_reg = rdtsc();
UPDATENETMEM(mallinfo().uordblks + ulCallCount * sizeof(void *));
for (i = 0; i < uThreadCount; i++) {
if (THREAD_EQ(tids[i] = RunThread(doBench, threadArg),THREAD_NULL))
{
fprintf(fout, "\nfailed to start thread #%d", i);
break;
}
//.........这里部分代码省略.........
示例12: SpecialEcsAccess
//
// Performs special Extended Configuration Space access.
//
// It takes advantage of AMD-specific IO CF8h/CFCh extension that enables
// accesses to PCI Extended Configuration Space. Access is realized by
// enabling ECS access via IOCF8/IOCFC using EnableCf8ExtCfg from NB_CFG
// MSR (MSRC001_001F) and performing CF8h/CFCh access per specifciation.
// State of NB_CFG and IOCF8 is saved before the operation and gets
// restored afterwards. Calling process is also bound to first CPU
// in the system for the duration of the operation to accommodate
// environments with multiple northbridges.
//
// EnableCf8ExtCfg is supported by all currently supported CPU families,
// that is, 10h, 11h, 12h, 14h, 15h and 16h.
//
// IO CF8h/CFCh method, while racy, is the only feasible method to access
// PCI ECS on Windows XP/2003 (accessing memory mapped configuration space
// is off the table due to lack of physical memory access support
// in WinRing0).
//
// Best effort is put to detect simultaneous users of CF8h/CFCh.
//
bool SpecialEcsAccess(bool write, DWORD devfunc, DWORD reg, DWORD *res)
{
DWORD_PTR mask_save;
DWORD_PTR dummy;
DWORD eax_save;
DWORD edx_save;
DWORD edx;
DWORD addr;
DWORD addr_save;
DWORD addr_check;
DWORD data;
bool result = false;
if (!GetProcessAffinityMask((HANDLE)-1, &mask_save, &dummy)) {
fprintf(stderr, "ERROR getting affinity mask\n");
goto out;
}
if (!SetProcessAffinityMask((HANDLE)-1, 1)) {
fprintf(stderr, "ERROR setting affinity mask\n");
goto out;
}
if (!RdmsrPx(0xC001001F, &eax_save, &edx_save, 1)) {
fprintf(stderr, "ERROR reading NB_CFG\n");
goto out_affinity;
}
edx = edx_save;
edx |= 0x4000;
if (!WrmsrPx(0xC001001F, eax_save, edx, (DWORD_PTR)1)) {
fprintf(stderr, "ERROR writing NB_CFG\n");
goto out_affinity;
}
addr_save = ReadIoPortDword(0xcf8);
addr = 1;
addr <<= 7;
addr |= (reg >> 8) & 0x0F;
addr <<= 16;
addr |= devfunc & 0xFFFF;
addr <<= 8;
addr |= reg & 0xFF;
WriteIoPortDword(0xcf8, addr);
if (write == false) {
data = ReadIoPortDword(0xcfc);
} else {
WriteIoPortDword(0xcfc, *res);
}
addr_check = ReadIoPortDword(0xcf8);
if (addr_check != addr) {
fprintf(stderr, "ERROR: IO CF8h hijacked!\n");
goto out_nbcfg;
}
WriteIoPortDword(0xcf8, addr_save);
if (write == false) {
*res = data;
}
result = true;
out_nbcfg:
WrmsrPx(0xC001001F, eax_save, edx_save, (DWORD_PTR)1);
out_affinity:
SetProcessAffinityMask((HANDLE)-1, mask_save);
out:
return result;
}
示例13: main
//.........这里部分代码省略.........
ACE_INET_Addr bind_addr(rmport, bind_ip.c_str());
if (acceptor.open(bind_addr, ACE_Reactor::instance(), ACE_NONBLOCK) == -1)
{
sLog->outError("StarGateAuth nicht zu binden %s:%d", bind_ip.c_str(), rmport);
return 1;
}
// Initialise the signal handlers
RealmdSignalHandler SignalINT, SignalTERM;
#ifdef _WIN32
RealmdSignalHandler SignalBREAK;
#endif /* _WIN32 */
// Register realmd's signal handlers
ACE_Sig_Handler Handler;
Handler.register_handler(SIGINT, &SignalINT);
Handler.register_handler(SIGTERM, &SignalTERM);
#ifdef _WIN32
Handler.register_handler(SIGBREAK, &SignalBREAK);
#endif /* _WIN32 */
///- Handle affinity for multiple processors and process priority on Windows
#ifdef _WIN32
{
HANDLE hProcess = GetCurrentProcess();
uint32 Aff = sConfig->GetIntDefault("UseProcessors", 0);
if (Aff > 0)
{
ULONG_PTR appAff;
ULONG_PTR sysAff;
if (GetProcessAffinityMask(hProcess, &appAff, &sysAff))
{
ULONG_PTR curAff = Aff & appAff; // remove non accessible processors
if (!curAff)
sLog->outError("Prozessoren in UseProcessors Bitmaske markiert (hex) %x nicht zugänglich realmd. Accessible Prozessor Bitmaske (hex): %x", Aff, appAff);
else if (SetProcessAffinityMask(hProcess, curAff))
sLog->outString("Mit Prozessoren (bitmask, hex): %x", curAff);
else
sLog->outError("Kann verwendeter Prozessor nicht festgelegen!.(hex): %x", curAff);
}
}
bool Prio = sConfig->GetBoolDefault("ProcessPriority", false);
if (Prio)
{
if (SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS))
sLog->outString("[StarGate-Auth] Prozess-Priorität festgelegt auf HOCH");
else
sLog->outError("Realmd Prozess-Priorität Fehler!.");
}
}
#endif
// maximum counter for next ping
uint32 numLoops = (sConfig->GetIntDefault("MaxPingTime", 30) * (MINUTE * 1000000 / 100000));
uint32 loopCounter = 0;
// possibly enable db logging; avoid massive startup spam by doing it here.
if (sLog->GetLogDBLater())
{
sLog->outString("Aktiviere Datenbankprotokollierung...");
示例14: StartProcess
//.........这里部分代码省略.........
EnablePrivilege(SE_INCREASE_QUOTA_NAME);
EnablePrivilege(SE_IMPERSONATE_NAME);
BOOL bImpersonated = ImpersonateLoggedOnUser(settings.hUser);
if(FALSE == bImpersonated)
{
Log(L"Failed to impersonate", GetLastError());
_ASSERT(bImpersonated);
}
bLaunched = CreateProcessAsUser(settings.hUser, NULL, path.LockBuffer(), NULL, NULL, TRUE, CREATE_SUSPENDED | CREATE_UNICODE_ENVIRONMENT | CREATE_NEW_CONSOLE, pEnvironment, startingDir, &si, &pi);
if(0 == GetLastError())
launchGLE = 0; //mark as successful, otherwise return our original error
path.UnlockBuffer();
#ifdef _DEBUG
if(0 != launchGLE)
Log(StrFormat(L"Launch (launchGLE=%u) params: user=[x%X] path=[%s] pEnv=[%s], dir=[%s], stdin=[x%X], stdout=[x%X], stderr=[x%X]",
launchGLE, (DWORD)settings.hUser, path, pEnvironment ? L"{env}" : L"{null}", startingDir ? startingDir : L"{null}",
(DWORD)si.hStdInput, (DWORD)si.hStdOutput, (DWORD)si.hStdError), false);
#endif
RevertToSelf();
}
}
else
{
Log(StrFormat(L"PAExec starting process [%s] as current user", path), false);
EnablePrivilege(SE_ASSIGNPRIMARYTOKEN_NAME);
EnablePrivilege(SE_INCREASE_QUOTA_NAME);
EnablePrivilege(SE_IMPERSONATE_NAME);
if(NULL != settings.hUser)
bLaunched = CreateProcessAsUser(settings.hUser, NULL, path.LockBuffer(), NULL, NULL, TRUE, dwFlags, pEnvironment, startingDir, &si, &pi);
if(FALSE == bLaunched)
bLaunched = CreateProcess(NULL, path.LockBuffer(), NULL, NULL, TRUE, dwFlags, pEnvironment, startingDir, &si, &pi);
launchGLE = GetLastError();
//#ifdef _DEBUG
if(0 != launchGLE)
Log(StrFormat(L"Launch (launchGLE=%u) params: path=[%s] user=[%s], pEnv=[%s], dir=[%s], stdin=[x%X], stdout=[x%X], stderr=[x%X]",
launchGLE, path, settings.hUser ? L"{non-null}" : L"{null}", pEnvironment ? L"{env}" : L"{null}", startingDir ? startingDir : L"{null}",
(DWORD)si.hStdInput, (DWORD)si.hStdOutput, (DWORD)si.hStdError), false);
//#endif
path.UnlockBuffer();
}
}
if(bLaunched)
{
if(gbInService)
Log(L"Successfully launched", false);
settings.hProcess = pi.hProcess;
settings.processID = pi.dwProcessId;
if(false == settings.allowedProcessors.empty())
{
DWORD sysMask = 0, procMask = 0;
VERIFY(GetProcessAffinityMask(pi.hProcess, &procMask, &sysMask));
procMask = 0;
for(std::vector<WORD>::iterator itr = settings.allowedProcessors.begin(); settings.allowedProcessors.end() != itr; itr++)
{
DWORD bit = 1;
bit = bit << (*itr - 1);
procMask |= bit & sysMask;
}
VERIFY(SetProcessAffinityMask(pi.hProcess, procMask));
}
VERIFY(SetPriorityClass(pi.hProcess, settings.priority));
ResumeThread(pi.hThread);
VERIFY(CloseHandle(pi.hThread));
}
else
{
Log(StrFormat(L"Failed to start %s.", path), launchGLE);
if((ERROR_ELEVATION_REQUIRED == launchGLE) && (false == gbInService))
Log(L"HINT: PAExec probably needs to be \"Run As Administrator\"", false);
}
if(ci.bPreped)
CleanUpInteractiveProcess(&ci);
if(settings.bDisableFileRedirection)
RevertFileRedirection();
if(NULL != pEnvironment)
DestroyEnvironmentBlock(pEnvironment);
pEnvironment = NULL;
if(bLoadedProfile)
UnloadUserProfile(settings.hUser, profile.hProfile);
if(!BAD_HANDLE(settings.hUser))
{
CloseHandle(settings.hUser);
settings.hUser = NULL;
}
return bLaunched ? true : false;
}
示例15: AffinityPriorityFix
/* Thread safe - doesn't care about the lock */
static int AffinityPriorityFix(DWORD EnableAffinityFix, DWORD EnablePriorityFix) {
HWND hFShwnd;
DWORD nPriority;
DWORD nProcAffinity;
DWORD nSysAffinity;
DWORD nProcId;
HANDLE hFS;
if(EnableAffinityFix || EnablePriorityFix) {
/* Start by finding the window */
switch(FSUIPC_FS_Version) {
case SIM_FSX:
hFShwnd = FindWindow(NULL,"Microsoft Flight Simulator X");
break;
case SIM_FS2K4:
hFShwnd = FindWindow(NULL,"Microsoft Flight Simulator 2004 - A Century of Flight");
break;
case SIM_FS2K2:
hFShwnd = FindWindow(NULL,"Microsoft Flight Simulator 2002");
break;
case SIM_FS2K:
hFShwnd = FindWindow(NULL,"Microsoft Flight Simulator 2000");
break;
case SIM_FS98:
hFShwnd = FindWindow(NULL,"Microsoft Flight Simulator 98");
break;
default:
/* Couldn't find the window name, giving up on affinity or priority fix */
debuglog(DEBUG_WARNING,"Unknown FS, don't know what window to search\n");
return 0;
}
if(hFShwnd == NULL) {
debuglog(DEBUG_WARNING,"Failed finding the window for the connected FS\n");
return 0;
}
GetWindowThreadProcessId(hFShwnd,&nProcId);
if(!nProcId) {
debuglog(DEBUG_WARNING,"Failed getting FS process ID\n");
return 0;
}
hFS = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_SET_INFORMATION,FALSE,nProcId);
if(hFS == NULL) {
debuglog(DEBUG_WARNING,"Failed opening FS process!\n");
return 0;
}
/* Get FS priority class and copy it to our process */
if(EnablePriorityFix) {
if(!(nPriority = GetPriorityClass(hFS))) {
debuglog(DEBUG_WARNING,"Failed getting FS priority class!\n");
} else {
if(!SetPriorityClass(GetCurrentProcess(),nPriority))
debuglog(DEBUG_WARNING,"Failed setting priority class!\n");
}
}
/* Get FS affinity mask and copy it to our process */
if(EnableAffinityFix) {
if(!GetProcessAffinityMask(hFS,&nProcAffinity,&nSysAffinity)) {
debuglog(DEBUG_WARNING,"Failed getting FS affinity mask!\n");
} else {
if(!SetProcessAffinityMask(GetCurrentProcess(),nProcAffinity))
debuglog(DEBUG_WARNING,"Failed setting affinity mask!\n");
}
}
/* Finished with the FS process, let's close it */
CloseHandle(hFS);
}
return 1;
}