summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohann Friedrichs <johann.friedrichs@web.de>2017-10-15 09:22:55 (GMT)
committerFrank Neumann <fnu@yavdr.org>2017-10-15 09:22:55 (GMT)
commitc7c02e2031801015dc70d6d4652e71ab9c2a2ea6 (patch)
tree7c0bbf6c74e97c90d93ad0d4b0c6db57b9e8cb90
parented8efb5807338c947a18fe0272ac05f19e94a290 (diff)
downloadvdr-plugin-epgsearch-c7c02e2031801015dc70d6d4652e71ab9c2a2ea6.tar.gz
vdr-plugin-epgsearch-c7c02e2031801015dc70d6d4652e71ab9c2a2ea6.tar.bz2
Fix deadlock.
-rw-r--r--recdone_thread.c170
-rw-r--r--recdone_thread.h10
-rw-r--r--recstatus.c3
3 files changed, 97 insertions, 86 deletions
diff --git a/recdone_thread.c b/recdone_thread.c
index 7029849..9e7b38b 100644
--- a/recdone_thread.c
+++ b/recdone_thread.c
@@ -76,99 +76,105 @@ int cRecdoneThread::RecLengthInSecs(const cRecording *pRecording)
void cRecdoneThread::Action(void)
{
- LogFile.Log(1,"started recdone_thread with %s",m_filename);
+ LogFile.Log(1,"started recdone_thread");
cMutexLock RecsDoneLock(&RecsDone);
time_t now = time(NULL);
// remove timers that finished recording from TimersRecording
// incomplete recordings are kept for a while, perhaps they will be resumed
LOCK_TIMERS_READ;
- cMutexLock TimersRecordingLock(&TimersRecording);
- cRecDoneTimerObj *tiR = TimersRecording.First();
- while(tiR)
+ while (m_fnames.size())
{
- // check if timer still exists
- bool found = false;
-
- for (const cTimer *ti = Timers->First(); ti; ti = Timers->Next(ti))
- if (ti == tiR->timer)
+ vector<string>::iterator it=m_fnames.begin();
+ const char *m_filename=(*it).c_str();
+ LogFile.Log(1,"recdone_thread processing %s",m_filename);
+ cMutexLock TimersRecordingLock(&TimersRecording);
+ cRecDoneTimerObj *tiR = TimersRecording.First();
+ while(tiR)
{
- found = true;
- break;
- }
+ // check if timer still exists
+ bool found = false;
- if (found && !tiR->timer->Recording())
- {
- if (tiR->recDone)
+ for (const cTimer *ti = Timers->First(); ti; ti = Timers->Next(ti))
+ if (ti == tiR->timer)
+ {
+ found = true;
+ break;
+ }
+
+ if (found && !tiR->timer->Recording())
{
- cSearchExt* search = SearchExts.GetSearchFromID(tiR->recDone->searchID);
- if (!search) return;
- // check if recording has ended before timer end
-
- bool complete = true;
- const cRecording *pRecording;
- {
- LOCK_RECORDINGS_READ;
- pRecording = Recordings->GetByName(m_filename);
- }
- long timerLengthSecs = tiR->timer->StopTime()-tiR->timer->StartTime();
- int recFraction = 100;
- if (pRecording && timerLengthSecs)
- {
- int recLen = RecLengthInSecs(pRecording);
- recFraction = double(recLen) * 100 / timerLengthSecs;
- }
- bool vpsUsed = tiR->timer->HasFlags(tfVps) && tiR->timer->Event() && tiR->timer->Event()->Vps();
- if ((!vpsUsed && now < tiR->timer->StopTime()) || recFraction < (vpsUsed ? 90: 98)) // assure timer has reached its end or at least 98% were recorded
- {
- complete = false;
- LogFile.Log(1,"finished: '%s' (not complete! - recorded only %d%%); search timer: '%s'; VPS used: %s", tiR->timer->File(), recFraction, search->search, vpsUsed ? "Yes": "No");
- }
- else
- {
- LogFile.Log(1,"finished: '%s'; search timer: '%s'; VPS used: %s", tiR->timer->File(), search->search, vpsUsed ? "Yes": "No");
- if (recFraction < 100)
- LogFile.Log(2,"recorded %d%%'", recFraction);
- }
- if (complete)
- {
- RecsDone.Add(tiR->recDone);
- LogFile.Log(1,"added rec done for '%s~%s';%s", tiR->recDone->title?tiR->recDone->title:"unknown title",
- tiR->recDone->shortText?tiR->recDone->shortText:"unknown subtitle",
- search->search);
- RecsDone.Save();
- tiR->recDone = NULL; // prevent deletion
- tiR->lastBreak = 0;
-
- // check for search timers to delete automatically
- SearchExts.CheckForAutoDelete(search);
-
- // trigger a search timer update (skip running events)
- search->skipRunningEvents = true;
- updateForced = 1;
- }
- else if (tiR->lastBreak == 0) // store first break
- tiR->lastBreak = now;
+ if (tiR->recDone)
+ {
+ cSearchExt* search = SearchExts.GetSearchFromID(tiR->recDone->searchID);
+ if (!search) return;
+ // check if recording has ended before timer end
+
+ bool complete = true;
+ const cRecording *pRecording;
+ {
+ LOCK_RECORDINGS_READ;
+ pRecording = Recordings->GetByName(m_filename);
+ }
+ long timerLengthSecs = tiR->timer->StopTime()-tiR->timer->StartTime();
+ int recFraction = 100;
+ if (pRecording && timerLengthSecs)
+ {
+ int recLen = RecLengthInSecs(pRecording);
+ recFraction = double(recLen) * 100 / timerLengthSecs;
+ }
+ bool vpsUsed = tiR->timer->HasFlags(tfVps) && tiR->timer->Event() && tiR->timer->Event()->Vps();
+ if ((!vpsUsed && now < tiR->timer->StopTime()) || recFraction < (vpsUsed ? 90: 98)) // assure timer has reached its end or at least 98% were recorded
+ {
+ complete = false;
+ LogFile.Log(1,"finished: '%s' (not complete! - recorded only %d%%); search timer: '%s'; VPS used: %s", tiR->timer->File(), recFraction, search->search, vpsUsed ? "Yes": "No");
+ }
+ else
+ {
+ LogFile.Log(1,"finished: '%s'; search timer: '%s'; VPS used: %s", tiR->timer->File(), search->search, vpsUsed ? "Yes": "No");
+ if (recFraction < 100)
+ LogFile.Log(2,"recorded %d%%'", recFraction);
+ }
+ if (complete)
+ {
+ RecsDone.Add(tiR->recDone);
+ LogFile.Log(1,"added rec done for '%s~%s';%s", tiR->recDone->title?tiR->recDone->title:"unknown title",
+ tiR->recDone->shortText?tiR->recDone->shortText:"unknown subtitle",
+ search->search);
+ RecsDone.Save();
+ tiR->recDone = NULL; // prevent deletion
+ tiR->lastBreak = 0;
+
+ // check for search timers to delete automatically
+ SearchExts.CheckForAutoDelete(search);
+
+ // trigger a search timer update (skip running events)
+ search->skipRunningEvents = true;
+ updateForced = 1;
+ }
+ else if (tiR->lastBreak == 0) // store first break
+ tiR->lastBreak = now;
+ }
+ if (tiR->lastBreak == 0 || (now - tiR->lastBreak) > ALLOWED_BREAK_INSECS)
+ { // remove finished recordings or those with an unallowed break
+ if (tiR->recDone) delete tiR->recDone; // clean up
+ cRecDoneTimerObj *tiRNext = TimersRecording.Next(tiR);
+ TimersRecording.Del(tiR);
+ tiR = tiRNext;
+ continue;
+ }
+ break;
}
- if (tiR->lastBreak == 0 || (now - tiR->lastBreak) > ALLOWED_BREAK_INSECS)
- { // remove finished recordings or those with an unallowed break
- if (tiR->recDone) delete tiR->recDone; // clean up
- cRecDoneTimerObj *tiRNext = TimersRecording.Next(tiR);
- TimersRecording.Del(tiR);
- tiR = tiRNext;
- continue;
+ if (!found)
+ {
+ if (tiR->recDone) delete tiR->recDone; // clean up
+ cRecDoneTimerObj *tiRNext = TimersRecording.Next(tiR);
+ TimersRecording.Del(tiR);
+ tiR = tiRNext;
+ continue;
}
- break;
- }
- if (!found)
- {
- if (tiR->recDone) delete tiR->recDone; // clean up
- cRecDoneTimerObj *tiRNext = TimersRecording.Next(tiR);
- TimersRecording.Del(tiR);
- tiR = tiRNext;
- continue;
+ tiR = TimersRecording.Next(tiR);
}
- tiR = TimersRecording.Next(tiR);
- }
- if (m_filename) free(m_filename);
+ m_fnames.erase(it);
+ } // while fnames
LogFile.Log(1,"recdone_thread ended");
}
diff --git a/recdone_thread.h b/recdone_thread.h
index adb65f9..43f5f3d 100644
--- a/recdone_thread.h
+++ b/recdone_thread.h
@@ -21,18 +21,24 @@ Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#ifndef VDR_RECDONE_THREAD_H
#define VDR_RECDONE_THREAD_H
+#include <vector>
+#include <string>
#include <vdr/thread.h>
#include "recstatus.h"
+using std::vector;
+using std::string;
+
class cRecdoneThread: public cThread {
private:
- char * m_filename;
+ vector<string>m_fnames;
public:
virtual void Action(void);
cRecdoneThread(void);
virtual ~cRecdoneThread();
void SetFilename(const char *FileName) {
- m_filename = strdup(FileName); };
+ m_fnames.push_back(FileName);
+ }
int RecLengthInSecs(const cRecording *pRecording);
bool IsPesRecording(const cRecording *pRecording);
};
diff --git a/recstatus.c b/recstatus.c
index 0b382fd..20a31a6 100644
--- a/recstatus.c
+++ b/recstatus.c
@@ -107,8 +107,7 @@ void cRecStatusMonitor::Recording(const cDevice *Device, const char *Name, const
if (!On)
{
// must be done in a different thread because we hold timer and scheduling lock here
- while (RecdoneThread.Active()) cCondWait::SleepMs(100); // wait before changing filename
- RecdoneThread.SetFilename(Filename);
+ RecdoneThread.SetFilename(Filename); // push_back Filename for processing
RecdoneThread.Start();
}
}