2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 22:45:39 +00:00

apply the modified style

This commit is contained in:
Evan Hunt
2020-02-13 14:44:37 -08:00
parent 0255a97473
commit e851ed0bb5
669 changed files with 35995 additions and 42219 deletions

View File

@@ -111,34 +111,26 @@ static const isc_statscounter_t unixstatsindex[] = {
ISC_THREAD_LOCAL int isc__nm_tid_v = ISC_NETMGR_TID_UNKNOWN;
static void
nmsocket_maybe_destroy(isc_nmsocket_t *sock);
static void
nmhandle_free(isc_nmsocket_t *sock, isc_nmhandle_t *handle);
static isc_threadresult_t
nm_thread(isc_threadarg_t worker0);
static void
async_cb(uv_async_t *handle);
static void
process_queue(isc__networker_t *worker, isc_queue_t *queue);
static void nmsocket_maybe_destroy(isc_nmsocket_t *sock);
static void nmhandle_free(isc_nmsocket_t *sock, isc_nmhandle_t *handle);
static isc_threadresult_t nm_thread(isc_threadarg_t worker0);
static void async_cb(uv_async_t *handle);
static void process_queue(isc__networker_t *worker, isc_queue_t *queue);
int
isc_nm_tid()
{
isc_nm_tid() {
return (isc__nm_tid_v);
}
bool
isc__nm_in_netthread()
{
isc__nm_in_netthread() {
return (isc__nm_tid_v >= 0);
}
isc_nm_t *
isc_nm_start(isc_mem_t *mctx, uint32_t workers)
{
isc_nm_start(isc_mem_t *mctx, uint32_t workers) {
isc_nm_t *mgr = NULL;
char name[32];
char name[32];
mgr = isc_mem_get(mctx, sizeof(*mgr));
*mgr = (isc_nm_t){ .nworkers = workers };
@@ -179,7 +171,7 @@ isc_nm_start(isc_mem_t *mctx, uint32_t workers)
mgr->workers = isc_mem_get(mctx, workers * sizeof(isc__networker_t));
for (size_t i = 0; i < workers; i++) {
int r;
int r;
isc__networker_t *worker = &mgr->workers[i];
*worker = (isc__networker_t){
.mgr = mgr,
@@ -221,8 +213,7 @@ isc_nm_start(isc_mem_t *mctx, uint32_t workers)
* Free the resources of the network manager.
*/
static void
nm_destroy(isc_nm_t **mgr0)
{
nm_destroy(isc_nm_t **mgr0) {
REQUIRE(VALID_NM(*mgr0));
REQUIRE(!isc__nm_in_netthread());
@@ -252,16 +243,18 @@ nm_destroy(isc_nm_t **mgr0)
for (size_t i = 0; i < mgr->nworkers; i++) {
isc__networker_t *worker = &mgr->workers[i];
isc__netievent_t *ievent = NULL;
int r;
int r;
/* Empty the async event queues */
while ((ievent = (isc__netievent_t *)isc_queue_dequeue(
worker->ievents)) != NULL) {
worker->ievents)) != NULL)
{
isc_mempool_put(mgr->evpool, ievent);
}
while ((ievent = (isc__netievent_t *)isc_queue_dequeue(
worker->ievents_prio)) != NULL) {
worker->ievents_prio)) != NULL)
{
isc_mempool_put(mgr->evpool, ievent);
}
@@ -292,8 +285,7 @@ nm_destroy(isc_nm_t **mgr0)
}
void
isc_nm_pause(isc_nm_t *mgr)
{
isc_nm_pause(isc_nm_t *mgr) {
REQUIRE(VALID_NM(mgr));
REQUIRE(!isc__nm_in_netthread());
@@ -317,15 +309,15 @@ isc_nm_pause(isc_nm_t *mgr)
LOCK(&mgr->lock);
while (atomic_load_relaxed(&mgr->workers_paused) !=
atomic_load_relaxed(&mgr->workers_running)) {
atomic_load_relaxed(&mgr->workers_running))
{
WAIT(&mgr->wkstatecond, &mgr->lock);
}
UNLOCK(&mgr->lock);
}
void
isc_nm_resume(isc_nm_t *mgr)
{
isc_nm_resume(isc_nm_t *mgr) {
REQUIRE(VALID_NM(mgr));
REQUIRE(!isc__nm_in_netthread());
@@ -344,8 +336,7 @@ isc_nm_resume(isc_nm_t *mgr)
}
void
isc_nm_attach(isc_nm_t *mgr, isc_nm_t **dst)
{
isc_nm_attach(isc_nm_t *mgr, isc_nm_t **dst) {
REQUIRE(VALID_NM(mgr));
REQUIRE(dst != NULL && *dst == NULL);
@@ -355,8 +346,7 @@ isc_nm_attach(isc_nm_t *mgr, isc_nm_t **dst)
}
void
isc_nm_detach(isc_nm_t **mgr0)
{
isc_nm_detach(isc_nm_t **mgr0) {
isc_nm_t *mgr = NULL;
REQUIRE(mgr0 != NULL);
@@ -371,8 +361,7 @@ isc_nm_detach(isc_nm_t **mgr0)
}
void
isc_nm_closedown(isc_nm_t *mgr)
{
isc_nm_closedown(isc_nm_t *mgr) {
REQUIRE(VALID_NM(mgr));
atomic_store(&mgr->closing, true);
@@ -384,8 +373,7 @@ isc_nm_closedown(isc_nm_t *mgr)
}
void
isc_nm_destroy(isc_nm_t **mgr0)
{
isc_nm_destroy(isc_nm_t **mgr0) {
isc_nm_t *mgr = NULL;
REQUIRE(mgr0 != NULL);
@@ -424,8 +412,7 @@ isc_nm_destroy(isc_nm_t **mgr0)
}
void
isc_nm_maxudp(isc_nm_t *mgr, uint32_t maxudp)
{
isc_nm_maxudp(isc_nm_t *mgr, uint32_t maxudp) {
REQUIRE(VALID_NM(mgr));
atomic_store(&mgr->maxudp, maxudp);
@@ -433,8 +420,7 @@ isc_nm_maxudp(isc_nm_t *mgr, uint32_t maxudp)
void
isc_nm_tcp_settimeouts(isc_nm_t *mgr, uint32_t init, uint32_t idle,
uint32_t keepalive, uint32_t advertised)
{
uint32_t keepalive, uint32_t advertised) {
REQUIRE(VALID_NM(mgr));
mgr->init = init * 100;
@@ -445,8 +431,7 @@ isc_nm_tcp_settimeouts(isc_nm_t *mgr, uint32_t init, uint32_t idle,
void
isc_nm_tcp_gettimeouts(isc_nm_t *mgr, uint32_t *initial, uint32_t *idle,
uint32_t *keepalive, uint32_t *advertised)
{
uint32_t *keepalive, uint32_t *advertised) {
REQUIRE(VALID_NM(mgr));
if (initial != NULL) {
@@ -471,15 +456,14 @@ isc_nm_tcp_gettimeouts(isc_nm_t *mgr, uint32_t *initial, uint32_t *idle,
* until asked to stop.
*/
static isc_threadresult_t
nm_thread(isc_threadarg_t worker0)
{
nm_thread(isc_threadarg_t worker0) {
isc__networker_t *worker = (isc__networker_t *)worker0;
isc__nm_tid_v = worker->id;
isc_thread_setaffinity(isc__nm_tid_v);
while (true) {
int r = uv_run(&worker->loop, UV_RUN_DEFAULT);
int r = uv_run(&worker->loop, UV_RUN_DEFAULT);
bool pausing = false;
/*
@@ -572,20 +556,18 @@ nm_thread(isc_threadarg_t worker0)
* passed from other threads.
*/
static void
async_cb(uv_async_t *handle)
{
async_cb(uv_async_t *handle) {
isc__networker_t *worker = (isc__networker_t *)handle->loop->data;
process_queue(worker, worker->ievents_prio);
process_queue(worker, worker->ievents);
}
static void
process_queue(isc__networker_t *worker, isc_queue_t *queue)
{
process_queue(isc__networker_t *worker, isc_queue_t *queue) {
isc__netievent_t *ievent = NULL;
while ((ievent = (isc__netievent_t *)isc_queue_dequeue(queue)) !=
NULL) {
while ((ievent = (isc__netievent_t *)isc_queue_dequeue(queue)) != NULL)
{
switch (ievent->type) {
case netievent_stop:
uv_stop(&worker->loop);
@@ -646,8 +628,7 @@ process_queue(isc__networker_t *worker, isc_queue_t *queue)
}
void *
isc__nm_get_ievent(isc_nm_t *mgr, isc__netievent_type type)
{
isc__nm_get_ievent(isc_nm_t *mgr, isc__netievent_type type) {
isc__netievent_storage_t *event = isc_mempool_get(mgr->evpool);
*event = (isc__netievent_storage_t){ .ni.type = type };
@@ -655,14 +636,12 @@ isc__nm_get_ievent(isc_nm_t *mgr, isc__netievent_type type)
}
void
isc__nm_put_ievent(isc_nm_t *mgr, void *ievent)
{
isc__nm_put_ievent(isc_nm_t *mgr, void *ievent) {
isc_mempool_put(mgr->evpool, ievent);
}
void
isc__nm_enqueue_ievent(isc__networker_t *worker, isc__netievent_t *event)
{
isc__nm_enqueue_ievent(isc__networker_t *worker, isc__netievent_t *event) {
if (event->type > netievent_prio) {
/*
* We need to make sure this signal will be delivered and
@@ -679,8 +658,7 @@ isc__nm_enqueue_ievent(isc__networker_t *worker, isc__netievent_t *event)
}
bool
isc__nmsocket_active(isc_nmsocket_t *sock)
{
isc__nmsocket_active(isc_nmsocket_t *sock) {
REQUIRE(VALID_NMSOCK(sock));
if (sock->parent != NULL) {
return (atomic_load(&sock->parent->active));
@@ -690,8 +668,7 @@ isc__nmsocket_active(isc_nmsocket_t *sock)
}
void
isc_nmsocket_attach(isc_nmsocket_t *sock, isc_nmsocket_t **target)
{
isc_nmsocket_attach(isc_nmsocket_t *sock, isc_nmsocket_t **target) {
REQUIRE(VALID_NMSOCK(sock));
REQUIRE(target != NULL && *target == NULL);
@@ -709,9 +686,8 @@ isc_nmsocket_attach(isc_nmsocket_t *sock, isc_nmsocket_t **target)
* Free all resources inside a socket (including its children if any).
*/
static void
nmsocket_cleanup(isc_nmsocket_t *sock, bool dofree)
{
isc_nmhandle_t * handle = NULL;
nmsocket_cleanup(isc_nmsocket_t *sock, bool dofree) {
isc_nmhandle_t *handle = NULL;
isc__nm_uvreq_t *uvreq = NULL;
REQUIRE(VALID_NMSOCK(sock));
@@ -788,9 +764,8 @@ nmsocket_cleanup(isc_nmsocket_t *sock, bool dofree)
}
static void
nmsocket_maybe_destroy(isc_nmsocket_t *sock)
{
int active_handles;
nmsocket_maybe_destroy(isc_nmsocket_t *sock) {
int active_handles;
bool destroy = false;
if (sock->parent != NULL) {
@@ -810,8 +785,8 @@ nmsocket_maybe_destroy(isc_nmsocket_t *sock)
*/
LOCK(&sock->lock);
if (atomic_load(&sock->active) || atomic_load(&sock->destroying) ||
!atomic_load(&sock->closed) ||
atomic_load(&sock->references) != 0) {
!atomic_load(&sock->closed) || atomic_load(&sock->references) != 0)
{
UNLOCK(&sock->lock);
return;
}
@@ -836,8 +811,7 @@ nmsocket_maybe_destroy(isc_nmsocket_t *sock)
}
void
isc__nmsocket_prep_destroy(isc_nmsocket_t *sock)
{
isc__nmsocket_prep_destroy(isc_nmsocket_t *sock) {
REQUIRE(sock->parent == NULL);
/*
@@ -882,8 +856,7 @@ isc__nmsocket_prep_destroy(isc_nmsocket_t *sock)
}
void
isc_nmsocket_detach(isc_nmsocket_t **sockp)
{
isc_nmsocket_detach(isc_nmsocket_t **sockp) {
REQUIRE(sockp != NULL && *sockp != NULL);
REQUIRE(VALID_NMSOCK(*sockp));
@@ -908,8 +881,7 @@ isc_nmsocket_detach(isc_nmsocket_t **sockp)
void
isc__nmsocket_init(isc_nmsocket_t *sock, isc_nm_t *mgr, isc_nmsocket_type type,
isc_nmiface_t *iface)
{
isc_nmiface_t *iface) {
uint16_t family;
REQUIRE(sock != NULL);
@@ -930,8 +902,8 @@ isc__nmsocket_init(isc_nmsocket_t *sock, isc_nm_t *mgr, isc_nmsocket_type type,
isc_nm_attach(mgr, &sock->mgr);
sock->uv_handle.handle.data = sock;
sock->ah_frees =
isc_mem_allocate(mgr->mctx, sock->ah_size * sizeof(size_t));
sock->ah_frees = isc_mem_allocate(mgr->mctx,
sock->ah_size * sizeof(size_t));
sock->ah_handles = isc_mem_allocate(
mgr->mctx, sock->ah_size * sizeof(isc_nmhandle_t *));
for (size_t i = 0; i < 32; i++) {
@@ -977,9 +949,8 @@ isc__nmsocket_init(isc_nmsocket_t *sock, isc_nm_t *mgr, isc_nmsocket_type type,
}
void
isc__nm_alloc_cb(uv_handle_t *handle, size_t size, uv_buf_t *buf)
{
isc_nmsocket_t * sock = uv_handle_get_data(handle);
isc__nm_alloc_cb(uv_handle_t *handle, size_t size, uv_buf_t *buf) {
isc_nmsocket_t *sock = uv_handle_get_data(handle);
isc__networker_t *worker = NULL;
REQUIRE(VALID_NMSOCK(sock));
@@ -995,8 +966,7 @@ isc__nm_alloc_cb(uv_handle_t *handle, size_t size, uv_buf_t *buf)
}
void
isc__nm_free_uvbuf(isc_nmsocket_t *sock, const uv_buf_t *buf)
{
isc__nm_free_uvbuf(isc_nmsocket_t *sock, const uv_buf_t *buf) {
isc__networker_t *worker = NULL;
REQUIRE(VALID_NMSOCK(sock));
@@ -1013,8 +983,7 @@ isc__nm_free_uvbuf(isc_nmsocket_t *sock, const uv_buf_t *buf)
}
static isc_nmhandle_t *
alloc_handle(isc_nmsocket_t *sock)
{
alloc_handle(isc_nmsocket_t *sock) {
isc_nmhandle_t *handle =
isc_mem_get(sock->mgr->mctx,
sizeof(isc_nmhandle_t) + sock->extrahandlesize);
@@ -1027,11 +996,10 @@ alloc_handle(isc_nmsocket_t *sock)
isc_nmhandle_t *
isc__nmhandle_get(isc_nmsocket_t *sock, isc_sockaddr_t *peer,
isc_sockaddr_t *local)
{
isc_sockaddr_t *local) {
isc_nmhandle_t *handle = NULL;
size_t handlenum;
int pos;
size_t handlenum;
int pos;
REQUIRE(VALID_NMSOCK(sock));
@@ -1096,16 +1064,14 @@ isc__nmhandle_get(isc_nmsocket_t *sock, isc_sockaddr_t *peer,
}
void
isc_nmhandle_ref(isc_nmhandle_t *handle)
{
isc_nmhandle_ref(isc_nmhandle_t *handle) {
REQUIRE(VALID_NMHANDLE(handle));
isc_refcount_increment(&handle->references);
}
bool
isc_nmhandle_is_stream(isc_nmhandle_t *handle)
{
isc_nmhandle_is_stream(isc_nmhandle_t *handle) {
REQUIRE(VALID_NMHANDLE(handle));
return (handle->sock->type == isc_nm_tcpsocket ||
@@ -1113,8 +1079,7 @@ isc_nmhandle_is_stream(isc_nmhandle_t *handle)
}
static void
nmhandle_free(isc_nmsocket_t *sock, isc_nmhandle_t *handle)
{
nmhandle_free(isc_nmsocket_t *sock, isc_nmhandle_t *handle) {
size_t extra = sock->extrahandlesize;
isc_refcount_destroy(&handle->references);
@@ -1129,8 +1094,7 @@ nmhandle_free(isc_nmsocket_t *sock, isc_nmhandle_t *handle)
}
static void
nmhandle_deactivate(isc_nmsocket_t *sock, isc_nmhandle_t *handle)
{
nmhandle_deactivate(isc_nmsocket_t *sock, isc_nmhandle_t *handle) {
/*
* We do all of this under lock to avoid races with socket
* destruction. We have to do this now, because at this point the
@@ -1157,8 +1121,7 @@ nmhandle_deactivate(isc_nmsocket_t *sock, isc_nmhandle_t *handle)
}
void
isc_nmhandle_unref(isc_nmhandle_t *handle)
{
isc_nmhandle_unref(isc_nmhandle_t *handle) {
isc_nmsocket_t *sock = NULL, *tmp = NULL;
REQUIRE(VALID_NMHANDLE(handle));
@@ -1210,8 +1173,7 @@ isc_nmhandle_unref(isc_nmhandle_t *handle)
}
void *
isc_nmhandle_getdata(isc_nmhandle_t *handle)
{
isc_nmhandle_getdata(isc_nmhandle_t *handle) {
REQUIRE(VALID_NMHANDLE(handle));
return (handle->opaque);
@@ -1219,8 +1181,7 @@ isc_nmhandle_getdata(isc_nmhandle_t *handle)
void
isc_nmhandle_setdata(isc_nmhandle_t *handle, void *arg,
isc_nm_opaquecb_t doreset, isc_nm_opaquecb_t dofree)
{
isc_nm_opaquecb_t doreset, isc_nm_opaquecb_t dofree) {
REQUIRE(VALID_NMHANDLE(handle));
handle->opaque = arg;
@@ -1229,32 +1190,28 @@ isc_nmhandle_setdata(isc_nmhandle_t *handle, void *arg,
}
void *
isc_nmhandle_getextra(isc_nmhandle_t *handle)
{
isc_nmhandle_getextra(isc_nmhandle_t *handle) {
REQUIRE(VALID_NMHANDLE(handle));
return (handle->extra);
}
isc_sockaddr_t
isc_nmhandle_peeraddr(isc_nmhandle_t *handle)
{
isc_nmhandle_peeraddr(isc_nmhandle_t *handle) {
REQUIRE(VALID_NMHANDLE(handle));
return (handle->peer);
}
isc_sockaddr_t
isc_nmhandle_localaddr(isc_nmhandle_t *handle)
{
isc_nmhandle_localaddr(isc_nmhandle_t *handle) {
REQUIRE(VALID_NMHANDLE(handle));
return (handle->local);
}
isc_nm_t *
isc_nmhandle_netmgr(isc_nmhandle_t *handle)
{
isc_nmhandle_netmgr(isc_nmhandle_t *handle) {
REQUIRE(VALID_NMHANDLE(handle));
REQUIRE(VALID_NMSOCK(handle->sock));
@@ -1262,8 +1219,7 @@ isc_nmhandle_netmgr(isc_nmhandle_t *handle)
}
isc__nm_uvreq_t *
isc__nm_uvreq_get(isc_nm_t *mgr, isc_nmsocket_t *sock)
{
isc__nm_uvreq_get(isc_nm_t *mgr, isc_nmsocket_t *sock) {
isc__nm_uvreq_t *req = NULL;
REQUIRE(VALID_NM(mgr));
@@ -1287,10 +1243,9 @@ isc__nm_uvreq_get(isc_nm_t *mgr, isc_nmsocket_t *sock)
}
void
isc__nm_uvreq_put(isc__nm_uvreq_t **req0, isc_nmsocket_t *sock)
{
isc__nm_uvreq_put(isc__nm_uvreq_t **req0, isc_nmsocket_t *sock) {
isc__nm_uvreq_t *req = NULL;
isc_nmhandle_t * handle = NULL;
isc_nmhandle_t *handle = NULL;
REQUIRE(req0 != NULL);
REQUIRE(VALID_UVREQ(*req0));
@@ -1323,8 +1278,7 @@ isc__nm_uvreq_put(isc__nm_uvreq_t **req0, isc_nmsocket_t *sock)
isc_result_t
isc_nm_send(isc_nmhandle_t *handle, isc_region_t *region, isc_nm_cb_t cb,
void *cbarg)
{
void *cbarg) {
REQUIRE(VALID_NMHANDLE(handle));
switch (handle->sock->type) {
@@ -1342,8 +1296,7 @@ isc_nm_send(isc_nmhandle_t *handle, isc_region_t *region, isc_nm_cb_t cb,
}
void
isc__nm_async_closecb(isc__networker_t *worker, isc__netievent_t *ev0)
{
isc__nm_async_closecb(isc__networker_t *worker, isc__netievent_t *ev0) {
isc__netievent_closecb_t *ievent = (isc__netievent_closecb_t *)ev0;
REQUIRE(VALID_NMSOCK(ievent->sock));
@@ -1359,8 +1312,7 @@ isc__nm_async_closecb(isc__networker_t *worker, isc__netievent_t *ev0)
}
static void
shutdown_walk_cb(uv_handle_t *handle, void *arg)
{
shutdown_walk_cb(uv_handle_t *handle, void *arg) {
UNUSED(arg);
switch (handle->type) {
@@ -1373,15 +1325,13 @@ shutdown_walk_cb(uv_handle_t *handle, void *arg)
}
void
isc__nm_async_shutdown(isc__networker_t *worker, isc__netievent_t *ev0)
{
isc__nm_async_shutdown(isc__networker_t *worker, isc__netievent_t *ev0) {
UNUSED(ev0);
uv_walk(&worker->loop, shutdown_walk_cb, NULL);
}
bool
isc__nm_acquire_interlocked(isc_nm_t *mgr)
{
isc__nm_acquire_interlocked(isc_nm_t *mgr) {
LOCK(&mgr->lock);
bool success = atomic_compare_exchange_strong(&mgr->interlocked,
&(bool){ false }, true);
@@ -1390,8 +1340,7 @@ isc__nm_acquire_interlocked(isc_nm_t *mgr)
}
void
isc__nm_drop_interlocked(isc_nm_t *mgr)
{
isc__nm_drop_interlocked(isc_nm_t *mgr) {
LOCK(&mgr->lock);
bool success = atomic_compare_exchange_strong(&mgr->interlocked,
&(bool){ true }, false);
@@ -1401,19 +1350,18 @@ isc__nm_drop_interlocked(isc_nm_t *mgr)
}
void
isc__nm_acquire_interlocked_force(isc_nm_t *mgr)
{
isc__nm_acquire_interlocked_force(isc_nm_t *mgr) {
LOCK(&mgr->lock);
while (!atomic_compare_exchange_strong(&mgr->interlocked,
&(bool){ false }, true)) {
&(bool){ false }, true))
{
WAIT(&mgr->wkstatecond, &mgr->lock);
}
UNLOCK(&mgr->lock);
}
void
isc_nm_setstats(isc_nm_t *mgr, isc_stats_t *stats)
{
isc_nm_setstats(isc_nm_t *mgr, isc_stats_t *stats) {
REQUIRE(VALID_NM(mgr));
REQUIRE(mgr->stats == NULL);
REQUIRE(isc_stats_ncounters(stats) == isc_sockstatscounter_max);
@@ -1422,8 +1370,7 @@ isc_nm_setstats(isc_nm_t *mgr, isc_stats_t *stats)
}
void
isc__nm_incstats(isc_nm_t *mgr, isc_statscounter_t counterid)
{
isc__nm_incstats(isc_nm_t *mgr, isc_statscounter_t counterid) {
REQUIRE(VALID_NM(mgr));
REQUIRE(counterid != -1);
@@ -1433,8 +1380,7 @@ isc__nm_incstats(isc_nm_t *mgr, isc_statscounter_t counterid)
}
void
isc__nm_decstats(isc_nm_t *mgr, isc_statscounter_t counterid)
{
isc__nm_decstats(isc_nm_t *mgr, isc_statscounter_t counterid) {
REQUIRE(VALID_NM(mgr));
REQUIRE(counterid != -1);