2021-06-19 18:50:18 +00:00
|
|
|
/*
|
|
|
|
* BIRD -- I/O and event loop
|
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _BIRD_IO_LOOP_H_
|
|
|
|
#define _BIRD_IO_LOOP_H_
|
|
|
|
|
2024-08-29 08:10:37 +00:00
|
|
|
extern struct birdloop main_birdloop;
|
|
|
|
|
2021-06-19 18:50:18 +00:00
|
|
|
#include "nest/bird.h"
|
|
|
|
#include "lib/lists.h"
|
|
|
|
#include "lib/locking.h"
|
|
|
|
#include "lib/resource.h"
|
2024-08-29 08:10:37 +00:00
|
|
|
#include "lib/buffer.h"
|
2021-06-19 18:50:18 +00:00
|
|
|
#include "lib/event.h"
|
2024-08-29 08:10:37 +00:00
|
|
|
#include "lib/timer.h"
|
2021-06-19 18:50:18 +00:00
|
|
|
#include "lib/socket.h"
|
|
|
|
|
2024-04-03 10:05:02 +00:00
|
|
|
/* Currently running birdloop */
|
|
|
|
extern _Thread_local struct birdloop *this_birdloop;
|
|
|
|
|
2024-06-27 06:37:05 +00:00
|
|
|
/* Lowest entered birdloop */
|
|
|
|
extern _Thread_local struct birdloop *birdloop_current;
|
|
|
|
|
2024-04-03 10:05:02 +00:00
|
|
|
/* Check that the task has enough time to do a bit more */
|
2024-06-26 15:19:24 +00:00
|
|
|
bool task_still_in_limit(void);
|
|
|
|
bool task_before_halftime(void);
|
2024-04-03 10:05:02 +00:00
|
|
|
|
2024-06-03 09:12:20 +00:00
|
|
|
#define MAYBE_DEFER_TASK(target, event, fmt, args...) do { \
|
|
|
|
if (!task_still_in_limit()) { \
|
2024-06-13 14:30:51 +00:00
|
|
|
if (atomic_load_explicit(&global_runtime, memory_order_relaxed)->latency_debug & DL_SCHEDULING) \
|
2024-06-03 09:12:20 +00:00
|
|
|
log(L_TRACE "Deferring " fmt, ##args); \
|
|
|
|
return ev_send(target, event); \
|
|
|
|
} } while (0)
|
|
|
|
|
2021-06-19 18:50:18 +00:00
|
|
|
/* Start a new birdloop owned by given pool and domain */
|
2023-04-22 19:20:19 +00:00
|
|
|
struct birdloop *birdloop_new(pool *p, uint order, btime max_latency, const char *fmt, ...);
|
2021-06-19 18:50:18 +00:00
|
|
|
|
|
|
|
/* Stop the loop. At the end, the @stopped callback is called unlocked in tail
|
|
|
|
* position to finish cleanup. Run birdloop_free() from that callback to free
|
|
|
|
* the loop itself. */
|
|
|
|
void birdloop_stop(struct birdloop *loop, void (*stopped)(void *data), void *data);
|
|
|
|
void birdloop_stop_self(struct birdloop *loop, void (*stopped)(void *data), void *data);
|
|
|
|
void birdloop_free(struct birdloop *loop);
|
|
|
|
|
2024-06-27 06:37:05 +00:00
|
|
|
/* Run this event in the running loop's priority event list to run asap */
|
|
|
|
void ev_send_defer(event *e);
|
2024-04-05 12:11:38 +00:00
|
|
|
|
2021-06-19 18:50:18 +00:00
|
|
|
/* Get birdloop's time heap */
|
|
|
|
struct timeloop *birdloop_time_loop(struct birdloop *loop);
|
2023-04-21 13:26:06 +00:00
|
|
|
#define birdloop_domain(l) (birdloop_time_loop((l))->domain)
|
2021-06-19 18:50:18 +00:00
|
|
|
|
2023-04-22 19:20:19 +00:00
|
|
|
/* Get birdloop's pool */
|
|
|
|
pool *birdloop_pool(struct birdloop *loop);
|
|
|
|
|
2021-06-19 18:50:18 +00:00
|
|
|
/* Enter and exit the birdloop */
|
|
|
|
void birdloop_enter(struct birdloop *loop);
|
|
|
|
void birdloop_leave(struct birdloop *loop);
|
|
|
|
|
2024-06-26 15:19:24 +00:00
|
|
|
bool birdloop_inside(struct birdloop *loop);
|
2021-06-19 18:50:18 +00:00
|
|
|
|
|
|
|
void birdloop_mask_wakeups(struct birdloop *loop);
|
|
|
|
void birdloop_unmask_wakeups(struct birdloop *loop);
|
|
|
|
|
|
|
|
void birdloop_link(struct birdloop *loop);
|
|
|
|
void birdloop_unlink(struct birdloop *loop);
|
|
|
|
|
|
|
|
void birdloop_ping(struct birdloop *loop);
|
|
|
|
|
2023-04-02 17:15:22 +00:00
|
|
|
/* Setup sockets */
|
|
|
|
void birdloop_add_socket(struct birdloop *, struct birdsock *);
|
|
|
|
void birdloop_remove_socket(struct birdloop *, struct birdsock *);
|
|
|
|
|
2024-09-03 10:24:27 +00:00
|
|
|
/* Initializations */
|
2021-06-19 18:50:18 +00:00
|
|
|
void birdloop_init(void);
|
2021-11-12 21:58:40 +00:00
|
|
|
|
2024-09-03 10:24:27 +00:00
|
|
|
struct thread_config {
|
|
|
|
uint count;
|
|
|
|
};
|
|
|
|
|
|
|
|
void bird_thread_commit(struct thread_config *new);
|
|
|
|
|
2024-09-10 09:25:59 +00:00
|
|
|
/* Minimalist main */
|
|
|
|
void birdloop_minimalist_main(void) NORET;
|
2024-09-03 10:24:27 +00:00
|
|
|
|
2021-06-19 18:50:18 +00:00
|
|
|
#endif /* _BIRD_IO_LOOP_H_ */
|