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
|
||||
PIChar('+');
|
||||
#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;
|
||||
PIScreenDrawer(PIVector<PIVector<PIScreenTypes::Cell> > & c);
|
||||
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 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
|
||||
FILETIME __pi_ftjan1970;
|
||||
long long __pi_perf_freq = -1;
|
||||
PINtQueryTimerResolution getTimerResolutionAddr = 0;
|
||||
PINtSetTimerResolution setTimerResolutionAddr = 0;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
# include <stdarg.h>
|
||||
# include <windef.h>
|
||||
# include <winbase.h>
|
||||
typedef void(*PINtQueryTimerResolution)(PULONG, PULONG, PULONG);
|
||||
typedef void(*PINtSetTimerResolution)(ULONG, BOOLEAN, PULONG);
|
||||
#endif
|
||||
#ifdef CC_GCC
|
||||
|
||||
@@ -28,7 +28,17 @@
|
||||
#ifdef WINDOWS
|
||||
# include <winsock2.h>
|
||||
extern FILETIME __pi_ftjan1970;
|
||||
extern PINtQueryTimerResolution getTimerResolutionAddr;
|
||||
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
|
||||
# include <pwd.h>
|
||||
# include <sys/utsname.h>
|
||||
@@ -135,7 +145,11 @@ PIInit::PIInit() {
|
||||
|
||||
// Sleep precision init
|
||||
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));*/
|
||||
# endif
|
||||
//piDebug = true;
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
void piUSleep(int usecs) {
|
||||
if (usecs <= 0) return;
|
||||
#ifdef WINDOWS
|
||||
//printf("Sleep %d\n", usecs / 1000);
|
||||
if (usecs > 0) Sleep(usecs / 1000);
|
||||
#else
|
||||
usecs -= PISystemTests::usleep_offset_us;
|
||||
|
||||
@@ -23,12 +23,16 @@
|
||||
#include "piintrospection_proxy.h"
|
||||
#include <signal.h>
|
||||
#ifdef WINDOWS
|
||||
extern PINtSetTimerResolution setTimerResolutionAddr;
|
||||
void __PISetTimerResolution() {if (setTimerResolutionAddr == NULL) return; ULONG ret; setTimerResolutionAddr(1, TRUE, &ret);}
|
||||
# define __THREAD_FUNC_RET__ uint __stdcall
|
||||
#else
|
||||
# define __THREAD_FUNC_RET__ void*
|
||||
#endif
|
||||
#if defined(MAC_OS) || defined(BLACKBERRY)
|
||||
# include <pthread.h>
|
||||
#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
|
||||
* \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) {
|
||||
switch (p) {
|
||||
# ifdef QNX
|
||||
@@ -412,3 +311,113 @@ bool PIThread::waitForStart(int timeout_msecs) {
|
||||
msleep(1);
|
||||
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 "pimutex.h"
|
||||
#include "piobject.h"
|
||||
#ifdef WINDOWS
|
||||
# define __THREAD_FUNC__ uint __stdcall
|
||||
#else
|
||||
# define __THREAD_FUNC__ void*
|
||||
#endif
|
||||
|
||||
typedef void (*ThreadFunc)(void * );
|
||||
|
||||
@@ -104,6 +99,9 @@ public:
|
||||
//! \brief Returns thread ID
|
||||
llong tid() const {return tid_;}
|
||||
|
||||
static void __thread_func__(void*);
|
||||
static void __thread_func_once__(void*);
|
||||
|
||||
EVENT(started)
|
||||
EVENT(stopped)
|
||||
|
||||
@@ -176,10 +174,7 @@ public:
|
||||
//! \}
|
||||
|
||||
protected:
|
||||
static __THREAD_FUNC__ thread_function(void * t);
|
||||
static __THREAD_FUNC__ thread_function_once(void * t);
|
||||
static int priority2System(PIThread::Priority p);
|
||||
|
||||
|
||||
//! Function executed once at the start of thread.
|
||||
virtual void begin() {;}
|
||||
|
||||
Reference in New Issue
Block a user