forked from external/yambar
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".
This commit is contained in:
parent
7f0f096ba4
commit
a3eb7ebc08
8 changed files with 35 additions and 1 deletions
17
bar.c
17
bar.c
|
@ -10,6 +10,8 @@
|
|||
#include <poll.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <sys/eventfd.h>
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_event.h>
|
||||
#include <xcb/randr.h>
|
||||
|
@ -383,10 +385,14 @@ run(struct bar_run_context *run_ctx)
|
|||
struct module_run_context run_ctx_center[bar->center.count];
|
||||
struct module_run_context run_ctx_right[bar->right.count];
|
||||
|
||||
int ready_fd = eventfd(0, EFD_SEMAPHORE);
|
||||
assert(ready_fd != -1);
|
||||
|
||||
for (size_t i = 0; i < bar->left.count; i++) {
|
||||
struct module_run_context *ctx = &run_ctx_left[i];
|
||||
|
||||
ctx->module = bar->left.mods[i];
|
||||
ctx->ready_fd = ready_fd;
|
||||
ctx->abort_fd = run_ctx->abort_fd;
|
||||
|
||||
thrd_create(&thrd_left[i], (int (*)(void *))bar->left.mods[i]->run, ctx);
|
||||
|
@ -395,6 +401,7 @@ run(struct bar_run_context *run_ctx)
|
|||
struct module_run_context *ctx = &run_ctx_center[i];
|
||||
|
||||
ctx->module = bar->center.mods[i];
|
||||
ctx->ready_fd = ready_fd;
|
||||
ctx->abort_fd = run_ctx->abort_fd;
|
||||
|
||||
thrd_create(&thrd_center[i], (int (*)(void *))bar->center.mods[i]->run, ctx);
|
||||
|
@ -403,12 +410,20 @@ run(struct bar_run_context *run_ctx)
|
|||
struct module_run_context *ctx = &run_ctx_right[i];
|
||||
|
||||
ctx->module = bar->right.mods[i];
|
||||
ctx->ready_fd = ready_fd;
|
||||
ctx->abort_fd = run_ctx->abort_fd;
|
||||
|
||||
thrd_create(&thrd_right[i], (int (*)(void *))bar->right.mods[i]->run, ctx);
|
||||
}
|
||||
|
||||
LOG_DBG("modules started");
|
||||
LOG_DBG("waiting for modules to become ready");
|
||||
for (size_t i = 0; i < bar->left.count + bar->center.count + bar->right.count; i++) {
|
||||
uint64_t b;
|
||||
read(ready_fd, &b, sizeof(b));
|
||||
}
|
||||
|
||||
close(ready_fd);
|
||||
LOG_DBG("all modules started");
|
||||
|
||||
int fd = xcb_get_file_descriptor(bar->conn);
|
||||
|
||||
|
|
1
module.h
1
module.h
|
@ -11,6 +11,7 @@ struct module;
|
|||
|
||||
struct module_run_context {
|
||||
struct module *module;
|
||||
int ready_fd;
|
||||
int abort_fd;
|
||||
};
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
|
@ -202,6 +203,8 @@ run(struct module_run_context *ctx)
|
|||
udev_monitor_filter_add_match_subsystem_devtype(mon, "power_supply", NULL);
|
||||
udev_monitor_enable_receiving(mon);
|
||||
|
||||
write(ctx->ready_fd, &(uint64_t){1}, sizeof(uint64_t));
|
||||
|
||||
bool first = true;
|
||||
while (true) {
|
||||
if (!first) {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include "clock.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <poll.h>
|
||||
|
@ -50,6 +52,8 @@ run(struct module_run_context *ctx)
|
|||
{
|
||||
const struct bar *bar = ctx->module->bar;
|
||||
|
||||
write(ctx->ready_fd, &(uint64_t){1}, sizeof(uint64_t));
|
||||
|
||||
while (true) {
|
||||
time_t now = time(NULL);
|
||||
time_t now_no_secs = now / 60 * 60;
|
||||
|
|
|
@ -287,6 +287,8 @@ run(struct module_run_context *ctx)
|
|||
send_pkg(sock, I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL);
|
||||
send_pkg(sock, I3_IPC_MESSAGE_TYPE_SUBSCRIBE, "[\"workspace\"]");
|
||||
|
||||
write(ctx->ready_fd, &(uint64_t){1}, sizeof(uint64_t));
|
||||
|
||||
char buf[1 * 1024 * 1024]; /* Some replies are *big*. TODO: grow dynamically */
|
||||
size_t buf_idx = 0;
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include "label.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <poll.h>
|
||||
|
@ -28,6 +30,7 @@ content(struct module *mod)
|
|||
static int
|
||||
run(struct module_run_context *ctx)
|
||||
{
|
||||
write(ctx->ready_fd, &(uint64_t){1}, sizeof(uint64_t));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
@ -437,6 +438,9 @@ run(struct module_run_context *ctx)
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* TODO: move this to later */
|
||||
write(ctx->ready_fd, &(uint64_t){1}, sizeof(uint64_t));
|
||||
|
||||
int ret = talk_to_xkb(ctx->abort_fd, ctx->module->bar, ctx->module->private, conn)
|
||||
? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
|
||||
|
|
|
@ -207,6 +207,8 @@ run(struct module_run_context *ctx)
|
|||
update_title(m);
|
||||
mod->bar->refresh(mod->bar);
|
||||
|
||||
write(ctx->ready_fd, &(uint64_t){1}, sizeof(uint64_t));
|
||||
|
||||
int xcb_fd = xcb_get_file_descriptor(m->conn);
|
||||
while (true) {
|
||||
struct pollfd fds[] = {{.fd = ctx->abort_fd, .events = POLLIN},
|
||||
|
|
Loading…
Add table
Reference in a new issue