improved thread handling

This commit is contained in:
louis 2014-04-27 11:06:32 +02:00
parent 4f9aa5ca01
commit b22842dc8e

View File

@ -132,7 +132,9 @@ int cUpdate::exitDb() {
void cUpdate::Stop() { void cUpdate::Stop() {
loopActive = false; loopActive = false;
waitCondition.Broadcast(); waitCondition.Broadcast();
Cancel(3); Cancel(1);
while (Active())
cCondWait::SleepMs(10);
} }
int cUpdate::CheckConnection(int& timeout) { int cUpdate::CheckConnection(int& timeout) {
@ -200,7 +202,7 @@ int cUpdate::ReadScrapedEvents(void) {
int movieId = 0; int movieId = 0;
string channelId = ""; string channelId = "";
int numNew = 0; int numNew = 0;
for (int res = select->find(); res; res = select->fetch()) { for (int res = select->find(); res; res = select->fetch() && Running()) {
eventId = tEvents->getIntValue(cTableEvents::fiUseId); eventId = tEvents->getIntValue(cTableEvents::fiUseId);
channelId = tEvents->getStrValue(cTableEvents::fiChannelId); channelId = tEvents->getStrValue(cTableEvents::fiChannelId);
seriesId = tEvents->getIntValue(cTableEvents::fiScrSeriesId); seriesId = tEvents->getIntValue(cTableEvents::fiScrSeriesId);
@ -231,7 +233,7 @@ int cUpdate::ReadSeries(bool isRec) {
bool isNew = false; bool isNew = false;
int numNew = 0; int numNew = 0;
while (scrapManager->GetNextSeries(isRec, seriesId, episodeId)) { while (scrapManager->GetNextSeries(isRec, seriesId, episodeId) && Running()) {
cTVDBSeries *series = scrapManager->GetSeries(seriesId); cTVDBSeries *series = scrapManager->GetSeries(seriesId);
if (!series) { if (!series) {
tSeries->clear(); tSeries->clear();
@ -605,7 +607,7 @@ int cUpdate::ReadMovies(bool isRec) {
return 0; return 0;
int numNew = 0; int numNew = 0;
while (scrapManager->GetNextMovie(isRec, movieId)) { while (scrapManager->GetNextMovie(isRec, movieId) && Running()) {
cMovieDbMovie *movie = scrapManager->GetMovie(movieId); cMovieDbMovie *movie = scrapManager->GetMovie(movieId);
if (movie) if (movie)
continue; continue;
@ -1178,7 +1180,7 @@ void cUpdate::Action() {
continue; continue;
} }
//Update Recordings from Database //Update Recordings from Database
if (forceRecordingUpdate || (time(0) - lastScanNewRecDB > scanNewRecDBFreq)) { if (forceRecordingUpdate || (time(0) - lastScanNewRecDB > scanNewRecDBFreq) && Running()) {
if (!init && CheckEpgdBusy()) if (!init && CheckEpgdBusy())
continue; continue;
int numNewRecs = ReadRecordings(); int numNewRecs = ReadRecordings();
@ -1191,7 +1193,7 @@ void cUpdate::Action() {
} }
//Update Events //Update Events
if (!config.headless && (forceUpdate || (time(0) - lastScan > scanFreq))) { if (!config.headless && (forceUpdate || (time(0) - lastScan > scanFreq)) && Running()) {
if (!init && CheckEpgdBusy()) if (!init && CheckEpgdBusy())
continue; continue;
int numNewEvents = ReadScrapedEvents(); int numNewEvents = ReadScrapedEvents();
@ -1220,7 +1222,7 @@ void cUpdate::Action() {
} }
//Scan new recordings //Scan new recordings
if (init || forceVideoDirUpdate || (time(0) - lastScanNewRec > scanNewRecFreq)) { if ((init || forceVideoDirUpdate || (time(0) - lastScanNewRec > scanNewRecFreq)) && Running()) {
if (CheckEpgdBusy()) { if (CheckEpgdBusy()) {
waitCondition.TimedWait(mutex, 1000); waitCondition.TimedWait(mutex, 1000);
continue; continue;
@ -1251,7 +1253,7 @@ void cUpdate::Action() {
} }
//Cleanup //Cleanup
if (time(0) - lastCleanup > cleanUpFreq) { if ((time(0) - lastCleanup > cleanUpFreq) && Running()){
if (CheckEpgdBusy()) { if (CheckEpgdBusy()) {
waitCondition.TimedWait(mutex, 1000); waitCondition.TimedWait(mutex, 1000);
continue; continue;