Some initial work on logging gathering data into cloud log segments.
[bluesky.git] / bluesky / cache.c
index 72c181a..6a91873 100644 (file)
@@ -270,6 +270,7 @@ static gpointer flushd_task(BlueSkyFS *fs)
         return NULL;
     flushd_dirty(fs);
     flushd_clean(fs);
+    bluesky_cloudlog_write_log(fs);
     g_mutex_unlock(fs->flushd_lock);
 
     return NULL;
@@ -295,3 +296,22 @@ void bluesky_flushd_invoke_conditional(BlueSkyFS *fs)
 
     bluesky_flushd_invoke(fs);
 }
+
+/* Start a perpetually-running thread that flushes the cache occasionally. */
+static gpointer flushd_thread(BlueSkyFS *fs)
+{
+    while (TRUE) {
+        bluesky_flushd_invoke(fs);
+        struct timespec delay;
+        delay.tv_sec = 2;
+        delay.tv_nsec = 0;
+        nanosleep(&delay, NULL);
+    }
+
+    return NULL;
+}
+
+void bluesky_flushd_thread_launch(BlueSkyFS *fs)
+{
+    g_thread_create((GThreadFunc)flushd_thread, fs, FALSE, NULL);
+}