summaryrefslogtreecommitdiff
path: root/sysdep/unix/io-loop.h
blob: c531d43efc0e723671c3fa689320827c8d3ac4fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 *	BIRD -- I/O and event loop
 *
 *	Can be freely distributed and used under the terms of the GNU GPL.
 */

#ifndef _BIRD_SYSDEP_UNIX_IO_LOOP_H_
#define _BIRD_SYSDEP_UNIX_IO_LOOP_H_

#include "lib/rcu.h"

#include <pthread.h>

struct pipe
{
  int fd[2];
};

struct pfd {
  BUFFER(struct pollfd) pfd;
  BUFFER(struct birdloop *) loop;
};

void sockets_prepare(struct birdloop *, struct pfd *);
void socket_changed(struct birdsock *);

void pipe_new(struct pipe *);
void pipe_pollin(struct pipe *, struct pfd *);
void pipe_drain(struct pipe *);
void pipe_kick(struct pipe *);

struct birdloop
{
  node n;

  event event;
  timer timer;

  pool *pool;

  struct timeloop time;
  event_list event_list;
  list sock_list;
  struct birdsock *sock_active;
  int sock_num;
  uint sock_changed;

  uint ping_pending;

  _Atomic u32 thread_transition;
#define LTT_PING  1
#define LTT_MOVE  2
  _Atomic u32 flags;
  struct birdloop_flag_handler *flag_handler;

  void (*stopped)(void *data);
  void *stop_data;

  struct birdloop *prev_loop;

  struct bird_thread *thread;

  u64 total_time_spent_ns;
};

struct bird_thread
{
  node n;

  struct pipe wakeup;
  event_list priority_events;

  struct birdloop *meta;

  pthread_t thread_id;
  pthread_attr_t thread_attr;

  struct rcu_thread rcu;

  list loops;
  pool *pool;
  struct pfd *pfd;

  event cleanup_event;

  int sock_changed;
  uint loop_count;

  u64 max_latency_ns;
  u64 max_loop_time_ns;
};

#endif