/*
* Icon file server operations
* Copyright (C) 2012 Andy Brown
+ * (C) 2015-2018 Jaroslav Kysela
+ *
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
static int imagecache_id;
static RB_HEAD(,imagecache_image) imagecache_by_id;
static RB_HEAD(,imagecache_image) imagecache_by_url;
+static tvh_cond_t imagecache_cond;
+static TAILQ_HEAD(, imagecache_image) imagecache_queue;
SKEL_DECLARE(imagecache_skel, imagecache_image_t);
#if ENABLE_IMAGECACHE
}
};
-static tvh_cond_t imagecache_cond;
-static TAILQ_HEAD(, imagecache_image) imagecache_queue;
static mtimer_t imagecache_timer;
#endif
return res;
};
+static void
+imagecache_timer_cb ( void *p )
+{
+ time_t now = gclk(), when;
+ imagecache_image_t *img, *img_next;
+ for (img = RB_FIRST(&imagecache_by_url); img; img = img_next) {
+ img_next = RB_NEXT(img, url_link);
+ if (imagecache_conf.expire > 0 && img->accessed > 0) {
+ when = img->accessed + imagecache_conf.expire * 24 * 3600;
+ if (when < now) {
+ tvhdebug(LS_IMAGECACHE, "expired: %s", img->url);
+ imagecache_destroy(img, 1);
+ }
+ }
+ if (img->state != IDLE) continue;
+ when = img->failed ? imagecache_conf.fail_period
+ : imagecache_conf.ok_period;
+ when = img->updated + (when * 3600);
+ if (when < now)
+ imagecache_image_add(img);
+ }
+}
+
+#endif /* ENABLE_IMAGECACHE */
+
static void *
imagecache_thread ( void *p )
{
htsmsg_destroy(m);
tvh_mutex_lock(&global_lock);
+#if ENABLE_IMAGECACHE
} else if (img->state == QUEUED) {
/* Process */
img->state = FETCHING;
/* Fetch */
(void)imagecache_image_fetch(img);
+#endif
}
}
tvh_mutex_unlock(&global_lock);
return NULL;
}
-static void
-imagecache_timer_cb ( void *p )
-{
- time_t now = gclk(), when;
- imagecache_image_t *img, *img_next;
- for (img = RB_FIRST(&imagecache_by_url); img; img = img_next) {
- img_next = RB_NEXT(img, url_link);
- if (imagecache_conf.expire > 0 && img->accessed > 0) {
- when = img->accessed + imagecache_conf.expire * 24 * 3600;
- if (when < now) {
- tvhdebug(LS_IMAGECACHE, "expired: %s", img->url);
- imagecache_destroy(img, 1);
- }
- }
- if (img->state != IDLE) continue;
- when = img->failed ? imagecache_conf.fail_period
- : imagecache_conf.ok_period;
- when = img->updated + (when * 3600);
- if (when < now)
- imagecache_image_add(img);
- }
-}
-
-#endif /* ENABLE_IMAGECACHE */
-
/*
* Initialise
*/
-#if ENABLE_IMAGECACHE
pthread_t imagecache_tid;
-#endif
void
imagecache_init ( void )
}
/* Start threads */
-#if ENABLE_IMAGECACHE
tvh_thread_create(&imagecache_tid, NULL, imagecache_thread, NULL, "imagecache");
+#if ENABLE_IMAGECACHE
/* Re-try timer */
// TODO: this could be more efficient by being targetted, however
// the reality its not necessary and I'd prefer to avoid dumping
#if ENABLE_IMAGECACHE
mtimer_disarm(&imagecache_timer);
+#endif
tvh_cond_signal(&imagecache_cond, 1);
pthread_join(imagecache_tid, NULL);
-#endif
while ((img = RB_FIRST(&imagecache_by_id)) != NULL) {
if (img->state == SAVE) {
htsmsg_t *m = imagecache_image_htsmsg(img);
lock_assert(&global_lock);
-#if ENABLE_IMAGECACHE
/* remove all cached data, except the one actually fetched */
for (img = RB_FIRST(&imagecache_by_id); img; img = next) {
next = RB_NEXT(img, id_link);
continue;
imagecache_destroy(img, 1);
}
-#endif
tvhinfo(LS_IMAGECACHE, "clean request");
/* remove unassociated data */