Browse Source

Remove system::getThreadTime() and system::setThreadRealTime().

tags/v2.0.0
Andrew Belt 4 years ago
parent
commit
c7f65f7bfb
2 changed files with 0 additions and 73 deletions
  1. +0
    -4
      include/system.hpp
  2. +0
    -69
      src/system.cpp

+ 0
- 4
include/system.hpp View File

@@ -34,10 +34,6 @@ void removeDirectory(const std::string& path);
int getLogicalCoreCount(); int getLogicalCoreCount();
/** Sets a name of the current thread for debuggers and OS-specific process viewers. */ /** Sets a name of the current thread for debuggers and OS-specific process viewers. */
void setThreadName(const std::string& name); void setThreadName(const std::string& name);
/** Sets the current thread to be high-priority. */
void setThreadRealTime(bool realTime);
/** Returns the number of seconds the current thread has been active. */
double getThreadTime();
/** Returns the caller's human-readable stack trace with "\n"-separated lines. */ /** Returns the caller's human-readable stack trace with "\n"-separated lines. */
std::string getStackTrace(); std::string getStackTrace();
/** Opens a URL, also happens to work with PDFs and folders. /** Opens a URL, also happens to work with PDFs and folders.


+ 0
- 69
src/system.cpp View File

@@ -21,7 +21,6 @@
#endif #endif


#if defined ARCH_WIN #if defined ARCH_WIN
#define _WIN32_WINNT _WIN32_WINNT_VISTA // for QueryThreadCycleTime
#include <windows.h> #include <windows.h>
#include <shellapi.h> #include <shellapi.h>
#include <processthreadsapi.h> #include <processthreadsapi.h>
@@ -156,74 +155,6 @@ void setThreadName(const std::string& name) {
} }




void setThreadRealTime(bool realTime) {
#if defined ARCH_LIN
int err;
int policy;
struct sched_param param;
if (realTime) {
// Round-robin scheduler policy
policy = SCHED_RR;
param.sched_priority = sched_get_priority_max(policy);
}
else {
// Default scheduler policy
policy = 0;
param.sched_priority = 0;
}
err = pthread_setschedparam(pthread_self(), policy, &param);
assert(!err);

// pthread_getschedparam(pthread_self(), &policy, &param);
// DEBUG("policy %d priority %d", policy, param.sched_priority);
#elif defined ARCH_MAC
// Not yet implemented
#elif defined ARCH_WIN
// Set process class first
if (realTime) {
SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
}
else {
SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
}
#endif
}


double getThreadTime() {
#if defined ARCH_LIN
struct timespec ts;
clockid_t cid;
pthread_getcpuclockid(pthread_self(), &cid);
clock_gettime(cid, &ts);
return ts.tv_sec + ts.tv_nsec * 1e-9;
#elif defined ARCH_MAC
mach_port_t thread = mach_thread_self();
mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT;
thread_basic_info_data_t info;
kern_return_t kr = thread_info(thread, THREAD_BASIC_INFO, (thread_info_t) &info, &count);
if (kr != KERN_SUCCESS || (info.flags & TH_FLAGS_IDLE) != 0)
return 0.0;
return info.user_time.seconds + info.user_time.microseconds * 1e-6;
#elif defined ARCH_WIN
// FILETIME creationTime;
// FILETIME exitTime;
// FILETIME kernelTime;
// FILETIME userTime;
// GetThreadTimes(GetCurrentThread(), &creationTime, &exitTime, &kernelTime, &userTime);
// return ((uint64_t(userTime.dwHighDateTime) << 32) + userTime.dwLowDateTime) * 1e-7;

uint64_t cycles;
QueryThreadCycleTime(GetCurrentThread(), &cycles);
// HACK Assume that the RDTSC Time-Step Counter instruction is fixed at 2.5GHz. This should only be within a factor of 2 on all PCs.
const double freq = 2.5e9;
return (double) cycles / freq;
#endif
}


std::string getStackTrace() { std::string getStackTrace() {
int stackLen = 128; int stackLen = 128;
void* stack[stackLen]; void* stack[stackLen];


Loading…
Cancel
Save