1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

Implemented a hash for the channels to reduce the system load in the EIT scanning thread

This commit is contained in:
Klaus Schmidinger 2005-09-11 13:23:49 +02:00
parent 0c6ba1f928
commit 94d43abecf
7 changed files with 75 additions and 29 deletions

View File

@ -1430,6 +1430,7 @@ Georg Acher <acher@baycom.de>
for avoiding unnecessary calls to getLength() in libsi/si.c, and avoiding the for avoiding unnecessary calls to getLength() in libsi/si.c, and avoiding the
'& 0xff' in CRC32::crc32() of libsi/util.c '& 0xff' in CRC32::crc32() of libsi/util.c
for suggesting to reduce the priority of the section handler threads for suggesting to reduce the priority of the section handler threads
for a patch that was used to implement a hash for the channels
Henrik Niehaus <henrik.niehaus@gmx.de> Henrik Niehaus <henrik.niehaus@gmx.de>
for reporting a problem with timers with a day given as MTWTF--@6, i.e. a repeating for reporting a problem with timers with a day given as MTWTF--@6, i.e. a repeating

View File

@ -3747,7 +3747,7 @@ Video Disk Recorder Revision History
- The new SVDRP command EDIT can be used to start the editing process of a recording - The new SVDRP command EDIT can be used to start the editing process of a recording
(based on the CUTR patch by Harald Milz). (based on the CUTR patch by Harald Milz).
2005-09-10: Version 1.3.32 2005-09-11: Version 1.3.32
- Added some missing braces in remux.c (thanks to Wayne Keer for reporting this one). - Added some missing braces in remux.c (thanks to Wayne Keer for reporting this one).
- Removed unused MAINMENUENTRY from svdrpdemo.c (thanks to Udo Richter for reporting - Removed unused MAINMENUENTRY from svdrpdemo.c (thanks to Udo Richter for reporting
@ -3804,3 +3804,5 @@ Video Disk Recorder Revision History
Rother for reporting this one). Rother for reporting this one).
- Fixed converting summary.vdr files that would result in a very long 'short text' - Fixed converting summary.vdr files that would result in a very long 'short text'
(thanks to Carsten Koch). (thanks to Carsten Koch).
- Implemented a hash for the channels to reduce the system load in the EIT scanning
thread (based on a patch by Georg Acher).

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: channels.c 1.45 2005/09/04 10:49:12 kls Exp $ * $Id: channels.c 1.46 2005/09/11 11:17:19 kls Exp $
*/ */
#include "channels.h" #include "channels.h"
@ -342,11 +342,14 @@ void cChannel::SetId(int Nid, int Tid, int Sid, int Rid)
dsyslog("changing id of channel %d from %d-%d-%d-%d to %d-%d-%d-%d", Number(), nid, tid, sid, rid, Nid, Tid, Sid, Rid); dsyslog("changing id of channel %d from %d-%d-%d-%d to %d-%d-%d-%d", Number(), nid, tid, sid, rid, Nid, Tid, Sid, Rid);
modification |= CHANNELMOD_ID; modification |= CHANNELMOD_ID;
Channels.SetModified(); Channels.SetModified();
Channels.UnhashChannel(this);
} }
nid = Nid; nid = Nid;
tid = Tid; tid = Tid;
sid = Sid; sid = Sid;
rid = Rid; rid = Rid;
if (Number())
Channels.HashChannel(this);
} }
} }
@ -868,6 +871,16 @@ bool cChannels::Load(const char *FileName, bool AllowComments, bool MustExist)
return false; return false;
} }
void cChannels::HashChannel(cChannel *Channel)
{
channelsHashSid.Add(Channel, Channel->Sid());
}
void cChannels::UnhashChannel(cChannel *Channel)
{
channelsHashSid.Del(Channel, Channel->Sid());
}
int cChannels::GetNextGroup(int Idx) int cChannels::GetNextGroup(int Idx)
{ {
cChannel *channel = Get(++Idx); cChannel *channel = Get(++Idx);
@ -894,6 +907,7 @@ int cChannels::GetNextNormal(int Idx)
void cChannels::ReNumber( void ) void cChannels::ReNumber( void )
{ {
channelsHashSid.Clear();
int Number = 1; int Number = 1;
for (cChannel *channel = First(); channel; channel = Next(channel)) { for (cChannel *channel = First(); channel; channel = Next(channel)) {
if (channel->GroupSep()) { if (channel->GroupSep()) {
@ -901,6 +915,7 @@ void cChannels::ReNumber( void )
Number = channel->Number(); Number = channel->Number();
} }
else { else {
HashChannel(channel);
maxNumber = Number; maxNumber = Number;
channel->SetNumber(Number++); channel->SetNumber(Number++);
} }
@ -924,33 +939,44 @@ cChannel *cChannels::GetByNumber(int Number, int SkipGap)
cChannel *cChannels::GetByServiceID(int Source, int Transponder, unsigned short ServiceID) cChannel *cChannels::GetByServiceID(int Source, int Transponder, unsigned short ServiceID)
{ {
for (cChannel *channel = First(); channel; channel = Next(channel)) { cList<cHashObject> *list = channelsHashSid.GetList(ServiceID);
if (!channel->GroupSep() && channel->Source() == Source && ISTRANSPONDER(channel->Transponder(), Transponder) && channel->Sid() == ServiceID) if (list) {
for (cHashObject *hobj = list->First(); hobj; hobj = list->Next(hobj)) {
cChannel *channel = (cChannel *)hobj->Object();
if (channel->Sid() == ServiceID && channel->Source() == Source && ISTRANSPONDER(channel->Transponder(), Transponder))
return channel; return channel;
} }
}
return NULL; return NULL;
} }
cChannel *cChannels::GetByChannelID(tChannelID ChannelID, bool TryWithoutRid, bool TryWithoutPolarization) cChannel *cChannels::GetByChannelID(tChannelID ChannelID, bool TryWithoutRid, bool TryWithoutPolarization)
{ {
for (cChannel *channel = First(); channel; channel = Next(channel)) { int sid = ChannelID.Sid();
if (!channel->GroupSep() && channel->GetChannelID() == ChannelID) cList<cHashObject> *list = channelsHashSid.GetList(sid);
if (list) {
for (cHashObject *hobj = list->First(); hobj; hobj = list->Next(hobj)) {
cChannel *channel = (cChannel *)hobj->Object();
if (channel->Sid() == sid && channel->GetChannelID() == ChannelID)
return channel; return channel;
} }
if (TryWithoutRid) { if (TryWithoutRid) {
ChannelID.ClrRid(); ChannelID.ClrRid();
for (cChannel *channel = First(); channel; channel = Next(channel)) { for (cHashObject *hobj = list->First(); hobj; hobj = list->Next(hobj)) {
if (!channel->GroupSep() && channel->GetChannelID().ClrRid() == ChannelID) cChannel *channel = (cChannel *)hobj->Object();
if (channel->Sid() == sid && channel->GetChannelID().ClrRid() == ChannelID)
return channel; return channel;
} }
} }
if (TryWithoutPolarization) { if (TryWithoutPolarization) {
ChannelID.ClrPolarization(); ChannelID.ClrPolarization();
for (cChannel *channel = First(); channel; channel = Next(channel)) { for (cHashObject *hobj = list->First(); hobj; hobj = list->Next(hobj)) {
if (!channel->GroupSep() && channel->GetChannelID().ClrPolarization() == ChannelID) cChannel *channel = (cChannel *)hobj->Object();
if (channel->Sid() == sid && channel->GetChannelID().ClrPolarization() == ChannelID)
return channel; return channel;
} }
} }
}
return NULL; return NULL;
} }

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: channels.h 1.34 2005/09/04 10:17:12 kls Exp $ * $Id: channels.h 1.35 2005/09/11 11:17:19 kls Exp $
*/ */
#ifndef __CHANNELS_H #ifndef __CHANNELS_H
@ -72,6 +72,11 @@ public:
bool Valid(void) const { return (nid || tid) && sid; } // rid is optional and source may be 0//XXX source may not be 0??? bool Valid(void) const { return (nid || tid) && sid; } // rid is optional and source may be 0//XXX source may not be 0???
tChannelID &ClrRid(void) { rid = 0; return *this; } tChannelID &ClrRid(void) { rid = 0; return *this; }
tChannelID &ClrPolarization(void); tChannelID &ClrPolarization(void);
int Source(void) { return source; }
int Nid(void) { return nid; }
int Tid(void) { return tid; }
int Sid(void) { return sid; }
int Rid(void) { return rid; }
static tChannelID FromString(const char *s); static tChannelID FromString(const char *s);
cString ToString(void) const; cString ToString(void) const;
static const tChannelID InvalidID; static const tChannelID InvalidID;
@ -203,10 +208,13 @@ private:
int maxNumber; int maxNumber;
int modified; int modified;
int beingEdited; int beingEdited;
cHash<cChannel> channelsHashSid;
void DeleteDuplicateChannels(void); void DeleteDuplicateChannels(void);
public: public:
cChannels(void); cChannels(void);
bool Load(const char *FileName, bool AllowComments = false, bool MustExist = false); bool Load(const char *FileName, bool AllowComments = false, bool MustExist = false);
void HashChannel(cChannel *Channel);
void UnhashChannel(cChannel *Channel);
int GetNextGroup(int Idx); // Get next channel group int GetNextGroup(int Idx); // Get next channel group
int GetPrevGroup(int Idx); // Get previous channel group int GetPrevGroup(int Idx); // Get previous channel group
int GetNextNormal(int Idx); // Get next normal channel (not group) int GetNextNormal(int Idx); // Get next normal channel (not group)

6
epg.h
View File

@ -7,7 +7,7 @@
* Original version (as used in VDR before 1.3.0) written by * Original version (as used in VDR before 1.3.0) written by
* Robert Schneider <Robert.Schneider@web.de> and Rolf Hakenes <hakenes@hippomi.de>. * Robert Schneider <Robert.Schneider@web.de> and Rolf Hakenes <hakenes@hippomi.de>.
* *
* $Id: epg.h 1.25 2005/05/28 11:32:36 kls Exp $ * $Id: epg.h 1.26 2005/09/11 12:54:30 kls Exp $
*/ */
#ifndef __EPG_H #ifndef __EPG_H
@ -132,8 +132,8 @@ public:
void Cleanup(void); void Cleanup(void);
cEvent *AddEvent(cEvent *Event); cEvent *AddEvent(cEvent *Event);
void DelEvent(cEvent *Event); void DelEvent(cEvent *Event);
void cSchedule::HashEvent(cEvent *Event); void HashEvent(cEvent *Event);
void cSchedule::UnhashEvent(cEvent *Event); void UnhashEvent(cEvent *Event);
const cList<cEvent> *Events(void) const { return &events; } const cList<cEvent> *Events(void) const { return &events; }
const cEvent *GetPresentEvent(bool CheckRunningStatus = false) const; const cEvent *GetPresentEvent(bool CheckRunningStatus = false) const;
const cEvent *GetFollowingEvent(bool CheckRunningStatus = false) const; const cEvent *GetFollowingEvent(bool CheckRunningStatus = false) const;

13
tools.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: tools.c 1.97 2005/08/27 14:43:55 kls Exp $ * $Id: tools.c 1.98 2005/09/11 13:11:05 kls Exp $
*/ */
#include "tools.h" #include "tools.h"
@ -1080,8 +1080,7 @@ cHashBase::cHashBase(int Size)
cHashBase::~cHashBase(void) cHashBase::~cHashBase(void)
{ {
for (int i = 0; i < size; i++) Clear();
delete hashTable[i];
free(hashTable); free(hashTable);
} }
@ -1106,6 +1105,14 @@ void cHashBase::Del(cListObject *Object, unsigned int Id)
} }
} }
void cHashBase::Clear(void)
{
for (int i = 0; i < size; i++) {
delete hashTable[i];
hashTable[i] = NULL;
}
}
cListObject *cHashBase::Get(unsigned int Id) const cListObject *cHashBase::Get(unsigned int Id) const
{ {
cList<cHashObject> *list = hashTable[hashfn(Id)]; cList<cHashObject> *list = hashTable[hashfn(Id)];

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: tools.h 1.75 2005/08/27 14:40:08 kls Exp $ * $Id: tools.h 1.76 2005/09/11 13:04:03 kls Exp $
*/ */
#ifndef __TOOLS_H #ifndef __TOOLS_H
@ -259,6 +259,7 @@ private:
cListObject *object; cListObject *object;
public: public:
cHashObject(cListObject *Object, unsigned int Id) { object = Object; id = Id; } cHashObject(cListObject *Object, unsigned int Id) { object = Object; id = Id; }
cListObject *Object(void) { return object; }
}; };
class cHashBase { class cHashBase {
@ -272,6 +273,7 @@ public:
virtual ~cHashBase(); virtual ~cHashBase();
void Add(cListObject *Object, unsigned int Id); void Add(cListObject *Object, unsigned int Id);
void Del(cListObject *Object, unsigned int Id); void Del(cListObject *Object, unsigned int Id);
void Clear(void);
cListObject *Get(unsigned int Id) const; cListObject *Get(unsigned int Id) const;
cList<cHashObject> *GetList(unsigned int Id) const; cList<cHashObject> *GetList(unsigned int Id) const;
}; };