Introduce refcounts for events.

We'll need it for doing fast sorting and partial queries of the EPG 
database.
This commit is contained in:
Andreas Öman 2008-09-07 14:22:21 +00:00
parent f21f7e0a09
commit 7122c27598
3 changed files with 28 additions and 12 deletions

View file

@ -371,7 +371,7 @@ channel_delete(channel_t *ch)
s->ths_channel = NULL;
}
epg_destroy_by_channel(ch);
epg_unlink_from_channel(ch);
fprintf(stderr, "!!!!!//autorec_destroy_by_channel(ch);\n");

32
epg.c
View file

@ -21,6 +21,7 @@
#include <stdlib.h>
#include <string.h>
#include <regex.h>
#include <assert.h>
#include "tvhead.h"
#include "channels.h"
@ -133,6 +134,7 @@ epg_event_find_by_start(channel_t *ch, time_t start, int create)
e = skel;
skel = NULL;
e->e_refcount = 1;
e->e_channel = ch;
epg_event_changed(e);
}
@ -160,13 +162,9 @@ epg_event_find_by_time(channel_t *ch, time_t t)
/**
*
*/
void
static void
epg_event_destroy(event_t *e)
{
channel_t *ch = e->e_channel;
RB_REMOVE(&ch->ch_epg_events, e, e_channel_link);
if(e->e_content_type != NULL)
LIST_REMOVE(e, e_content_type_link);
@ -175,6 +173,21 @@ epg_event_destroy(event_t *e)
free(e);
}
/**
*
*/
static void
epg_event_unref(event_t *e)
{
if(e->e_refcount > 1) {
e->e_refcount--;
return;
}
assert(e->e_refcount == 1);
epg_event_destroy(e);
}
#if 0
/**
*
@ -225,12 +238,15 @@ epg_channel_maintain()
*
*/
void
epg_destroy_by_channel(channel_t *ch)
epg_unlink_from_channel(channel_t *ch)
{
event_t *e;
while((e = ch->ch_epg_events.root) != NULL)
epg_event_destroy(e);
while((e = ch->ch_epg_events.root) != NULL) {
RB_REMOVE(&ch->ch_epg_events, e, e_channel_link);
e->e_channel = NULL;
epg_event_unref(e);
}
}

6
epg.h
View file

@ -47,6 +47,8 @@ typedef struct event {
struct channel *e_channel;
RB_ENTRY(event) e_channel_link;
int e_refcount;
LIST_ENTRY(event) e_content_type_link;
epg_content_type_t *e_content_type;
@ -81,9 +83,7 @@ event_t *epg_event_find_by_start(channel_t *ch, time_t start, int create);
event_t *epg_event_find_by_time(channel_t *ch, time_t t);
void epg_event_destroy(event_t *e);
void epg_destroy_by_channel(channel_t *ch);
void epg_unlink_from_channel(channel_t *ch);
/**