Coverage Report

Created: 2026-12-01 07:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/bind9/lib/isc/include/isc/loop.h
Line
Count
Source
1
/*
2
 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3
 *
4
 * SPDX-License-Identifier: MPL-2.0
5
 *
6
 * This Source Code Form is subject to the terms of the Mozilla Public
7
 * License, v. 2.0. If a copy of the MPL was not distributed with this
8
 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
9
 *
10
 * See the COPYRIGHT file distributed with this work for additional
11
 * information regarding copyright ownership.
12
 */
13
14
#pragma once
15
16
#include <inttypes.h>
17
18
#include <isc/job.h>
19
#include <isc/mem.h>
20
#include <isc/refcount.h>
21
#include <isc/types.h>
22
#include <isc/urcu.h>
23
#include <isc/work.h>
24
25
typedef void (*isc_job_cb)(void *);
26
27
/* Add -DISC_LOOP_TRACE=1 to CFLAGS for detailed reference tracing */
28
29
/*%<
30
 * Returns the current running loop.
31
 */
32
33
extern thread_local isc_loop_t *isc__loop_local;
34
35
static inline isc_loop_t *
36
0
isc_loop(void) {
37
0
  return isc__loop_local;
38
0
}
Unexecuted instantiation: dns_qp.c:isc_loop
Unexecuted instantiation: qp.c:isc_loop
Unexecuted instantiation: lib.c:isc_loop
Unexecuted instantiation: qpzone.c:isc_loop
Unexecuted instantiation: rdata.c:isc_loop
Unexecuted instantiation: rdatavec.c:isc_loop
Unexecuted instantiation: zone.c:isc_loop
Unexecuted instantiation: zonefetch.c:isc_loop
Unexecuted instantiation: zonemgr.c:isc_loop
Unexecuted instantiation: zoneproperties.c:isc_loop
Unexecuted instantiation: zoneverify.c:isc_loop
Unexecuted instantiation: resolver.c:isc_loop
Unexecuted instantiation: xfrin.c:isc_loop
Unexecuted instantiation: adb.c:isc_loop
Unexecuted instantiation: catz.c:isc_loop
Unexecuted instantiation: db.c:isc_loop
Unexecuted instantiation: diff.c:isc_loop
Unexecuted instantiation: dispatch.c:isc_loop
Unexecuted instantiation: dlz.c:isc_loop
Unexecuted instantiation: dnssec.c:isc_loop
Unexecuted instantiation: dyndb.c:isc_loop
Unexecuted instantiation: forward.c:isc_loop
Unexecuted instantiation: journal.c:isc_loop
Unexecuted instantiation: keytable.c:isc_loop
Unexecuted instantiation: master.c:isc_loop
Unexecuted instantiation: masterdump.c:isc_loop
Unexecuted instantiation: message.c:isc_loop
Unexecuted instantiation: nametree.c:isc_loop
Unexecuted instantiation: ncache.c:isc_loop
Unexecuted instantiation: notify.c:isc_loop
Unexecuted instantiation: nsec.c:isc_loop
Unexecuted instantiation: nsec3.c:isc_loop
Unexecuted instantiation: private.c:isc_loop
Unexecuted instantiation: qpcache.c:isc_loop
Unexecuted instantiation: rdataslab.c:isc_loop
Unexecuted instantiation: request.c:isc_loop
Unexecuted instantiation: rpz.c:isc_loop
Unexecuted instantiation: rriterator.c:isc_loop
Unexecuted instantiation: ssu.c:isc_loop
Unexecuted instantiation: stats.c:isc_loop
Unexecuted instantiation: unreachcache.c:isc_loop
Unexecuted instantiation: update.c:isc_loop
Unexecuted instantiation: validator.c:isc_loop
Unexecuted instantiation: view.c:isc_loop
Unexecuted instantiation: zt.c:isc_loop
Unexecuted instantiation: deleg.c:isc_loop
Unexecuted instantiation: badcache.c:isc_loop
Unexecuted instantiation: cache.c:isc_loop
Unexecuted instantiation: nta.c:isc_loop
Unexecuted instantiation: rrl.c:isc_loop
Unexecuted instantiation: netmgr.c:isc_loop
Unexecuted instantiation: proxystream.c:isc_loop
Unexecuted instantiation: proxyudp.c:isc_loop
Unexecuted instantiation: socket.c:isc_loop
Unexecuted instantiation: streamdns.c:isc_loop
Unexecuted instantiation: tcp.c:isc_loop
Unexecuted instantiation: timer.c:isc_loop
Unexecuted instantiation: tlsstream.c:isc_loop
Unexecuted instantiation: udp.c:isc_loop
Unexecuted instantiation: job.c:isc_loop
Unexecuted instantiation: async.c:isc_loop
Unexecuted instantiation: loop.c:isc_loop
Unexecuted instantiation: ratelimiter.c:isc_loop
Unexecuted instantiation: signal.c:isc_loop
Unexecuted instantiation: work.c:isc_loop
Unexecuted instantiation: http.c:isc_loop
Unexecuted instantiation: dns_qpkey_name.c:isc_loop
Unexecuted instantiation: dns_master_load.c:isc_loop
Unexecuted instantiation: dns_message_checksig.c:isc_loop
39
40
void
41
isc_loopmgr_create(isc_mem_t *mctx, uint32_t nloops);
42
/*%<
43
 * Create a loop manager supporting 'nloops' loops.
44
 *
45
 * Requires:
46
 *\li 'nloops' is greater than 0.
47
 */
48
49
void
50
isc_loopmgr_destroy(void);
51
/*%<
52
 * Destroy the loop manager.
53
 */
