• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision9c9331905a9899c0df8b4c1cac0ee4c4b2916ca4 (tree)
Time2014-08-11 17:00:00
Authoralucky4416 <alucky4416@user...>
Commiteralucky4416

Log Message

change: add mutexlockert to ThSchManager and PlayMusicThread.

Change Summary

Incremental Difference

--- a/PlayMusicThread.cpp
+++ b/PlayMusicThread.cpp
@@ -5,6 +5,7 @@
55
66 PlayMusicThread::PlayMusicThread(WId winId)
77 {
8+ QMutexLocker locker(&mutex);
89 stopped = false;
910
1011 #ifdef __WIN32__
@@ -31,28 +32,41 @@ PlayMusicThread::~PlayMusicThread()
3132
3233 void PlayMusicThread::stop()
3334 {
35+ QMutexLocker locker(&mutex);
3436 stopped = true;
3537 }
3638
3739 void PlayMusicThread::PlayMusic(const QString &filepath) {
3840 if (state == IDLE) {
41+ QMutexLocker locker(&mutex);
3942 FilePath = filepath;
4043 }
4144 }
4245
4346 void PlayMusicThread::StopMusic() {
4447 if (state == PLAYING) {
48+ QMutexLocker locker(&mutex);
4549 playstopped = true;
4650 }
4751 }
4852 int PlayMusicThread::GetPlayStatus() {
53+ QMutexLocker locker(&mutex);
4954 return state;
5055 }
5156
5257 void PlayMusicThread::run()
5358 {
54- while (!stopped) {
59+
60+ forever {
61+ {
62+ QMutexLocker locker(&mutex);
63+ if (stopped) {
64+ stopped = false;
65+ break;
66+ }
67+ }
5568 if (state == IDLE) {
69+ QMutexLocker locker(&mutex);
5670 if (FilePath.isEmpty()) {
5771 ;
5872 } else {
@@ -69,6 +83,7 @@ void PlayMusicThread::run()
6983 emit MusicStarted(PlayFileName);
7084 }
7185 } else if (state == PLAYING){
86+ QMutexLocker locker(&mutex);
7287 if (!IsMusicPlaying() || playstopped) {
7388 // Music Stop
7489 MusicStop();
--- a/PlayMusicThread.h
+++ b/PlayMusicThread.h
@@ -2,8 +2,10 @@
22 #define PLAYMUSICTHREAD_H
33
44 #include <QWidget> // WId
5-#include <QThread>
65 #include <QString>
6+#include <QThread>
7+#include <QMutexLocker>
8+
79
810 #include <bass.h>
911
@@ -34,6 +36,7 @@ protected:
3436 int IsMusicPlaying();
3537
3638 private:
39+ QMutex mutex;
3740 volatile bool stopped;
3841 volatile bool playstopped;
3942
--- a/thschmanager.cpp
+++ b/thschmanager.cpp
@@ -2,6 +2,7 @@
22
33 #include <QStringList>
44 #include <QDateTime>
5+#include <QMutexLocker>
56
67 #include <QDebug>
78
@@ -20,23 +21,39 @@ ThSchManager::~ThSchManager()
2021
2122 void ThSchManager::stop()
2223 {
24+ QMutexLocker locker(&mutex);
2325 stopped = true;
2426 }
2527
2628 void ThSchManager::run()
2729 {
30+ bool EventEmpty;
2831 EventData event;
2932 int event_id;
3033 int status = 0; // 0 = idle, 1 = exec
3134 int index;
3235 QString nexttime;
3336
34- while (!stopped) {
35- if (EvtQue->isEmpty()) {
37+ forever {
38+ {
39+ QMutexLocker locker(&mutex);
40+ if (stopped) {
41+ stopped = false;
42+ break;
43+ } else {
44+ if (EventEmpty = EvtQue->isEmpty()) {
45+ ;
46+ } else{
47+ event = EvtQue->dequeue();
48+ }
49+ }
50+ }
51+ if (EventEmpty) {
3652 if (status == 1) { // EXEC (supervise sch time)
53+ QMutexLocker locker(&mutex);
3754 // Is Saturday and Sunday
3855 if ((ExcludeSS && isSaturdayOrSunday()) || (ExcludeHolidays && isHolidays())) {
39- sleep(1); // skip
56+ ; // skip
4057 } else {
4158 // Time Check
4259 if (isMatchSchTimeVsCurrentTime(&nexttime)) {
@@ -45,50 +62,48 @@ void ThSchManager::run()
4562 ThPlayMusic->PlayMusic(ChimeFilepath);
4663
4764 // next
48- if ((index + 1) < SchTimeList.count())
65+ if ((index + 1) < SchTimeList.count()) {
4966 index++;
50- else
67+ } else {
5168 index = 0;
69+ }
5270 nexttime = SchTimeList.at(index);
5371 emit sig_notify_nexttime(nexttime);
5472 // qDebug() << "### next time : " << nexttime;
55- } else {
56- sleep(1);
5773 }
5874 }
59- } else {
60- sleep(1);
6175 }
76+ sleep(1);
6277 } else {
63- event = EvtQue->dequeue();
64- event_id = event.id;
65- switch(event_id) {
66- case Ev_Start:
67- if (status == 0) { // idle
68- // Start;
69- // qDebug() << "### Start!";
70- index = nextSchTimeIndex(&SchTimeList);
71- nexttime = SchTimeList.at(index);
72- emit sig_notify_nexttime(nexttime);
73- // qDebug() << "### next time : " << nexttime;
74- status = 1; // goto EXEC
75- }
76- break;
77- case Ev_Stop:
78- if (status == 1) {
79- // Stop;
80- emit sig_notify_nexttime("idle...");
81- // qDebug() << "### Stop!";
82- status = 0; // goto IDLE
78+ // event = EvtQue->dequeue();
79+ event_id = event.id;
80+ switch(event_id) {
81+ case Ev_Start:
82+ if (status == 0) { // idle
83+ QMutexLocker locker(&mutex);
84+ // Start;
85+ // qDebug() << "### Start!";
86+ index = nextSchTimeIndex(&SchTimeList);
87+ nexttime = SchTimeList.at(index);
88+ emit sig_notify_nexttime(nexttime);
89+ // qDebug() << "### next time : " << nexttime;
90+ status = 1; // goto EXEC
91+ }
92+ break;
93+ case Ev_Stop:
94+ if (status == 1) {
95+ QMutexLocker locker(&mutex);
96+ // Stop;
97+ emit sig_notify_nexttime("idle...");
98+ // qDebug() << "### Stop!";
99+ status = 0; // goto IDLE
100+ }
101+ break;
102+ default:
103+ break;
83104 }
84- break;
85- default:
86- break;
87- }
88- }
89-
90- } // while(!stopped)
91-
105+ } // if(EventEmpty)
106+ } // forever
92107 }
93108
94109 void ThSchManager::sendEvent_Start()
@@ -96,6 +111,7 @@ void ThSchManager::sendEvent_Start()
96111 EventData evt;
97112
98113 evt.id = Ev_Start;
114+ QMutexLocker locker(&mutex);
99115 EvtQue->enqueue(evt);
100116 }
101117
@@ -104,6 +120,7 @@ void ThSchManager::sendEvent_Stop()
104120 EventData evt;
105121
106122 evt.id = Ev_Stop;
123+ QMutexLocker locker(&mutex);
107124 EvtQue->enqueue(evt);
108125 }
109126
@@ -121,6 +138,7 @@ void ThSchManager::setSchTimeList(QStringList list)
121138 {
122139 if (list.isEmpty()) return;
123140
141+ QMutexLocker locker(&mutex);
124142 SchTimeList.clear();
125143 SchTimeList = list;
126144 // qDebug() << "ThSchManager::SchTimeList:" << SchTimeList;
@@ -130,6 +148,7 @@ void ThSchManager::setHolidaysList(QStringList list)
130148 {
131149 if (list.isEmpty()) return;
132150
151+ QMutexLocker locker(&mutex);
133152 HolidaysList.clear();
134153 HolidaysList = list;
135154 // qDebug() << "ThSchManager::HolidaysList:" << HolidaysList;
@@ -137,11 +156,13 @@ void ThSchManager::setHolidaysList(QStringList list)
137156
138157 void ThSchManager::setExcludeSS(bool flag)
139158 {
159+ QMutexLocker locker(&mutex);
140160 ExcludeSS = flag;
141161 }
142162
143163 void ThSchManager::setExcludeHolidays(bool flag)
144164 {
165+ QMutexLocker locker(&mutex);
145166 ExcludeHolidays = flag;
146167 }
147168
--- a/thschmanager.h
+++ b/thschmanager.h
@@ -38,6 +38,7 @@ protected:
3838 void run();
3939
4040 private:
41+ QMutex mutex;
4142 volatile bool stopped;
4243
4344 // Event ID