OSDN Git Service

[dennco] integrated engine related changes from denncoCreator
[dennco/dennco.git] / Source / platform / qt / qtdnthreadimpl.cpp
1 //  Copyright (c) 2012 Dennco Project
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16 //
17 //  Created by tkawata on Mar-1/2012.
18 //
19 #include "qtdnthreadimpl.h"
20
21 #include "TKLog.h"
22
23 //static
24 DNThread* DNThreadImpl::createThread(DNThreadFunc threadFunc, void *data)
25 {
26     return new DNThread(new QtDNThreadImpl(threadFunc,data));
27 }
28
29 QtDNThreadImpl::QtDNThreadImpl(DNThreadFunc threadFunc, void *data) : mThreadFunc(threadFunc), mData(data)
30 {
31 }
32
33 QtDNThreadImpl::~QtDNThreadImpl()
34 {
35     mLock.lock();
36     if (isRunning())
37     {
38         if (!wait(5000))
39         {
40             TKLog::printf(TKLog::WARNING, "!WARNING! DNThread %p hasn't finished in 5sec. execute terminate to quit  forcedly ", this);
41             setTerminationEnabled(true);
42             terminate();
43         }
44     }
45     mLock.unlock();
46 }
47
48 bool QtDNThreadImpl::start()
49 {
50     if (isRunning())
51         return false;
52
53     QThread::start();
54
55     return true;
56 }
57
58 void QtDNThreadImpl::run()
59 {
60     mThreadFunc(mData);
61 }
62
63 bool QtDNThreadImpl::waitForExit(int timeout)
64 {
65     return wait(timeout);
66 }