From 1e9b16d20bacb9795a07af5ff61db67fc78c3728 Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Thu, 4 Oct 2012 12:32:31 +0200 Subject: The cThread constructor now has an additional boolean parameter that can be set to true to have this thread run at a lower priority --- HISTORY | 7 ++++++- cutter.c | 6 ++---- epg.c | 6 ++---- recording.c | 6 ++---- sections.c | 5 ++--- thread.c | 11 ++++++++--- thread.h | 7 +++++-- 7 files changed, 27 insertions(+), 21 deletions(-) diff --git a/HISTORY b/HISTORY index 03808ab0..39232718 100644 --- a/HISTORY +++ b/HISTORY @@ -7272,7 +7272,7 @@ Video Disk Recorder Revision History ".keep" to prevent a directory from being deleted when it is empty. Currently the only file name that is ignored is ".sort". -2012-10-03: Version 1.7.32 +2012-10-04: Version 1.7.32 - Pressing the Play key during normal live viewing mode now opens the Recordings menu if there is no "last viewed" recording (thanks to Alexander Wenzel). @@ -7280,3 +7280,8 @@ Video Disk Recorder Revision History - cIoThrottle::Engaged() is now also checked in cRemoveDeletedRecordingsThread::Action(), to suspend removing deleted recordings in case this is necessary to make room for new, ongoing recordings (suggested by Udo Richter). +- The cThread constructor now has an additional boolean parameter that can be set to + true to have this thread run at a lower priority. Plugin authors that use low + priority threads may want to use this instead of the calls to SetPriority(19) and + SetIOPriority(7). The priority of a thread ("low" or "high") is now logged when the + thread starts. diff --git a/cutter.c b/cutter.c index bcae2b72..a0e2b477 100644 --- a/cutter.c +++ b/cutter.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: cutter.c 2.14 2012/09/20 09:12:47 kls Exp $ + * $Id: cutter.c 2.15 2012/10/04 12:19:37 kls Exp $ */ #include "cutter.h" @@ -33,7 +33,7 @@ public: }; cCuttingThread::cCuttingThread(const char *FromFileName, const char *ToFileName) -:cThread("video cutting") +:cThread("video cutting", true) { error = NULL; fromFile = toFile = NULL; @@ -69,8 +69,6 @@ void cCuttingThread::Action(void) { cMark *Mark = fromMarks.First(); if (Mark) { - SetPriority(19); - SetIOPriority(7); fromFile = fromFileName->Open(); toFile = toFileName->Open(); if (!fromFile || !toFile) diff --git a/epg.c b/epg.c index 1c1ecdf5..3da7dc1d 100644 --- a/epg.c +++ b/epg.c @@ -7,7 +7,7 @@ * Original version (as used in VDR before 1.3.0) written by * Robert Schneider and Rolf Hakenes . * - * $Id: epg.c 2.21 2012/09/29 14:29:49 kls Exp $ + * $Id: epg.c 2.22 2012/10/04 12:21:24 kls Exp $ */ #include "epg.h" @@ -1148,14 +1148,12 @@ public: }; cEpgDataWriter::cEpgDataWriter(void) -:cThread("epg data writer") +:cThread("epg data writer", true) { } void cEpgDataWriter::Action(void) { - SetPriority(19); - SetIOPriority(7); Perform(); } diff --git a/recording.c b/recording.c index 8600e077..783a46e5 100644 --- a/recording.c +++ b/recording.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: recording.c 2.65 2012/10/03 12:52:13 kls Exp $ + * $Id: recording.c 2.66 2012/10/04 12:21:38 kls Exp $ */ #include "recording.h" @@ -83,14 +83,12 @@ public: }; cRemoveDeletedRecordingsThread::cRemoveDeletedRecordingsThread(void) -:cThread("remove deleted recordings") +:cThread("remove deleted recordings", true) { } void cRemoveDeletedRecordingsThread::Action(void) { - SetPriority(19); - SetIOPriority(7); // Make sure only one instance of VDR does this: cLockFile LockFile(VideoDirectory); if (LockFile.Lock()) { diff --git a/sections.c b/sections.c index c9ed0c14..991499bc 100644 --- a/sections.c +++ b/sections.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: sections.c 2.1 2012/08/26 12:53:39 kls Exp $ + * $Id: sections.c 2.2 2012/10/04 12:21:59 kls Exp $ */ #include "sections.h" @@ -40,7 +40,7 @@ public: // --- cSectionHandler ------------------------------------------------------- cSectionHandler::cSectionHandler(cDevice *Device) -:cThread("section handler") +:cThread("section handler", true) { shp = new cSectionHandlerPrivate; device = Device; @@ -164,7 +164,6 @@ void cSectionHandler::SetStatus(bool On) void cSectionHandler::Action(void) { - SetPriority(19); while (Running()) { Lock(); diff --git a/thread.c b/thread.c index a650fab8..b80ee70d 100644 --- a/thread.c +++ b/thread.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: thread.c 2.5 2012/09/20 09:05:50 kls Exp $ + * $Id: thread.c 2.6 2012/10/04 12:20:43 kls Exp $ */ #include "thread.h" @@ -204,7 +204,7 @@ void cMutex::Unlock(void) tThreadId cThread::mainThreadId = 0; -cThread::cThread(const char *Description) +cThread::cThread(const char *Description, bool LowPriority) { active = running = false; childTid = 0; @@ -212,6 +212,7 @@ cThread::cThread(const char *Description) description = NULL; if (Description) SetDescription("%s", Description); + lowPriority = LowPriority; } cThread::~cThread() @@ -248,12 +249,16 @@ void *cThread::StartThread(cThread *Thread) { Thread->childThreadId = ThreadId(); if (Thread->description) { - dsyslog("%s thread started (pid=%d, tid=%d)", Thread->description, getpid(), Thread->childThreadId); + dsyslog("%s thread started (pid=%d, tid=%d, prio=%s)", Thread->description, getpid(), Thread->childThreadId, Thread->lowPriority ? "low" : "high"); #ifdef PR_SET_NAME if (prctl(PR_SET_NAME, Thread->description, 0, 0, 0) < 0) esyslog("%s thread naming failed (pid=%d, tid=%d)", Thread->description, getpid(), Thread->childThreadId); #endif } + if (Thread->lowPriority) { + Thread->SetPriority(19); + Thread->SetIOPriority(7); + } Thread->Action(); if (Thread->description) dsyslog("%s thread ended (pid=%d, tid=%d)", Thread->description, getpid(), Thread->childThreadId); diff --git a/thread.h b/thread.h index f77e8198..a08d40c9 100644 --- a/thread.h +++ b/thread.h @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: thread.h 2.2 2012/09/20 08:46:27 kls Exp $ + * $Id: thread.h 2.3 2012/10/04 12:15:39 kls Exp $ */ #ifndef __THREAD_H @@ -83,6 +83,7 @@ private: tThreadId childThreadId; cMutex mutex; char *description; + bool lowPriority; static tThreadId mainThreadId; static void *StartThread(cThread *Thread); protected: @@ -106,11 +107,13 @@ protected: ///< If WaitSeconds is -1, only 'running' is set to false and Cancel() ///< returns immediately, without killing the thread. public: - cThread(const char *Description = NULL); + cThread(const char *Description = NULL, bool LowPriority = false); ///< Creates a new thread. ///< If Description is present, a log file entry will be made when ///< the thread starts and stops. The Start() function must be called ///< to actually start the thread. + ///< LowPriority can be set to true to make this thread run at a lower + ///< priority. virtual ~cThread(); void SetDescription(const char *Description, ...) __attribute__ ((format (printf, 2, 3))); bool Start(void); -- cgit v1.2.3