20.10.2013 - Modified PIObject - virtual debugName() for macro piCoutObj, improved timer measurements and timers on Windows
This commit is contained in:
@@ -26,6 +26,9 @@ string ifconfigPath;
|
||||
|
||||
PIInit piInit;
|
||||
lconv * currentLocale = std::localeconv();
|
||||
#ifdef HAS_LOCALE
|
||||
static locale_t currentLocale_t = 0;
|
||||
#endif
|
||||
|
||||
#ifdef MAC_OS
|
||||
clock_serv_t __pi_mac_clock;
|
||||
@@ -51,6 +54,83 @@ PIMutex __PICout_mutex__;
|
||||
* \section PICout_ex0 Example
|
||||
* \snippet picout.cpp 0
|
||||
*/
|
||||
|
||||
|
||||
#ifdef WINDOWS
|
||||
FILETIME __pi_ftjan1970;
|
||||
long long __pi_perf_freq = -1;
|
||||
PINtSetTimerResolution setTimerResolutionAddr = 0;
|
||||
#endif
|
||||
|
||||
|
||||
PIInit::PIInit() {
|
||||
if (isPIInit) return;
|
||||
isPIInit = true;
|
||||
#ifndef WINDOWS
|
||||
sigset_t ss;
|
||||
sigemptyset(&ss);
|
||||
sigaddset(&ss, SIGALRM);
|
||||
sigprocmask(SIG_BLOCK, &ss, 0);
|
||||
pthread_sigmask(SIG_BLOCK, &ss, 0);
|
||||
ifconfigPath = "/bin/ifconfig";
|
||||
if (!fileExists(ifconfigPath)) {
|
||||
ifconfigPath = "/sbin/ifconfig";
|
||||
if (!fileExists(ifconfigPath)) {
|
||||
ifconfigPath = "/usr/bin/ifconfig";
|
||||
if (!fileExists(ifconfigPath)) {
|
||||
ifconfigPath = "/usr/sbin/ifconfig";
|
||||
if (!fileExists(ifconfigPath)) {
|
||||
ifconfigPath = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
// WinSock inint
|
||||
WSADATA wsaData;
|
||||
WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||
|
||||
// Timers init
|
||||
SYSTEMTIME jan1970 = {1970, 1, 4, 1, 0, 0, 0, 0};
|
||||
SystemTimeToFileTime(&jan1970, &__pi_ftjan1970);
|
||||
LARGE_INTEGER pf;
|
||||
pf.QuadPart = -1;
|
||||
if (QueryPerformanceFrequency(&pf) != 0) __pi_perf_freq = pf.QuadPart;
|
||||
if (__pi_perf_freq == 0) __pi_perf_freq = -1;
|
||||
|
||||
// Sleep precision init
|
||||
ntlib = LoadLibrary("ntdll.dll");
|
||||
if (ntlib) setTimerResolutionAddr = (PINtSetTimerResolution)GetProcAddress(ntlib, "NtSetTimerResolution");
|
||||
/*if (setTimerResolution) setTimerResolutionAddr(1, TRUE, &prev_res);*/
|
||||
#endif
|
||||
//piDebug = true;
|
||||
#ifdef HAS_LOCALE
|
||||
//cout << "has locale" << endl;
|
||||
if (currentLocale_t != 0) {
|
||||
freelocale(currentLocale_t);
|
||||
currentLocale_t = 0;
|
||||
}
|
||||
currentLocale_t = newlocale(LC_ALL, setlocale(LC_ALL, ""), 0);
|
||||
#else
|
||||
setlocale(LC_ALL, "");
|
||||
#endif
|
||||
#ifdef MAC_OS
|
||||
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &__pi_mac_clock);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
PIInit::~PIInit() {
|
||||
#ifdef WINDOWS
|
||||
WSACleanup();
|
||||
//if (setTimerResolution) setTimerResolutionAddr(prev_res, TRUE, &prev_res);
|
||||
if (ntlib) FreeLibrary(ntlib);
|
||||
#endif
|
||||
#ifdef MAC_OS
|
||||
mach_port_deallocate(mach_task_self(), __pi_mac_clock);
|
||||
#endif
|
||||
//if (currentLocale_t != 0) freelocale(currentLocale_t);
|
||||
}
|
||||
|
||||
|
||||
#ifdef WINDOWS
|
||||
@@ -243,5 +323,8 @@ void PICout::applyFormat(PICoutFormat f) {
|
||||
* * peering net node (\a PIPeer)
|
||||
* * process (\a PIProcess)
|
||||
* * state machine (\a PIStateMachine)
|
||||
* \n Basic using of PIP described at page \ref using_basic
|
||||
*
|
||||
*/
|
||||
* \page using_basic Getting started
|
||||
* blablabla
|
||||
*/
|
||||
Reference in New Issue
Block a user