forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
io_loop_with_timers.c
37 lines (33 loc) · 1.06 KB
/
io_loop_with_timers.c
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
#include "config.h"
#include <ccan/io/io.h>
#include <common/timeout.h>
#include <db/exec.h>
#include <lightningd/io_loop_with_timers.h>
#include <lightningd/lightningd.h>
void *io_loop_with_timers(struct lightningd *ld)
{
void *retval = NULL;
struct timer *expired;
while (!retval) {
/* ~ccan/io's io_loop() continuously calls
* io_poll_lightningd() for all file descriptors registered
* with it, then calls their callbacks or closes them if they
* fail, as appropriate.
*
* It will only exit if there's an expired timer, *or* someone
* calls io_break, or if there are no more file descriptors
* (which never happens in our code). */
retval = io_loop(ld->timers, &expired);
/*~ Notice that timers are called here in the event loop like
* anything else, so there are no weird concurrency issues. */
if (expired) {
/* This routine is legal in early startup, too. */
if (ld->wallet)
db_begin_transaction(ld->wallet->db);
timer_expired(expired);
if (ld->wallet)
db_commit_transaction(ld->wallet->db);
}
}
return retval;
}