chiark / gitweb /
Make tmpdir removal asynchronous
[elogind.git] / src / core / async.c
similarity index 87%
rename from src/core/sync.c
rename to src/core/async.c
index 7e74b63071e4477fd6bcfb4bfcc892d1da3e002a..af527bea4ec62ff46c92ec0f0b547618f737cc09 100644 (file)
 #include <pthread.h>
 #include <unistd.h>
 
-#include "sync.h"
+#include "async.h"
+#include "log.h"
 
-static void *sync_thread(void *p) {
-        sync();
-        return NULL;
-}
-
-int asynchronous_sync(void) {
+int asynchronous_job(void* (*func)(void *p), void *arg) {
         pthread_attr_t a;
         pthread_t t;
         int r;
@@ -53,7 +49,7 @@ int asynchronous_sync(void) {
                 goto finish;
         }
 
-        r = pthread_create(&t, &a, sync_thread, NULL);
+        r = pthread_create(&t, &a, func, arg);
         if (r != 0) {
                 r = -r;
                 goto finish;
@@ -63,3 +59,14 @@ finish:
         pthread_attr_destroy(&a);
         return r;
 }
+
+static void *sync_thread(void *p) {
+        sync();
+        return NULL;
+}
+
+int asynchronous_sync(void) {
+        log_debug("Spawning new thread for sync");
+
+        return asynchronous_job(sync_thread, NULL);
+}