diff --git a/src_main/console/piscreendrawer.cpp b/src_main/console/piscreendrawer.cpp index 4440353c..30a61dc9 100644 --- a/src_main/console/piscreendrawer.cpp +++ b/src_main/console/piscreendrawer.cpp @@ -72,6 +72,20 @@ PIScreenDrawer::PIScreenDrawer(PIVector > & 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 } diff --git a/src_main/console/piscreendrawer.h b/src_main/console/piscreendrawer.h index d8ec1a1b..054eb7b4 100644 --- a/src_main/console/piscreendrawer.h +++ b/src_main/console/piscreendrawer.h @@ -31,7 +31,17 @@ class PIP_EXPORT PIScreenDrawer friend class PIScreen; PIScreenDrawer(PIVector > & 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, ' ');} diff --git a/src_main/core/piincludes.cpp b/src_main/core/piincludes.cpp index 447a8283..c17e3d10 100755 --- a/src_main/core/piincludes.cpp +++ b/src_main/core/piincludes.cpp @@ -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 diff --git a/src_main/core/piincludes_p.h b/src_main/core/piincludes_p.h index 85a7dfc5..867d936b 100644 --- a/src_main/core/piincludes_p.h +++ b/src_main/core/piincludes_p.h @@ -25,6 +25,7 @@ # include # include # include +typedef void(*PINtQueryTimerResolution)(PULONG, PULONG, PULONG); typedef void(*PINtSetTimerResolution)(ULONG, BOOLEAN, PULONG); #endif #ifdef CC_GCC diff --git a/src_main/core/piinit.cpp b/src_main/core/piinit.cpp index aeb646e6..c0e01e51 100644 --- a/src_main/core/piinit.cpp +++ b/src_main/core/piinit.cpp @@ -28,7 +28,17 @@ #ifdef WINDOWS # include 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 # include @@ -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; diff --git a/src_main/core/pitime.cpp b/src_main/core/pitime.cpp index 1044945c..f58f2839 100755 --- a/src_main/core/pitime.cpp +++ b/src_main/core/pitime.cpp @@ -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; diff --git a/src_main/thread/pithread.cpp b/src_main/thread/pithread.cpp index 2d243915..744ab154 100755 --- a/src_main/thread/pithread.cpp +++ b/src_main/thread/pithread.cpp @@ -23,12 +23,16 @@ #include "piintrospection_proxy.h" #include #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 #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 +} diff --git a/src_main/thread/pithread.h b/src_main/thread/pithread.h index ee24f1f6..031a97a5 100755 --- a/src_main/thread/pithread.h +++ b/src_main/thread/pithread.h @@ -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() {;}