X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fcore%2Fasync.c;fp=src%2Fcore%2Fsync.c;h=af527bea4ec62ff46c92ec0f0b547618f737cc09;hp=7e74b63071e4477fd6bcfb4bfcc892d1da3e002a;hb=f485606bf8957d2954cf6fa5b0aabd5c39db15c1;hpb=43638332c4236ac2db44b0524ea5ade4f918e602 diff --git a/src/core/sync.c b/src/core/async.c similarity index 87% rename from src/core/sync.c rename to src/core/async.c index 7e74b6307..af527bea4 100644 --- a/src/core/sync.c +++ b/src/core/async.c @@ -22,14 +22,10 @@ #include #include -#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); +}