X-Git-Url: https://git.wpitchoune.net/gitweb/?p=prss.git;a=blobdiff_plain;f=src%2Fttrss_cache.c;h=d13b534dd19cf0cc88bea4c5e001c5c8104d36f9;hp=be5b1199b3cdcb40ca5dcef1ccf7270564fd269a;hb=09bcceb88ae4a548c573098fc35a884fe0cc96ad;hpb=be5c3215b84a3637eca78aa271890ab5e1423908 diff --git a/src/ttrss_cache.c b/src/ttrss_cache.c index be5b119..d13b534 100644 --- a/src/ttrss_cache.c +++ b/src/ttrss_cache.c @@ -25,11 +25,13 @@ #include #include +#include #include "io.h" #include "log.h" #include "ttrss_cache.h" +static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; static char *cache_dir; static const char *get_cache_dir() @@ -79,8 +81,11 @@ void cache_put(const struct headline *h, const char *content) path = content_get_path(h); - if (path) + if (path) { + pthread_mutex_lock(&lock); file_set_content(path, content); + pthread_mutex_unlock(&lock); + } g_free(path); } @@ -93,10 +98,12 @@ int cache_exists(const struct headline *h) path = content_get_path(h); + pthread_mutex_lock(&lock); if (stat(path, &s) == -1) result = 0; else result = 1; + pthread_mutex_unlock(&lock); g_free(path); @@ -107,11 +114,15 @@ char *cache_get(const struct headline *h) { char *content, *path; + path = content_get_path(h); - if (path) + if (path) { + pthread_mutex_lock(&lock); content = file_get_content(path); - else + pthread_mutex_unlock(&lock); + } else { content = NULL; + } g_free(path);