git-svn-id: svn://db.shs.com.ru/pip@492 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -72,6 +72,20 @@ PIScreenDrawer::PIScreenDrawer(PIVector<PIVector<Cell> > & c): cells(c) {
|
|||||||
#else
|
#else
|
||||||
PIChar('+');
|
PIChar('+');
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
arts_[Unchecked] =
|
||||||
|
#ifdef PIP_ICU
|
||||||
|
PIChar::fromUTF8("☐");
|
||||||
|
#else
|
||||||
|
PIChar('O');
|
||||||
|
#endif
|
||||||
|
|
||||||
|
arts_[Checked] =
|
||||||
|
#ifdef PIP_ICU
|
||||||
|
PIChar::fromUTF8("☑");
|
||||||
|
#else
|
||||||
|
PIChar('0');
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,17 @@ class PIP_EXPORT PIScreenDrawer
|
|||||||
friend class PIScreen;
|
friend class PIScreen;
|
||||||
PIScreenDrawer(PIVector<PIVector<PIScreenTypes::Cell> > & c);
|
PIScreenDrawer(PIVector<PIVector<PIScreenTypes::Cell> > & c);
|
||||||
public:
|
public:
|
||||||
enum ArtChar {LineVertical = 1, LineHorizontal, Cross, CornerTopLeft, CornerTopRight, CornerBottomLeft, CornerBottomRight};
|
enum ArtChar {
|
||||||
|
LineVertical = 1,
|
||||||
|
LineHorizontal,
|
||||||
|
Cross,
|
||||||
|
CornerTopLeft,
|
||||||
|
CornerTopRight,
|
||||||
|
CornerBottomLeft,
|
||||||
|
CornerBottomRight,
|
||||||
|
Unchecked,
|
||||||
|
Checked
|
||||||
|
};
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
void clearRect(int x0, int y0, int x1, int y1) {fillRect(x0, y0, x1, y1, ' ');}
|
void clearRect(int x0, int y0, int x1, int y1) {fillRect(x0, y0, x1, y1, ' ');}
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ clock_serv_t __pi_mac_clock;
|
|||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
FILETIME __pi_ftjan1970;
|
FILETIME __pi_ftjan1970;
|
||||||
long long __pi_perf_freq = -1;
|
long long __pi_perf_freq = -1;
|
||||||
|
PINtQueryTimerResolution getTimerResolutionAddr = 0;
|
||||||
PINtSetTimerResolution setTimerResolutionAddr = 0;
|
PINtSetTimerResolution setTimerResolutionAddr = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
# include <stdarg.h>
|
# include <stdarg.h>
|
||||||
# include <windef.h>
|
# include <windef.h>
|
||||||
# include <winbase.h>
|
# include <winbase.h>
|
||||||
|
typedef void(*PINtQueryTimerResolution)(PULONG, PULONG, PULONG);
|
||||||
typedef void(*PINtSetTimerResolution)(ULONG, BOOLEAN, PULONG);
|
typedef void(*PINtSetTimerResolution)(ULONG, BOOLEAN, PULONG);
|
||||||
#endif
|
#endif
|
||||||
#ifdef CC_GCC
|
#ifdef CC_GCC
|
||||||
|
|||||||
@@ -28,7 +28,17 @@
|
|||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
extern FILETIME __pi_ftjan1970;
|
extern FILETIME __pi_ftjan1970;
|
||||||
|
extern PINtQueryTimerResolution getTimerResolutionAddr;
|
||||||
extern PINtSetTimerResolution setTimerResolutionAddr;
|
extern PINtSetTimerResolution setTimerResolutionAddr;
|
||||||
|
void __PISetTimerResolution() {
|
||||||
|
if (setTimerResolutionAddr == NULL || getTimerResolutionAddr == NULL)
|
||||||
|
return;
|
||||||
|
ULONG max(0), min(0), cur(0);
|
||||||
|
getTimerResolutionAddr(&max, &min, &cur);
|
||||||
|
//printf("getTimerResolution %lu %lu %lu\n", min, max, cur);
|
||||||
|
setTimerResolutionAddr(min, TRUE, &cur);
|
||||||
|
//printf("setTimerResolution %lu\n", cur);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
# include <pwd.h>
|
# include <pwd.h>
|
||||||
# include <sys/utsname.h>
|
# include <sys/utsname.h>
|
||||||
@@ -135,7 +145,11 @@ PIInit::PIInit() {
|
|||||||
|
|
||||||
// Sleep precision init
|
// Sleep precision init
|
||||||
PRIVATE->ntlib = LoadLibrary("ntdll.dll");
|
PRIVATE->ntlib = LoadLibrary("ntdll.dll");
|
||||||
if (PRIVATE->ntlib) setTimerResolutionAddr = (PINtSetTimerResolution)GetProcAddress(PRIVATE->ntlib, "NtSetTimerResolution");
|
if (PRIVATE->ntlib) {
|
||||||
|
getTimerResolutionAddr = (PINtQueryTimerResolution)GetProcAddress(PRIVATE->ntlib, "NtQueryTimerResolution");
|
||||||
|
setTimerResolutionAddr = (PINtSetTimerResolution)GetProcAddress(PRIVATE->ntlib, "NtSetTimerResolution");
|
||||||
|
}
|
||||||
|
__PISetTimerResolution();
|
||||||
/*if (setTimerResolution) setTimerResolutionAddr(1, TRUE, &(PRIVATE->prev_res));*/
|
/*if (setTimerResolution) setTimerResolutionAddr(1, TRUE, &(PRIVATE->prev_res));*/
|
||||||
# endif
|
# endif
|
||||||
//piDebug = true;
|
//piDebug = true;
|
||||||
|
|||||||
@@ -60,6 +60,7 @@
|
|||||||
void piUSleep(int usecs) {
|
void piUSleep(int usecs) {
|
||||||
if (usecs <= 0) return;
|
if (usecs <= 0) return;
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
|
//printf("Sleep %d\n", usecs / 1000);
|
||||||
if (usecs > 0) Sleep(usecs / 1000);
|
if (usecs > 0) Sleep(usecs / 1000);
|
||||||
#else
|
#else
|
||||||
usecs -= PISystemTests::usleep_offset_us;
|
usecs -= PISystemTests::usleep_offset_us;
|
||||||
|
|||||||
@@ -23,12 +23,16 @@
|
|||||||
#include "piintrospection_proxy.h"
|
#include "piintrospection_proxy.h"
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
extern PINtSetTimerResolution setTimerResolutionAddr;
|
# define __THREAD_FUNC_RET__ uint __stdcall
|
||||||
void __PISetTimerResolution() {if (setTimerResolutionAddr == NULL) return; ULONG ret; setTimerResolutionAddr(1, TRUE, &ret);}
|
#else
|
||||||
|
# define __THREAD_FUNC_RET__ void*
|
||||||
#endif
|
#endif
|
||||||
#if defined(MAC_OS) || defined(BLACKBERRY)
|
#if defined(MAC_OS) || defined(BLACKBERRY)
|
||||||
# include <pthread.h>
|
# include <pthread.h>
|
||||||
#endif
|
#endif
|
||||||
|
__THREAD_FUNC_RET__ thread_function(void * t) {PIThread::__thread_func__(t); return 0;}
|
||||||
|
__THREAD_FUNC_RET__ thread_function_once(void * t) {PIThread::__thread_func_once__(t); return 0;}
|
||||||
|
|
||||||
|
|
||||||
/*! \class PIThread
|
/*! \class PIThread
|
||||||
* \brief Thread class
|
* \brief Thread class
|
||||||
@@ -229,111 +233,6 @@ void PIThread::terminate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
__THREAD_FUNC__ PIThread::thread_function(void * t) {
|
|
||||||
#ifndef WINDOWS
|
|
||||||
# ifndef ANDROID
|
|
||||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0);
|
|
||||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
|
|
||||||
# endif
|
|
||||||
#else
|
|
||||||
__PISetTimerResolution();
|
|
||||||
#endif
|
|
||||||
PIThread & ct = *((PIThread * )t);
|
|
||||||
#ifdef WINDOWS
|
|
||||||
ct.tid_ = GetCurrentThreadId();
|
|
||||||
#endif
|
|
||||||
PIINTROSPECTION_REGISTER_THREAD(ct.tid(), ct.priority(), ct.name());
|
|
||||||
ct.running_ = true;
|
|
||||||
if (ct.lockRun) ct.mutex_.lock();
|
|
||||||
ct.begin();
|
|
||||||
if (ct.lockRun) ct.mutex_.unlock();
|
|
||||||
ct.started();
|
|
||||||
while (!ct.terminating) {
|
|
||||||
ct.maybeCallQueuedEvents();
|
|
||||||
if (ct.lockRun) ct.mutex_.lock();
|
|
||||||
//piCout << "thread" << ct.name() << "...";
|
|
||||||
ct.run();
|
|
||||||
//piCout << "thread" << ct.name() << "done";
|
|
||||||
//printf("thread %p tick\n", &ct);
|
|
||||||
if (ct.ret_func != 0) ct.ret_func(ct.data_);
|
|
||||||
if (ct.lockRun) ct.mutex_.unlock();
|
|
||||||
if (ct.delay_ > 0) {
|
|
||||||
ct.tmr_.reset();
|
|
||||||
double sl(0.);
|
|
||||||
while (1) {
|
|
||||||
sl = piMind(ct.delay_ - ct.tmr_.elapsed_m(), 2.);
|
|
||||||
if (sl <= 0.) break;
|
|
||||||
piMSleep(sl);
|
|
||||||
if (ct.terminating)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ct.stopped();
|
|
||||||
if (ct.lockRun) ct.mutex_.lock();
|
|
||||||
ct.end();
|
|
||||||
if (ct.lockRun) ct.mutex_.unlock();
|
|
||||||
ct.terminating = ct.running_ = false;
|
|
||||||
ct.tid_ = -1;
|
|
||||||
//cout << "thread " << t << " exiting ... " << endl;
|
|
||||||
//piCout << "pthread_exit" << (ct.__privateinitializer__.p)->thread;
|
|
||||||
PIINTROSPECTION_UNREGISTER_THREAD(ct.tid());
|
|
||||||
#ifndef WINDOWS
|
|
||||||
pthread_detach((ct.__privateinitializer__.p)->thread);
|
|
||||||
(ct.__privateinitializer__.p)->thread = 0;
|
|
||||||
#endif
|
|
||||||
#ifndef WINDOWS
|
|
||||||
pthread_exit(0);
|
|
||||||
#else
|
|
||||||
_endthreadex(0);
|
|
||||||
//ExitThread(0);
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
__THREAD_FUNC__ PIThread::thread_function_once(void * t) {
|
|
||||||
#ifndef WINDOWS
|
|
||||||
# ifndef ANDROID
|
|
||||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0);
|
|
||||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
|
|
||||||
# endif
|
|
||||||
#else
|
|
||||||
__PISetTimerResolution();
|
|
||||||
#endif
|
|
||||||
PIThread & ct = *((PIThread * )t);
|
|
||||||
#ifdef WINDOWS
|
|
||||||
ct.tid_ = GetCurrentThreadId();
|
|
||||||
#endif
|
|
||||||
PIINTROSPECTION_REGISTER_THREAD(ct.tid(), ct.priority(), ct.name());
|
|
||||||
ct.running_ = true;
|
|
||||||
ct.begin();
|
|
||||||
ct.started();
|
|
||||||
if (ct.lockRun) ct.mutex_.lock();
|
|
||||||
ct.run();
|
|
||||||
if (ct.ret_func != 0) ct.ret_func(ct.data_);
|
|
||||||
if (ct.lockRun) ct.mutex_.unlock();
|
|
||||||
ct.stopped();
|
|
||||||
ct.end();
|
|
||||||
ct.terminating = ct.running_ = false;
|
|
||||||
ct.tid_ = -1;
|
|
||||||
//cout << "thread " << t << " exiting ... " << endl;
|
|
||||||
//piCout << "pthread_exit" << (ct.__privateinitializer__.p)->thread;
|
|
||||||
PIINTROSPECTION_UNREGISTER_THREAD(ct.tid());
|
|
||||||
#ifndef WINDOWS
|
|
||||||
pthread_detach((ct.__privateinitializer__.p)->thread);
|
|
||||||
(ct.__privateinitializer__.p)->thread = 0;
|
|
||||||
#endif
|
|
||||||
#ifndef WINDOWS
|
|
||||||
pthread_exit(0);
|
|
||||||
#else
|
|
||||||
_endthreadex(0);
|
|
||||||
//ExitThread(0);
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int PIThread::priority2System(PIThread::Priority p) {
|
int PIThread::priority2System(PIThread::Priority p) {
|
||||||
switch (p) {
|
switch (p) {
|
||||||
# ifdef QNX
|
# ifdef QNX
|
||||||
@@ -412,3 +311,113 @@ bool PIThread::waitForStart(int timeout_msecs) {
|
|||||||
msleep(1);
|
msleep(1);
|
||||||
return tms_.elapsed_m() < timeout_msecs;
|
return tms_.elapsed_m() < timeout_msecs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PIThread::__thread_func__(void * t) {
|
||||||
|
#ifndef WINDOWS
|
||||||
|
# ifndef ANDROID
|
||||||
|
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0);
|
||||||
|
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
//__PISetTimerResolution();
|
||||||
|
#endif
|
||||||
|
PIThread & ct = *((PIThread * )t);
|
||||||
|
#ifdef WINDOWS
|
||||||
|
ct.tid_ = GetCurrentThreadId();
|
||||||
|
#endif
|
||||||
|
PIINTROSPECTION_REGISTER_THREAD(ct.tid(), ct.priority(), ct.name());
|
||||||
|
ct.running_ = true;
|
||||||
|
if (ct.lockRun) ct.mutex_.lock();
|
||||||
|
ct.begin();
|
||||||
|
if (ct.lockRun) ct.mutex_.unlock();
|
||||||
|
ct.started();
|
||||||
|
while (!ct.terminating) {
|
||||||
|
ct.maybeCallQueuedEvents();
|
||||||
|
if (ct.lockRun) ct.mutex_.lock();
|
||||||
|
//piCout << "thread" << ct.name() << "...";
|
||||||
|
ct.run();
|
||||||
|
//piCout << "thread" << ct.name() << "done";
|
||||||
|
//printf("thread %p tick\n", &ct);
|
||||||
|
if (ct.ret_func != 0) ct.ret_func(ct.data_);
|
||||||
|
if (ct.lockRun) ct.mutex_.unlock();
|
||||||
|
if (ct.delay_ > 0) {
|
||||||
|
ct.tmr_.reset();
|
||||||
|
double sl(0.);
|
||||||
|
while (1) {
|
||||||
|
sl = piMind(ct.delay_ - ct.tmr_.elapsed_m(), 2.);
|
||||||
|
#ifdef WINDOWS
|
||||||
|
/*if (sl <= 1. && sl >= 0.) {
|
||||||
|
piMSleep(1.);
|
||||||
|
continue;
|
||||||
|
}*/
|
||||||
|
#endif
|
||||||
|
//printf("%f %f %f\n", double(ct.delay_), ct.tmr_.elapsed_m(), sl);
|
||||||
|
if (sl <= 0.) break;
|
||||||
|
piMSleep(sl);
|
||||||
|
if (ct.terminating)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ct.stopped();
|
||||||
|
if (ct.lockRun) ct.mutex_.lock();
|
||||||
|
ct.end();
|
||||||
|
if (ct.lockRun) ct.mutex_.unlock();
|
||||||
|
ct.terminating = ct.running_ = false;
|
||||||
|
ct.tid_ = -1;
|
||||||
|
//cout << "thread " << t << " exiting ... " << endl;
|
||||||
|
//piCout << "pthread_exit" << (ct.__privateinitializer__.p)->thread;
|
||||||
|
PIINTROSPECTION_UNREGISTER_THREAD(ct.tid());
|
||||||
|
#ifndef WINDOWS
|
||||||
|
pthread_detach((ct.__privateinitializer__.p)->thread);
|
||||||
|
(ct.__privateinitializer__.p)->thread = 0;
|
||||||
|
#endif
|
||||||
|
#ifndef WINDOWS
|
||||||
|
pthread_exit(0);
|
||||||
|
#else
|
||||||
|
_endthreadex(0);
|
||||||
|
//ExitThread(0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PIThread::__thread_func_once__(void * t) {
|
||||||
|
#ifndef WINDOWS
|
||||||
|
# ifndef ANDROID
|
||||||
|
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0);
|
||||||
|
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
//__PISetTimerResolution();
|
||||||
|
#endif
|
||||||
|
PIThread & ct = *((PIThread * )t);
|
||||||
|
#ifdef WINDOWS
|
||||||
|
ct.tid_ = GetCurrentThreadId();
|
||||||
|
#endif
|
||||||
|
PIINTROSPECTION_REGISTER_THREAD(ct.tid(), ct.priority(), ct.name());
|
||||||
|
ct.running_ = true;
|
||||||
|
ct.begin();
|
||||||
|
ct.started();
|
||||||
|
if (ct.lockRun) ct.mutex_.lock();
|
||||||
|
ct.run();
|
||||||
|
if (ct.ret_func != 0) ct.ret_func(ct.data_);
|
||||||
|
if (ct.lockRun) ct.mutex_.unlock();
|
||||||
|
ct.stopped();
|
||||||
|
ct.end();
|
||||||
|
ct.terminating = ct.running_ = false;
|
||||||
|
ct.tid_ = -1;
|
||||||
|
//cout << "thread " << t << " exiting ... " << endl;
|
||||||
|
//piCout << "pthread_exit" << (ct.__privateinitializer__.p)->thread;
|
||||||
|
PIINTROSPECTION_UNREGISTER_THREAD(ct.tid());
|
||||||
|
#ifndef WINDOWS
|
||||||
|
pthread_detach((ct.__privateinitializer__.p)->thread);
|
||||||
|
(ct.__privateinitializer__.p)->thread = 0;
|
||||||
|
#endif
|
||||||
|
#ifndef WINDOWS
|
||||||
|
pthread_exit(0);
|
||||||
|
#else
|
||||||
|
_endthreadex(0);
|
||||||
|
//ExitThread(0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|||||||
@@ -28,11 +28,6 @@
|
|||||||
#include "piinit.h"
|
#include "piinit.h"
|
||||||
#include "pimutex.h"
|
#include "pimutex.h"
|
||||||
#include "piobject.h"
|
#include "piobject.h"
|
||||||
#ifdef WINDOWS
|
|
||||||
# define __THREAD_FUNC__ uint __stdcall
|
|
||||||
#else
|
|
||||||
# define __THREAD_FUNC__ void*
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef void (*ThreadFunc)(void * );
|
typedef void (*ThreadFunc)(void * );
|
||||||
|
|
||||||
@@ -104,6 +99,9 @@ public:
|
|||||||
//! \brief Returns thread ID
|
//! \brief Returns thread ID
|
||||||
llong tid() const {return tid_;}
|
llong tid() const {return tid_;}
|
||||||
|
|
||||||
|
static void __thread_func__(void*);
|
||||||
|
static void __thread_func_once__(void*);
|
||||||
|
|
||||||
EVENT(started)
|
EVENT(started)
|
||||||
EVENT(stopped)
|
EVENT(stopped)
|
||||||
|
|
||||||
@@ -176,11 +174,8 @@ public:
|
|||||||
//! \}
|
//! \}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static __THREAD_FUNC__ thread_function(void * t);
|
|
||||||
static __THREAD_FUNC__ thread_function_once(void * t);
|
|
||||||
static int priority2System(PIThread::Priority p);
|
static int priority2System(PIThread::Priority p);
|
||||||
|
|
||||||
|
|
||||||
//! Function executed once at the start of thread.
|
//! Function executed once at the start of thread.
|
||||||
virtual void begin() {;}
|
virtual void begin() {;}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user