From a76aa71d8c58eb6e447d017378eddc46ba1e28d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Mon, 20 Apr 2015 11:37:50 +0000 Subject: [PATCH] PIPeer important fix! git-svn-id: svn://db.shs.com.ru/pip@115 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- src/thread/pithread.cpp | 15 ++++++++------- src/thread/pithread.h | 9 +++++++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/thread/pithread.cpp b/src/thread/pithread.cpp index b8b3b644..ecd87e75 100755 --- a/src/thread/pithread.cpp +++ b/src/thread/pithread.cpp @@ -129,6 +129,7 @@ bool PIThread::start(int timer_delay) { pthread_attr_destroy(&attr); if (ret == 0) { #else + if (thread != 0) CloseHandle(thread); thread = (void *)_beginthreadex(0, 0, thread_function, this, 0, 0); // thread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)thread_function, this, 0, 0); if (thread != 0) { @@ -157,7 +158,7 @@ bool PIThread::startOnce() { pthread_attr_destroy(&attr); if (ret == 0) { #else - uint _id = 0; + if (thread != 0) CloseHandle(thread); thread = (void *)_beginthreadex(0, 0, thread_function_once, this, 0, 0); // thread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)thread_function_once, this, 0, 0); if (thread != 0) { @@ -194,7 +195,7 @@ void PIThread::terminate() { } -uint __stdcall PIThread::thread_function(void * t) { +__THREAD_FUNC__ PIThread::thread_function(void * t) { #ifndef WINDOWS # ifndef ANDROID pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0); @@ -235,19 +236,19 @@ uint __stdcall PIThread::thread_function(void * t) { //cout << "thread " << t << " exiting ... " << endl; #ifndef WINDOWS pthread_detach(ct.thread); -#endif ct.thread = 0; +#endif #ifndef WINDOWS pthread_exit(0); #else _endthreadex(0); -// ExitThread(0); + //ExitThread(0); #endif return 0; } -uint __stdcall PIThread::thread_function_once(void * t) { +__THREAD_FUNC__ PIThread::thread_function_once(void * t) { #ifndef WINDOWS # ifndef ANDROID pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0); @@ -270,13 +271,13 @@ uint __stdcall PIThread::thread_function_once(void * t) { //cout << "thread " << t << " exiting ... " << endl; #ifndef WINDOWS pthread_detach(ct.thread); -#endif ct.thread = 0; +#endif #ifndef WINDOWS pthread_exit(0); #else _endthreadex(0); -// ExitThread(0); + //ExitThread(0); #endif return 0; } diff --git a/src/thread/pithread.h b/src/thread/pithread.h index e649a4b8..8c8fd680 100755 --- a/src/thread/pithread.h +++ b/src/thread/pithread.h @@ -28,6 +28,11 @@ #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 * ); @@ -174,8 +179,8 @@ public: //! \} protected: - static uint __stdcall thread_function(void * t); - static uint __stdcall thread_function_once(void * t); + static __THREAD_FUNC__ thread_function(void * t); + static __THREAD_FUNC__ thread_function_once(void * t); static int priority2System(PIThread::Priority p);