54
55
void
56
isc_loopmgr_shutdown(void);
57
/*%<
58
 * Request shutdown of the loop manager.
59
 *
60
 * This will stop all signal handlers and send shutdown events to
61
 * all active loops. As a final action on shutting down, each loop
62
 * will run the function (or functions) set by isc_loopmgr_teardown()
63
 * or isc_loop_teardown().
64
 */
65
66
void
67
isc_loopmgr_run(void);
68
/*%<
69
 * Run the loops in loop manager. Each loop will start by running the
70
 * function (or functions) set by isc_loopmgr_setup() or isc_loop_setup().
71
 */
72
73
void
74
isc_loopmgr_pause(void);
75
/*%<
76
 * Send pause events to all running loops in loop manager except the
77
 * current one. This can only be called from a running loop.
78
 * All the paused loops will wait until isc_loopmgr_resume() is
79
 * run in the calling loop before continuing.
80
 *
81
 * Requires:
82
 *\li We are in a running loop.
83
 */
84
85
bool
86
isc_loopmgr_paused(void);
87
/*%<
88
 * Returns true if the loopmgr has been paused and not yet resumed.
89
 *
90
 * Requires:
91
 *\li We are in a running loop.
92
 */
93
94
void
95
isc_loopmgr_resume(void);
96
/*%<
97
 * Send resume events to all paused loops in loop manager. This can
98
 * only be called by a running loop (which must therefore be the
99
 * loop that called isc_loopmgr_pause()).
100
 *
101
 * Requires:
102
 *\li We are in a running loop.
103
 */
104
105
uint32_t
106
isc_loopmgr_nloops(void);
107
108
isc_job_t *
109
isc_loop_setup(isc_loop_t *loop, isc_job_cb cb, void *cbarg);
110
isc_job_t *
111
isc_loop_teardown(isc_loop_t *loop, isc_job_cb cb, void *cbarg);
112
/*%<
113
 * Schedule actions to be run when starting, and when shutting down,
114
 * one of the loops in a loop manager.
115
 *
116
 * Requires:
117
 *\li 'loop' is a valid loop.
118
 *\li The loop manager associated with 'loop' is paused or has not
119
 *  yet been started.
120
 */
121
122
void
123
isc_loopmgr_setup(isc_job_cb cb, void *cbarg);
124
void
125
isc_loopmgr_teardown(isc_job_cb cb, void *cbarg);
126
/*%<
127
 * Schedule actions to be run when starting, and when shutting down,
128
 * *all* of the loops in loopmgr.
129
 *
130
 * This is the same as running isc_loop_setup() or
131
 * isc_loop_teardown() on each of the loops in turn.
132
 *
133
 * Requires:
134
 *\li loopmgr is paused or has not yet been started.
135
 */
136
137
isc_mem_t *
138
isc_loop_getmctx(isc_loop_t *loop);
139
/*%<
140
 * Return a pointer to the a memory context that was created for
141
 * 'loop' when it was initialized.
142
 *
143
 * Requires:
144
 *\li 'loop' is a valid loop.
145
 */
146
147
isc_loop_t *
148
isc_loop_main(void);
149
/*%<
150
 * Returns the main loop for the loop manager (which is 'loops[0]',
151
 * regardless of how many loops there are).
152
 */
153
154
isc_loop_t *
155
isc_loop_get(isc_tid_t tid);
156
/*%<
157
 * Return the loop object associated with the 'tid' threadid
158
 *
159
 * Requires:
160
 *\li   'tid' is smaller than number of initialized loops
161
 */
162
163
#if ISC_LOOP_TRACE
164
#define isc_loop_ref(ptr)   isc_loop__ref(ptr, __func__, __FILE__, __LINE__)
165
#define isc_loop_unref(ptr) isc_loop__unref(ptr, __func__, __FILE__, __LINE__)
166
#define isc_loop_attach(ptr, ptrp) \
167
  isc_loop__attach(ptr, ptrp, __func__, __FILE__, __LINE__)
168
#define isc_loop_detach(ptrp) \
169
  isc_loop__detach(ptrp, __func__, __FILE__, __LINE__)
170
ISC_REFCOUNT_TRACE_DECL(isc_loop);
171
#else
172
ISC_REFCOUNT_DECL(isc_loop);
173
#endif
174
/*%<
175
 * Reference counting functions for isc_loop
176
 */
177
178
void
179
isc_loopmgr_blocking(void);
180
void
181
isc_loopmgr_nonblocking(void);
182
/*%<
183
 * isc_loopmgr_blocking() stops the SIGINT and SIGTERM signal handlers
184
 * during blocking operations, for example while waiting for user
185
 * interaction; isc_loopmgr_nonblocking() restarts them.
186
 *
187
 * Because of this, `isc_loopmgr_nonblocking()` also internally calls
188
 * `uv_update_time()` from the current loop which ensures that code running
189
 * after `_nonblocking()` call would have the updated current time. (It's
190
 * important, for instance, if there are network IO to avoid wrong timeout
191
 * detections.)
192
 */
193
194
isc_time_t
195
isc_loop_now(isc_loop_t *loop);
196
/*%<
197
 * Returns the start time of the current loop tick.
198
 *
199
 * Requires:
200
 *
201
 * \li 'loop' is a valid loop.
202
 */
203
204
bool
205
isc_loop_shuttingdown(isc_loop_t *loop);
206
/*%<
207
 * Returns whether the loop is shutting down.
208
 *
209
 * Requires:
210
 *
211
 * \li 'loop' is a valid loop and the loop tid matches the current tid.
212
 */