summaryrefslogtreecommitdiffstats
path: root/src/mainloop-api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mainloop-api.c')
-rw-r--r--src/mainloop-api.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/mainloop-api.c b/src/mainloop-api.c
new file mode 100644
index 00000000..6caa0c25
--- /dev/null
+++ b/src/mainloop-api.c
@@ -0,0 +1,35 @@
+#include <assert.h>
+#include <stdlib.h>
+#include "mainloop-api.h"
+
+struct once_info {
+ void (*callback)(void *userdata);
+ void *userdata;
+};
+
+static void once_callback(struct pa_mainloop_api *api, void *id, void *userdata) {
+ struct once_info *i = userdata;
+ assert(api && i && i->callback);
+ i->callback(i->userdata);
+ assert(api->cancel_fixed);
+ api->cancel_fixed(api, id);
+ free(i);
+}
+
+void pa_mainloop_api_once(struct pa_mainloop_api* api, void (*callback)(void *userdata), void *userdata) {
+ struct once_info *i;
+ void *id;
+ assert(api && callback);
+
+ i = malloc(sizeof(struct once_info));
+ assert(i);
+ i->callback = callback;
+ i->userdata = userdata;
+
+ assert(api->source_fixed);
+ id = api->source_fixed(api, once_callback, i);
+ assert(id);
+
+ /* Note: if the mainloop is destroyed before once_callback() was called, some memory is leaked. */
+}
+