2013-09-16 21:57:40 +00:00
|
|
|
/*
|
|
|
|
* BIRD -- I/O and event loop
|
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
2013-09-10 10:09:36 +00:00
|
|
|
|
2021-06-19 18:50:18 +00:00
|
|
|
#ifndef _BIRD_SYSDEP_UNIX_IO_LOOP_H_
|
|
|
|
#define _BIRD_SYSDEP_UNIX_IO_LOOP_H_
|
2013-09-10 10:09:36 +00:00
|
|
|
|
2021-11-12 21:58:40 +00:00
|
|
|
#include "lib/rcu.h"
|
|
|
|
|
2023-01-21 22:42:02 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
|
2022-09-20 15:01:50 +00:00
|
|
|
struct pipe
|
|
|
|
{
|
|
|
|
int fd[2];
|
|
|
|
};
|
|
|
|
|
2023-02-24 08:13:35 +00:00
|
|
|
struct pfd {
|
|
|
|
BUFFER(struct pollfd) pfd;
|
|
|
|
BUFFER(struct birdloop *) loop;
|
|
|
|
};
|
|
|
|
|
|
|
|
void sockets_prepare(struct birdloop *, struct pfd *);
|
2023-04-02 17:15:22 +00:00
|
|
|
void socket_changed(struct birdsock *);
|
2023-02-24 08:13:35 +00:00
|
|
|
|
2022-09-20 15:01:50 +00:00
|
|
|
void pipe_new(struct pipe *);
|
2023-02-24 08:13:35 +00:00
|
|
|
void pipe_pollin(struct pipe *, struct pfd *);
|
2022-09-20 15:01:50 +00:00
|
|
|
void pipe_drain(struct pipe *);
|
|
|
|
void pipe_kick(struct pipe *);
|
|
|
|
|
2021-06-19 18:50:18 +00:00
|
|
|
struct birdloop
|
|
|
|
{
|
2023-01-19 09:49:47 +00:00
|
|
|
node n;
|
|
|
|
|
2023-02-24 08:13:35 +00:00
|
|
|
event event;
|
|
|
|
timer timer;
|
|
|
|
|
2021-06-19 18:50:18 +00:00
|
|
|
pool *pool;
|
2013-09-16 21:57:40 +00:00
|
|
|
|
2021-06-19 18:50:18 +00:00
|
|
|
struct timeloop time;
|
|
|
|
event_list event_list;
|
|
|
|
list sock_list;
|
2023-04-02 17:15:22 +00:00
|
|
|
struct birdsock *sock_active;
|
2023-01-19 09:49:47 +00:00
|
|
|
int sock_num;
|
2023-04-02 17:15:22 +00:00
|
|
|
uint sock_changed;
|
2013-09-10 10:09:36 +00:00
|
|
|
|
2022-07-28 17:49:03 +00:00
|
|
|
uint ping_pending;
|
2021-11-12 21:58:40 +00:00
|
|
|
|
2023-02-24 08:13:35 +00:00
|
|
|
_Atomic u32 thread_transition;
|
|
|
|
#define LTT_PING 1
|
|
|
|
#define LTT_MOVE 2
|
2022-09-12 08:24:55 +00:00
|
|
|
_Atomic u32 flags;
|
|
|
|
struct birdloop_flag_handler *flag_handler;
|
|
|
|
|
2021-06-19 18:50:18 +00:00
|
|
|
void (*stopped)(void *data);
|
|
|
|
void *stop_data;
|
2013-09-16 21:57:40 +00:00
|
|
|
|
2021-06-19 18:50:18 +00:00
|
|
|
struct birdloop *prev_loop;
|
2023-01-19 09:49:47 +00:00
|
|
|
|
|
|
|
struct bird_thread *thread;
|
|
|
|
|
|
|
|
u64 total_time_spent_ns;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct bird_thread
|
|
|
|
{
|
|
|
|
node n;
|
|
|
|
|
|
|
|
struct pipe wakeup;
|
|
|
|
event_list priority_events;
|
|
|
|
|
2023-02-24 08:13:35 +00:00
|
|
|
struct birdloop *meta;
|
|
|
|
|
2023-01-19 09:49:47 +00:00
|
|
|
pthread_t thread_id;
|
|
|
|
pthread_attr_t thread_attr;
|
|
|
|
|
|
|
|
struct rcu_thread rcu;
|
|
|
|
|
|
|
|
list loops;
|
|
|
|
pool *pool;
|
2023-02-24 08:13:35 +00:00
|
|
|
struct pfd *pfd;
|
2023-01-19 09:49:47 +00:00
|
|
|
|
|
|
|
event cleanup_event;
|
2023-04-02 17:15:22 +00:00
|
|
|
|
|
|
|
int sock_changed;
|
2023-04-06 18:18:04 +00:00
|
|
|
uint loop_count;
|
|
|
|
|
|
|
|
u64 max_latency_ns;
|
|
|
|
u64 max_loop_time_ns;
|
2021-06-19 18:50:18 +00:00
|
|
|
};
|
2013-09-10 10:09:36 +00:00
|
|
|
|
2021-06-19 18:50:18 +00:00
|
|
|
#endif
|