X-Git-Url: https://git.wpitchoune.net/gitweb/?p=prss.git;a=blobdiff_plain;f=src%2Fttrss_cache.c;h=d13b534dd19cf0cc88bea4c5e001c5c8104d36f9;hp=1526e25ad437776bb8256631a8cbc909553f7080;hb=d278b66d10ef96b5af22cec6fb8c7d12be855b93;hpb=a3f79452df23ac3db9e7a827e16097322de377c0 diff --git a/src/ttrss_cache.c b/src/ttrss_cache.c index 1526e25..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() @@ -78,9 +80,12 @@ void cache_put(const struct headline *h, const char *content) char *path; 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);