* ***********************************************************************/
void epg_init (void);
-void epg_save (void);
+void epg_save (void*);
void epg_updated (void);
/* ************************************************************************
extern epg_object_tree_t epg_seasons;
extern epg_object_tree_t epg_episodes;
extern epg_object_tree_t epg_serieslinks;
-static pthread_cond_t _epgdbsave_cond;
-static void* _epgdbsave_thread ( void *p );
-pthread_mutex_t epgdbsave_mutex;
/* **************************************************************************
* Load
}
}
-/*
- * Thread functions
- */
-static void *_epgdbsave_thread ( void *p )
-{
- struct timespec ts;
- ts.tv_nsec = 0;
- tvhlog(LOG_DEBUG, "epgdb", "epgdbsave setting: %i", epggrab_epgdb_periodicsave);
- while (1) {
- if (epggrab_epgdb_periodicsave != 0) {
- tvhlog(LOG_DEBUG, "epgdb", "epgdbsave setting: %i",
- epggrab_epgdb_periodicsave);
- epg_save();
- };
- pthread_mutex_lock(&epgdbsave_mutex);
- time(&ts.tv_sec);
- ts.tv_sec += epggrab_epgdb_periodicsave * 3600; /* User defined in hours */
- pthread_cond_timedwait(&_epgdbsave_cond, &epgdbsave_mutex, &ts);
- pthread_mutex_unlock(&epgdbsave_mutex);
- };
-return NULL;
-}
-
/*
* Load data
*/
/* Close file */
munmap(mem, st.st_size);
close(fd);
-
- /* Create thread */
- pthread_mutex_init(&epgdbsave_mutex, NULL);
- pthread_cond_init(&_epgdbsave_cond, NULL);
- /* Start thread */
- pthread_t tid;
- pthread_create(&tid, NULL, _epgdbsave_thread, NULL);
}
/* **************************************************************************
return _epg_write(fd, m);
}
-void epg_save ( void )
+void epg_save ( void *p )
{
int fd;
epg_object_t *eo;
epg_broadcast_t *ebc;
channel_t *ch;
epggrab_stats_t stats;
+ extern gtimer_t epggrab_save_timer;
+
+ if (epggrab_epgdb_periodicsave)
+ gtimer_arm(&epggrab_save_timer, epg_save, NULL, epggrab_epgdb_periodicsave);
fd = hts_settings_open_file(1, "epgdb.v%d", EPG_DB_VERSION);
#include "service.h"
/* Thread protection */
-static int epggrab_confver;
+static int epggrab_confver;
pthread_mutex_t epggrab_mutex;
-static pthread_cond_t epggrab_cond;
+static pthread_cond_t epggrab_cond;
/* Config */
uint32_t epggrab_interval;
uint32_t epggrab_channel_reicon;
uint32_t epggrab_epgdb_periodicsave;
+gtimer_t epggrab_save_timer;
+
/* **************************************************************************
* Internal Grab Thread
* *************************************************************************/
htsmsg_get_u32(m, "channel_renumber", &epggrab_channel_renumber);
htsmsg_get_u32(m, "channel_reicon", &epggrab_channel_reicon);
htsmsg_get_u32(m, "epgdb_periodicsave", &epggrab_epgdb_periodicsave);
+ if (epggrab_epgdb_periodicsave)
+ gtimer_arm(&epggrab_save_timer, epg_save, NULL,
+ epggrab_epgdb_periodicsave);
if (!htsmsg_get_u32(m, old ? "grab-interval" : "interval",
&epggrab_interval)) {
if (old) epggrab_interval *= 3600;
int save = 0;
if ( e != epggrab_epgdb_periodicsave ) {
epggrab_epgdb_periodicsave = e;
+ pthread_mutex_lock(&global_lock);
+ if (!e)
+ gtimer_disarm(&epggrab_save_timer);
+ else
+ epg_save(NULL); // will arm the timer
+ pthread_mutex_unlock(&global_lock);
save = 1;
}
return save;
*/
void epggrab_init ( void )
{
+ /* Defaults */
+ epggrab_interval = 0;
+ epggrab_module = NULL;
+ epggrab_channel_rename = 0;
+ epggrab_channel_renumber = 0;
+ epggrab_channel_reicon = 0;
+ epggrab_epgdb_periodicsave = 0;
+
/* Lists */
#if ENABLE_LINUXDVB
extern TAILQ_HEAD(, epggrab_ota_mux) ota_mux_all;
mainloop();
- epg_save();
+ // Note: the locking is obviously a bit redundant, but without
+ // we need to disable the gtimer_arm call in epg_save()
+ pthread_mutex_lock(&global_lock);
+ epg_save(NULL);
#if ENABLE_TIMESHIFT
timeshift_term();
#endif
+ pthread_mutex_unlock(&global_lock);
tvhlog(LOG_NOTICE, "STOP", "Exiting HTS Tvheadend");
htsmsg_add_u32(r, "channel_rename", epggrab_channel_rename);
htsmsg_add_u32(r, "channel_renumber", epggrab_channel_renumber);
htsmsg_add_u32(r, "channel_reicon", epggrab_channel_reicon);
- htsmsg_add_u32(r, "epgdb_periodicsave", epggrab_epgdb_periodicsave);
+ htsmsg_add_u32(r, "epgdb_periodicsave", epggrab_epgdb_periodicsave / 3600);
pthread_mutex_unlock(&epggrab_mutex);
out = json_single_record(r, "epggrabSettings");
str = http_arg_get(&hc->hc_req_args, "channel_reicon");
save |= epggrab_set_channel_reicon(str ? 1 : 0);
if ( (str = http_arg_get(&hc->hc_req_args, "epgdb_periodicsave")) )
- save |= epggrab_set_periodicsave(atoi(str));
+ save |= epggrab_set_periodicsave(atoi(str) * 3600);
if ( (str = http_arg_get(&hc->hc_req_args, "interval")) )
save |= epggrab_set_interval(atoi(str));
if ( (str = http_arg_get(&hc->hc_req_args, "module")) )
htsbuf_qprintf(hq, "<?xml version=\"1.0\"?>\n"
"<epgflush>1</epgflush>\n");
- epg_save();
+ pthread_mutex_lock(&global_lock);
+ epg_save(NULL);
+ pthread_mutex_unlock(&global_lock);
http_output_content(hc, "text/xml");