forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio_lock.h
55 lines (46 loc) · 1.62 KB
/
io_lock.h
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
#ifndef LIGHTNING_COMMON_IO_LOCK_H
#define LIGHTNING_COMMON_IO_LOCK_H
#include "config.h"
#include <ccan/io/io.h>
#include <ccan/tal/tal.h>
struct io_lock;
/**
* Create a new lock
*/
struct io_lock *io_lock_new(const tal_t *ctx);
/**
* Acquire lock @lock before proceeding to @next
*
* Attempts to acquire the lock before proceeding with next. If the
* lock is free this reduces to `io_always`, otherwise we put @conn in
* wait until we get notified about the lock being released.
*/
#define io_lock_acquire_out(conn, lock, next, arg) \
io_lock_acquire_out_((conn), (lock), \
typesafe_cb_preargs(struct io_plan *, void *, \
(next), (arg), \
struct io_conn *), \
(arg))
struct io_plan *io_lock_acquire_out_(struct io_conn *conn, struct io_lock *lock,
struct io_plan *(*next)(struct io_conn *,
void *),
void *arg);
#define io_lock_acquire_in(conn, lock, next, arg) \
io_lock_acquire_in_((conn), (lock), \
typesafe_cb_preargs(struct io_plan *, void *, \
(next), (arg), \
struct io_conn *), \
(arg))
struct io_plan *io_lock_acquire_in_(struct io_conn *conn, struct io_lock *lock,
struct io_plan *(*next)(struct io_conn *,
void *),
void *arg);
/**
* Release the lock and notify waiters so they can proceed.
*/
void io_lock_release(struct io_lock *lock);
/**
* Is this lock acquired?
*/
bool io_lock_taken(const struct io_lock *lock);
#endif /* LIGHTNING_COMMON_IO_LOCK_H */