yambar/modules/label/label.c
Daniel Eklöf a3eb7ebc08 bar: wait for all modules to have started up before continuing
After starting all the module threads, wait for all modules to have
signalled "ready" before continuing.

This will allow modules to do initial setup, and knowing that
content() will *not* be called until they've signalled "ready".
2018-12-19 19:41:25 +01:00

49 lines
897 B
C

#include "label.h"
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <assert.h>
#include <poll.h>
struct private {
struct particle *label;
};
static void
destroy(struct module *mod)
{
struct private *m = mod->private;
m->label->destroy(m->label);
free(m);
module_default_destroy(mod);
}
static struct exposable *
content(struct module *mod)
{
const struct private *m = mod->private;
return m->label->instantiate(m->label, NULL);
}
static int
run(struct module_run_context *ctx)
{
write(ctx->ready_fd, &(uint64_t){1}, sizeof(uint64_t));
return 0;
}
struct module *
module_label(struct particle *label)
{
struct private *m = malloc(sizeof(*m));
m->label = label;
struct module *mod = module_common_new();
mod->private = m;
mod->run = &run;
mod->destroy = &destroy;
mod->content = &content;
return mod;
}