diff options
-rw-r--r-- | dvbapi.c | 9 | ||||
-rw-r--r-- | dvbapi.h | 6 | ||||
-rw-r--r-- | eit.c | 9 | ||||
-rw-r--r-- | eit.h | 7 | ||||
-rw-r--r-- | menu.c | 14 | ||||
-rw-r--r-- | svdrp.c | 6 | ||||
-rw-r--r-- | thread.c | 28 | ||||
-rw-r--r-- | thread.h | 18 |
8 files changed, 69 insertions, 28 deletions
@@ -7,7 +7,7 @@ * DVD support initially written by Andreas Schultz <aschultz@warp10.net> * based on dvdplayer-0.5 by Matjaz Thaler <matjaz.thaler@guest.arnes.si> * - * $Id: dvbapi.c 1.149 2002/02/23 10:40:55 kls Exp $ + * $Id: dvbapi.c 1.150 2002/02/23 13:11:13 kls Exp $ */ //#define DVDDEBUG 1 @@ -2732,13 +2732,6 @@ void cDvbApi::Cleanup(void) PrimaryDvbApi = NULL; } -const cSchedules *cDvbApi::Schedules(cThreadLock *ThreadLock) const -{ - if (siProcessor && ThreadLock->Lock(siProcessor)) - return siProcessor->Schedules(); - return NULL; -} - bool cDvbApi::GrabImage(const char *FileName, bool Jpeg, int Quality, int SizeX, int SizeY) { int videoDev = OstOpen(DEV_VIDEO, CardIndex(), O_RDWR, true); @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: dvbapi.h 1.61 2002/02/03 16:43:38 kls Exp $ + * $Id: dvbapi.h 1.62 2002/02/23 13:11:07 kls Exp $ */ #ifndef __DVBAPI_H @@ -143,10 +143,6 @@ public: private: cSIProcessor *siProcessor; public: - const cSchedules *Schedules(cThreadLock *ThreadLock) const; - // Caller must provide a cThreadLock which has to survive the entire - // time the returned cSchedules is accessed. Once the cSchedules is no - // longer used, the cThreadLock must be destroyed. void SetUseTSTime(bool On) { if (siProcessor) siProcessor->SetUseTSTime(On); } // Image Grab facilities @@ -16,7 +16,7 @@ * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * - * $Id: eit.c 1.35 2002/02/15 13:58:26 kls Exp $ + * $Id: eit.c 1.36 2002/02/23 13:53:53 kls Exp $ ***************************************************************************/ #include "eit.h" @@ -913,6 +913,13 @@ cSIProcessor::~cSIProcessor() delete fileName; } +const cSchedules *cSIProcessor::Schedules(cMutexLock &MutexLock) +{ + if (MutexLock.Lock(&schedulesMutex)) + return schedules; + return NULL; +} + void cSIProcessor::SetEpgDataFileName(const char *FileName) { epgDataFileName = NULL; @@ -16,7 +16,7 @@ * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * - * $Id: eit.h 1.13 2002/01/13 16:18:23 kls Exp $ + * $Id: eit.h 1.14 2002/02/23 13:51:31 kls Exp $ ***************************************************************************/ #ifndef __EIT_H @@ -146,10 +146,13 @@ public: ~cSIProcessor(); static void SetEpgDataFileName(const char *FileName); static const char *GetEpgDataFileName(void); + static const cSchedules *Schedules(cMutexLock &MutexLock); + // Caller must provide a cMutexLock which has to survive the entire + // time the returned cSchedules is accessed. Once the cSchedules is no + // longer used, the cMutexLock must be destroyed. void SetStatus(bool On); bool SetUseTSTime(bool use); bool SetCurrentServiceID(unsigned short servid); - const cSchedules *Schedules(void) { return schedules; } }; #endif @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: menu.c 1.156 2002/02/23 09:33:04 kls Exp $ + * $Id: menu.c 1.157 2002/02/23 13:55:23 kls Exp $ */ #include "menu.h" @@ -1429,7 +1429,7 @@ cMenuScheduleItem::cMenuScheduleItem(const cEventInfo *EventInfo) class cMenuSchedule : public cOsdMenu { private: - cThreadLock threadLock; + cMutexLock mutexLock; const cSchedules *schedules; bool now, next; int otherChannel; @@ -1449,7 +1449,7 @@ cMenuSchedule::cMenuSchedule(void) cChannel *channel = Channels.GetByNumber(cDvbApi::CurrentChannel()); if (channel) { cMenuWhatsOn::SetCurrentChannel(channel->number); - schedules = cDvbApi::PrimaryDvbApi->Schedules(&threadLock); + schedules = cSIProcessor::Schedules(mutexLock); PrepareSchedule(channel); SetHelp(tr("Record"), tr("Now"), tr("Next")); } @@ -2262,8 +2262,8 @@ void cDisplayChannel::DisplayInfo(void) { if (withInfo) { const cEventInfo *Present = NULL, *Following = NULL; - cThreadLock ThreadLock; - const cSchedules *Schedules = cDvbApi::PrimaryDvbApi->Schedules(&ThreadLock); + cMutexLock MutexLock; + const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock); if (Schedules) { const cSchedule *Schedule = Schedules->GetSchedule(); if (Schedule) { @@ -2445,8 +2445,8 @@ bool cRecordControl::GetEventInfo(void) time_t Time = timer->active == taActInst ? timer->StartTime() + INSTANT_REC_EPG_LOOKAHEAD : timer->StartTime() + (timer->StopTime() - timer->StartTime()) / 2; for (int seconds = 0; seconds <= MAXWAIT4EPGINFO; seconds++) { { - cThreadLock ThreadLock; - const cSchedules *Schedules = dvbApi->Schedules(&ThreadLock); + cMutexLock MutexLock; + const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock); if (Schedules) { const cSchedule *Schedule = Schedules->GetSchedule(channel->pnr); if (Schedule) { @@ -10,7 +10,7 @@ * and interact with the Video Disk Recorder - or write a full featured * graphical interface that sits on top of an SVDRP connection. * - * $Id: svdrp.c 1.30 2002/02/02 15:59:18 kls Exp $ + * $Id: svdrp.c 1.31 2002/02/23 13:55:57 kls Exp $ */ #include "svdrp.h" @@ -600,8 +600,8 @@ void cSVDRP::CmdLSTC(const char *Option) void cSVDRP::CmdLSTE(const char *Option) { - cThreadLock ThreadLock; - const cSchedules *Schedules = cDvbApi::PrimaryDvbApi->Schedules(&ThreadLock); + cMutexLock MutexLock; + const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock); if (Schedules) { FILE *f = fdopen(file, "w"); if (f) { @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: thread.c 1.17 2002/02/17 14:47:28 kls Exp $ + * $Id: thread.c 1.18 2002/02/23 13:49:06 kls Exp $ */ #include "thread.h" @@ -190,6 +190,32 @@ bool cThread::EmergencyExit(bool Request) return emergencyExitRequested = true; // yes, it's an assignment, not a comparison! } +// --- cMutexLock ------------------------------------------------------------ + +cMutexLock::cMutexLock(cMutex *Mutex) +{ + mutex = NULL; + locked = false; + Lock(Mutex); +} + +cMutexLock::~cMutexLock() +{ + if (mutex && locked) + mutex->Unlock(); +} + +bool cMutexLock::Lock(cMutex *Mutex) +{ + if (Mutex && !mutex) { + mutex = Mutex; + Mutex->Lock(); + locked = true; + return true; + } + return false; +} + // --- cThreadLock ----------------------------------------------------------- cThreadLock::cThreadLock(cThread *Thread) @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: thread.h 1.11 2001/10/27 13:22:20 kls Exp $ + * $Id: thread.h 1.12 2002/02/23 13:53:38 kls Exp $ */ #ifndef __THREAD_H @@ -69,6 +69,22 @@ public: static bool EmergencyExit(bool Request = false); }; +// cMutexLock can be used to easily set a lock on mutex and make absolutely +// sure that it will be unlocked when the block will be left. Several locks can +// be stacked, so a function that makes many calls to another function which uses +// cMutexLock may itself use a cMutexLock to make one longer lock instead of many +// short ones. + +class cMutexLock { +private: + cMutex *mutex; + bool locked; +public: + cMutexLock(cMutex *Mutex = NULL); + ~cMutexLock(); + bool Lock(cMutex *Mutex); + }; + // cThreadLock can be used to easily set a lock in a thread and make absolutely // sure that it will be unlocked when the block will be left. Several locks can // be stacked, so a function that makes many calls to another function which uses |