11#include < XSYDMultiTask.h>
2+ unsigned int EasyCrossPlatform::Thread::getRecommendedThreadNum () {
3+ return std::thread::hardware_concurrency ();
4+ }
25
36int EasyCrossPlatform::Thread::SingleWork::DoingJob (EasyCrossPlatform::Thread::WorkInfo MyInfo)
47{
@@ -14,7 +17,6 @@ EasyCrossPlatform::Thread::SingleWork::SingleWork(){
1417EasyCrossPlatform::Thread::SingleWork::SingleWork (EasyCrossPlatform::Thread::SpecificWorkPtr mWork )
1518{
1619 this ->MyWork = mWork ;
17- this ->mThread = NULL ;
1820 this ->RunningSign = false ;
1921}
2022
@@ -23,7 +25,6 @@ EasyCrossPlatform::Thread::SingleWork::SingleWork(const SingleWork & mWork)
2325{
2426 this ->MyWork = mWork .MyWork ;
2527 this ->RunningSign = false ;
26- this ->mThread = NULL ;
2728}
2829
2930void EasyCrossPlatform::Thread::SingleWork::setWork (EasyCrossPlatform::Thread::SpecificWorkPtr mWork )
@@ -34,33 +35,20 @@ void EasyCrossPlatform::Thread::SingleWork::setWork(EasyCrossPlatform::Thread::S
3435bool EasyCrossPlatform::Thread::SingleWork::StartJob (std::mutex *MyMutex, void * Parameter)
3536{
3637 if (this ->RunningSign ) { return false ; }
37- if (this ->mThread != NULL ) {
38- if (this ->mThread ->joinable ()) {
39- this ->mThread ->join ();
40- }
41- delete this ->mThread ;
42- this ->mThread = NULL ;
43- }
4438 WorkInfo MyInfo;
4539 MyInfo.mMutex = MyMutex;
4640 MyInfo.MyWork = this ->MyWork ;
4741 MyInfo.Parameters = Parameter;
4842 MyInfo.RunningSign = &(this ->RunningSign );
4943 this ->RunningSign = true ;
50- this ->mThread = new std::thread (EasyCrossPlatform::Thread::SingleWork::DoingJob, MyInfo);
44+ this ->mThread = std::thread (EasyCrossPlatform::Thread::SingleWork::DoingJob, MyInfo);
45+ this ->mThread .detach ();
5146 return true ;
5247}
5348
5449void EasyCrossPlatform::Thread::SingleWork::StopJob ()
5550{
5651 this ->RunningSign = false ;
57- if (this ->mThread != NULL ) {
58- if (this ->mThread ->joinable ()) {
59- this ->mThread ->join ();
60- }
61- delete this ->mThread ;
62- this ->mThread = NULL ;
63- }
6452 return ;
6553}
6654
@@ -71,14 +59,7 @@ bool EasyCrossPlatform::Thread::SingleWork::getRunningStatus()
7159
7260EasyCrossPlatform::Thread::SingleWork::~SingleWork ()
7361{
74- this ->RunningSign = false ;
75- if (this ->mThread != NULL ) {
76- if (this ->mThread ->joinable ()) {
77- this ->mThread ->join ();
78- }
79- delete this ->mThread ;
80- this ->mThread = NULL ;
81- }
62+ if (this ->RunningSign ) { this ->StopJob (); }
8263}
8364
8465void EasyCrossPlatform::Thread::WorkPool::SuperviseThreads (std::thread::id ThreadID, void * Parameters, bool * RunningSign, std::mutex * Mutex)
@@ -257,7 +238,6 @@ EasyCrossPlatform::Thread::SingleWorkCls::SingleWorkCls()
257238
258239EasyCrossPlatform::Thread::SingleWorkCls::SingleWorkCls (SingleWorkCls & CopyWorkCls)
259240{
260- this ->mThread = NULL ;
261241 this ->RunningSign = false ;
262242}
263243
@@ -269,24 +249,17 @@ bool EasyCrossPlatform::Thread::SingleWorkCls::StartJob(std::mutex* MyMutex, voi
269249 this ->TempParameter = Parameters;
270250 this ->TempMutex = MyMutex;
271251 this ->RunningSign = true ;
272- this ->mThread = new std::thread (EasyCrossPlatform::Thread::SingleWorkCls::DoingJob, this );
252+ this ->mThread = std::thread (EasyCrossPlatform::Thread::SingleWorkCls::DoingJob, this );
253+ this ->mThread .detach ();
273254 return true ;
274255}
275256
276257void EasyCrossPlatform::Thread::SingleWorkCls::StopJob ()
277258{
278259
279- if (this ->mThread != NULL ) {
280- this ->RunningSign = false ;
281- if (this ->mThread ->joinable ()) {
282- this ->mThread ->join ();
283- }
284- delete this ->mThread ;
285- this ->mThread = NULL ;
286- }
260+ this ->RunningSign = false ;
287261 return ;
288262}
289-
290263bool EasyCrossPlatform::Thread::SingleWorkCls::getRunningStatus ()
291264{
292265 return this ->RunningSign ;
@@ -299,12 +272,5 @@ void EasyCrossPlatform::Thread::SingleWorkCls::ThreadJob(std::thread::id ThreadI
299272
300273EasyCrossPlatform::Thread::SingleWorkCls::~SingleWorkCls ()
301274{
302- this ->RunningSign = false ;
303- if (this ->mThread != NULL ) {
304- if (this ->mThread ->joinable ()) {
305- this ->mThread ->join ();
306- }
307- delete this ->mThread ;
308- this ->mThread = NULL ;
309- }
275+ if (this ->RunningSign ) { this ->StopJob (); }
310276}
0 commit comments