(no commit message)
[prss.git] / src / ttrss_cache.c
index be5b119..d13b534 100644 (file)
 #include <unistd.h>
 
 #include <glib.h>
+#include <pthread.h>
 
 #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);