aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/iomgr
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lib/iomgr')
-rw-r--r--src/core/lib/iomgr/call_combiner.cc2
-rw-r--r--src/core/lib/iomgr/closure.cc28
-rw-r--r--src/core/lib/iomgr/combiner.cc14
-rw-r--r--src/core/lib/iomgr/error.cc18
-rw-r--r--src/core/lib/iomgr/error.h9
-rw-r--r--src/core/lib/iomgr/error_internal.h3
-rw-r--r--src/core/lib/iomgr/ev_epoll1_linux.cc68
-rw-r--r--src/core/lib/iomgr/ev_epollex_linux.cc104
-rw-r--r--src/core/lib/iomgr/ev_epollsig_linux.cc126
-rw-r--r--src/core/lib/iomgr/ev_poll_posix.cc114
-rw-r--r--src/core/lib/iomgr/ev_posix.cc14
-rw-r--r--src/core/lib/iomgr/exec_ctx.cc82
-rw-r--r--src/core/lib/iomgr/exec_ctx.h2
-rw-r--r--src/core/lib/iomgr/executor.cc4
-rw-r--r--src/core/lib/iomgr/gethostname_host_name_max.cc2
-rw-r--r--src/core/lib/iomgr/iocp_windows.h6
-rw-r--r--src/core/lib/iomgr/iomgr.cc2
-rw-r--r--src/core/lib/iomgr/is_epollexclusive_available.cc2
-rw-r--r--src/core/lib/iomgr/load_file.cc6
-rw-r--r--src/core/lib/iomgr/polling_entity.cc12
-rw-r--r--src/core/lib/iomgr/pollset_windows.h5
-rw-r--r--src/core/lib/iomgr/resolve_address_posix.cc14
-rw-r--r--src/core/lib/iomgr/resource_quota.cc56
-rw-r--r--src/core/lib/iomgr/sockaddr_utils.cc26
-rw-r--r--src/core/lib/iomgr/sockaddr_windows.h6
-rw-r--r--src/core/lib/iomgr/socket_utils_common_posix.cc8
-rw-r--r--src/core/lib/iomgr/socket_windows.h5
-rw-r--r--src/core/lib/iomgr/tcp_client_posix.cc18
-rw-r--r--src/core/lib/iomgr/tcp_posix.cc39
-rw-r--r--src/core/lib/iomgr/tcp_server_posix.cc34
-rw-r--r--src/core/lib/iomgr/tcp_server_utils_posix_common.cc10
-rw-r--r--src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc24
-rw-r--r--src/core/lib/iomgr/tcp_uv.h6
-rw-r--r--src/core/lib/iomgr/tcp_windows.h5
-rw-r--r--src/core/lib/iomgr/timer_generic.cc30
-rw-r--r--src/core/lib/iomgr/timer_manager.cc12
-rw-r--r--src/core/lib/iomgr/udp_server.cc21
-rw-r--r--src/core/lib/iomgr/unix_sockets_posix.cc7
-rw-r--r--src/core/lib/iomgr/wakeup_fd_cv.cc4
-rw-r--r--src/core/lib/iomgr/wakeup_fd_posix.cc4
40 files changed, 529 insertions, 423 deletions
diff --git a/src/core/lib/iomgr/call_combiner.cc b/src/core/lib/iomgr/call_combiner.cc
index c2f5b4bb84..32b4244748 100644
--- a/src/core/lib/iomgr/call_combiner.cc
+++ b/src/core/lib/iomgr/call_combiner.cc
@@ -119,7 +119,7 @@ void grpc_call_combiner_stop(grpc_call_combiner* call_combiner DEBUG_ARGS,
bool empty;
grpc_closure* closure = (grpc_closure*)gpr_mpscq_pop_and_check_end(
&call_combiner->queue, &empty);
- if (closure == NULL) {
+ if (closure == nullptr) {
// This can happen either due to a race condition within the mpscq
// code or because of a race with grpc_call_combiner_start().
if (GRPC_TRACER_ON(grpc_call_combiner_trace)) {
diff --git a/src/core/lib/iomgr/closure.cc b/src/core/lib/iomgr/closure.cc
index 44731eed76..32766110cc 100644
--- a/src/core/lib/iomgr/closure.cc
+++ b/src/core/lib/iomgr/closure.cc
@@ -43,7 +43,7 @@ grpc_closure* grpc_closure_init(grpc_closure* closure, grpc_iomgr_cb_func cb,
closure->scheduler = scheduler;
#ifndef NDEBUG
closure->scheduled = false;
- closure->file_initiated = NULL;
+ closure->file_initiated = nullptr;
closure->line_initiated = 0;
closure->run = false;
closure->file_created = file;
@@ -53,18 +53,18 @@ grpc_closure* grpc_closure_init(grpc_closure* closure, grpc_iomgr_cb_func cb,
}
void grpc_closure_list_init(grpc_closure_list* closure_list) {
- closure_list->head = closure_list->tail = NULL;
+ closure_list->head = closure_list->tail = nullptr;
}
bool grpc_closure_list_append(grpc_closure_list* closure_list,
grpc_closure* closure, grpc_error* error) {
- if (closure == NULL) {
+ if (closure == nullptr) {
GRPC_ERROR_UNREF(error);
return false;
}
closure->error_data.error = error;
- closure->next_data.next = NULL;
- bool was_empty = (closure_list->head == NULL);
+ closure->next_data.next = nullptr;
+ bool was_empty = (closure_list->head == nullptr);
if (was_empty) {
closure_list->head = closure;
} else {
@@ -76,7 +76,7 @@ bool grpc_closure_list_append(grpc_closure_list* closure_list,
void grpc_closure_list_fail_all(grpc_closure_list* list,
grpc_error* forced_failure) {
- for (grpc_closure* c = list->head; c != NULL; c = c->next_data.next) {
+ for (grpc_closure* c = list->head; c != nullptr; c = c->next_data.next) {
if (c->error_data.error == GRPC_ERROR_NONE) {
c->error_data.error = GRPC_ERROR_REF(forced_failure);
}
@@ -85,20 +85,20 @@ void grpc_closure_list_fail_all(grpc_closure_list* list,
}
bool grpc_closure_list_empty(grpc_closure_list closure_list) {
- return closure_list.head == NULL;
+ return closure_list.head == nullptr;
}
void grpc_closure_list_move(grpc_closure_list* src, grpc_closure_list* dst) {
- if (src->head == NULL) {
+ if (src->head == nullptr) {
return;
}
- if (dst->head == NULL) {
+ if (dst->head == nullptr) {
*dst = *src;
} else {
dst->tail->next_data.next = src->head;
dst->tail = src->tail;
}
- src->head = src->tail = NULL;
+ src->head = src->tail = nullptr;
}
typedef struct {
@@ -141,7 +141,7 @@ void grpc_closure_run(const char* file, int line, grpc_closure* c,
void grpc_closure_run(grpc_closure* c, grpc_error* error) {
#endif
GPR_TIMER_BEGIN("grpc_closure_run", 0);
- if (c != NULL) {
+ if (c != nullptr) {
#ifndef NDEBUG
c->file_initiated = file;
c->line_initiated = line;
@@ -162,7 +162,7 @@ void grpc_closure_sched(const char* file, int line, grpc_closure* c,
void grpc_closure_sched(grpc_closure* c, grpc_error* error) {
#endif
GPR_TIMER_BEGIN("grpc_closure_sched", 0);
- if (c != NULL) {
+ if (c != nullptr) {
#ifndef NDEBUG
if (c->scheduled) {
gpr_log(GPR_ERROR,
@@ -192,7 +192,7 @@ void grpc_closure_list_sched(const char* file, int line,
void grpc_closure_list_sched(grpc_closure_list* list) {
#endif
grpc_closure* c = list->head;
- while (c != NULL) {
+ while (c != nullptr) {
grpc_closure* next = c->next_data.next;
#ifndef NDEBUG
if (c->scheduled) {
@@ -212,5 +212,5 @@ void grpc_closure_list_sched(grpc_closure_list* list) {
c->scheduler->vtable->sched(c, c->error_data.error);
c = next;
}
- list->head = list->tail = NULL;
+ list->head = list->tail = nullptr;
}
diff --git a/src/core/lib/iomgr/combiner.cc b/src/core/lib/iomgr/combiner.cc
index 6cc4eef1d8..d2b7cf4b10 100644
--- a/src/core/lib/iomgr/combiner.cc
+++ b/src/core/lib/iomgr/combiner.cc
@@ -144,7 +144,7 @@ static void push_first_on_exec_ctx(grpc_combiner* lock) {
lock->next_combiner_on_this_exec_ctx =
grpc_core::ExecCtx::Get()->combiner_data()->active_combiner;
grpc_core::ExecCtx::Get()->combiner_data()->active_combiner = lock;
- if (lock->next_combiner_on_this_exec_ctx == NULL) {
+ if (lock->next_combiner_on_this_exec_ctx == nullptr) {
grpc_core::ExecCtx::Get()->combiner_data()->last_combiner = lock;
}
}
@@ -190,8 +190,8 @@ static void move_next() {
grpc_core::ExecCtx::Get()
->combiner_data()
->active_combiner->next_combiner_on_this_exec_ctx;
- if (grpc_core::ExecCtx::Get()->combiner_data()->active_combiner == NULL) {
- grpc_core::ExecCtx::Get()->combiner_data()->last_combiner = NULL;
+ if (grpc_core::ExecCtx::Get()->combiner_data()->active_combiner == nullptr) {
+ grpc_core::ExecCtx::Get()->combiner_data()->last_combiner = nullptr;
}
}
@@ -211,7 +211,7 @@ bool grpc_combiner_continue_exec_ctx() {
GPR_TIMER_BEGIN("combiner.continue_exec_ctx", 0);
grpc_combiner* lock =
grpc_core::ExecCtx::Get()->combiner_data()->active_combiner;
- if (lock == NULL) {
+ if (lock == nullptr) {
GPR_TIMER_END("combiner.continue_exec_ctx", 0);
return false;
}
@@ -245,7 +245,7 @@ bool grpc_combiner_continue_exec_ctx() {
gpr_mpscq_node* n = gpr_mpscq_pop(&lock->queue);
GRPC_COMBINER_TRACE(
gpr_log(GPR_DEBUG, "C:%p maybe_finish_one n=%p", lock, n));
- if (n == NULL) {
+ if (n == nullptr) {
// queue is in an inconsistent state: use this as a cue that we should
// go off and do something else for a while (and come back later)
GPR_TIMER_MARK("delay_busy", 0);
@@ -264,10 +264,10 @@ bool grpc_combiner_continue_exec_ctx() {
GPR_TIMER_END("combiner.exec1", 0);
} else {
grpc_closure* c = lock->final_list.head;
- GPR_ASSERT(c != NULL);
+ GPR_ASSERT(c != nullptr);
grpc_closure_list_init(&lock->final_list);
int loops = 0;
- while (c != NULL) {
+ while (c != nullptr) {
GPR_TIMER_BEGIN("combiner.exec_1final", 0);
GRPC_COMBINER_TRACE(
gpr_log(GPR_DEBUG, "C:%p execute_final[%d] c=%p", lock, loops, c));
diff --git a/src/core/lib/iomgr/error.cc b/src/core/lib/iomgr/error.cc
index 157f12a36d..2364b1a369 100644
--- a/src/core/lib/iomgr/error.cc
+++ b/src/core/lib/iomgr/error.cc
@@ -321,7 +321,7 @@ grpc_error* grpc_error_create(const char* file, int line, grpc_slice desc,
(uint8_t)(num_referencing * SLOTS_PER_LINKED_ERROR) + SURPLUS_CAPACITY);
grpc_error* err = (grpc_error*)gpr_malloc(
sizeof(*err) + initial_arena_capacity * sizeof(intptr_t));
- if (err == NULL) { // TODO(ctiller): make gpr_malloc return NULL
+ if (err == nullptr) { // TODO(ctiller): make gpr_malloc return NULL
return GRPC_ERROR_OOM;
}
#ifndef NDEBUG
@@ -453,7 +453,7 @@ bool grpc_error_get_int(grpc_error* err, grpc_error_ints which, intptr_t* p) {
if (which == GRPC_ERROR_INT_GRPC_STATUS) {
for (size_t i = 0; i < GPR_ARRAY_SIZE(error_status_map); i++) {
if (error_status_map[i].error == err) {
- if (p != NULL) *p = error_status_map[i].code;
+ if (p != nullptr) *p = error_status_map[i].code;
GPR_TIMER_END("grpc_error_get_int", 0);
return true;
}
@@ -464,7 +464,7 @@ bool grpc_error_get_int(grpc_error* err, grpc_error_ints which, intptr_t* p) {
}
uint8_t slot = err->ints[which];
if (slot != UINT8_MAX) {
- if (p != NULL) *p = err->arena[slot];
+ if (p != nullptr) *p = err->arena[slot];
GPR_TIMER_END("grpc_error_get_int", 0);
return true;
}
@@ -614,7 +614,7 @@ static char* key_str(grpc_error_strs which) {
}
static char* fmt_str(grpc_slice slice) {
- char* s = NULL;
+ char* s = nullptr;
size_t sz = 0;
size_t cap = 0;
append_esc_str((const uint8_t*)GRPC_SLICE_START_PTR(slice),
@@ -684,7 +684,7 @@ static void add_errs(grpc_error* err, char** s, size_t* sz, size_t* cap) {
}
static char* errs_string(grpc_error* err) {
- char* s = NULL;
+ char* s = nullptr;
size_t sz = 0;
size_t cap = 0;
append_chr('[', &s, &sz, &cap);
@@ -701,7 +701,7 @@ static int cmp_kvs(const void* a, const void* b) {
}
static char* finish_kvs(kv_pairs* kvs) {
- char* s = NULL;
+ char* s = nullptr;
size_t sz = 0;
size_t cap = 0;
@@ -729,7 +729,7 @@ const char* grpc_error_string(grpc_error* err) {
if (err == GRPC_ERROR_CANCELLED) return cancelled_error_string;
void* p = (void*)gpr_atm_acq_load(&err->atomics.error_string);
- if (p != NULL) {
+ if (p != nullptr) {
GPR_TIMER_END("grpc_error_string", 0);
return (const char*)p;
}
@@ -763,8 +763,8 @@ grpc_error* grpc_os_error(const char* file, int line, int err,
grpc_error_set_str(
grpc_error_set_int(
grpc_error_create(file, line,
- grpc_slice_from_static_string("OS Error"), NULL,
- 0),
+ grpc_slice_from_static_string("OS Error"),
+ nullptr, 0),
GRPC_ERROR_INT_ERRNO, err),
GRPC_ERROR_STR_OS_ERROR,
grpc_slice_from_static_string(strerror(err))),
diff --git a/src/core/lib/iomgr/error.h b/src/core/lib/iomgr/error.h
index 36ba440c8a..8d7aea4872 100644
--- a/src/core/lib/iomgr/error.h
+++ b/src/core/lib/iomgr/error.h
@@ -24,6 +24,7 @@
#include <grpc/slice.h>
#include <grpc/status.h>
+#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/debug/trace.h"
@@ -184,9 +185,15 @@ grpc_error* grpc_error_add_child(grpc_error* src,
grpc_error* child) GRPC_MUST_USE_RESULT;
grpc_error* grpc_os_error(const char* file, int line, int err,
const char* call_name) GRPC_MUST_USE_RESULT;
+
+inline grpc_error* grpc_assert_never_ok(grpc_error* error) {
+ GPR_ASSERT(error != GRPC_ERROR_NONE);
+ return error;
+}
+
/// create an error associated with errno!=0 (an 'operating system' error)
#define GRPC_OS_ERROR(err, call_name) \
- grpc_os_error(__FILE__, __LINE__, err, call_name)
+ grpc_assert_never_ok(grpc_os_error(__FILE__, __LINE__, err, call_name))
grpc_error* grpc_wsa_error(const char* file, int line, int err,
const char* call_name) GRPC_MUST_USE_RESULT;
/// windows only: create an error associated with WSAGetLastError()!=0
diff --git a/src/core/lib/iomgr/error_internal.h b/src/core/lib/iomgr/error_internal.h
index acf6e04e9c..d5ccbae9e7 100644
--- a/src/core/lib/iomgr/error_internal.h
+++ b/src/core/lib/iomgr/error_internal.h
@@ -23,6 +23,7 @@
#include <stdbool.h> // TODO, do we need this?
#include <grpc/support/sync.h>
+#include "src/core/lib/iomgr/error.h"
#ifdef __cplusplus
extern "C" {
@@ -59,7 +60,7 @@ struct grpc_error {
intptr_t arena[0];
};
-bool grpc_error_is_special(grpc_error* err);
+bool grpc_error_is_special(struct grpc_error* err);
#ifdef __cplusplus
}
diff --git a/src/core/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc
index f22fb82797..1598657afe 100644
--- a/src/core/lib/iomgr/ev_epoll1_linux.cc
+++ b/src/core/lib/iomgr/ev_epoll1_linux.cc
@@ -235,7 +235,7 @@ static bool append_error(grpc_error** composite, grpc_error* error,
* alarm 'epoch'). This wakeup_fd gives us something to alert on when such a
* case occurs. */
-static grpc_fd* fd_freelist = NULL;
+static grpc_fd* fd_freelist = nullptr;
static gpr_mu fd_freelist_mu;
static void fd_global_init(void) { gpr_mu_init(&fd_freelist_mu); }
@@ -243,7 +243,7 @@ static void fd_global_init(void) { gpr_mu_init(&fd_freelist_mu); }
static void fd_global_shutdown(void) {
gpr_mu_lock(&fd_freelist_mu);
gpr_mu_unlock(&fd_freelist_mu);
- while (fd_freelist != NULL) {
+ while (fd_freelist != nullptr) {
grpc_fd* fd = fd_freelist;
fd_freelist = fd_freelist->freelist_next;
gpr_free(fd);
@@ -252,25 +252,25 @@ static void fd_global_shutdown(void) {
}
static grpc_fd* fd_create(int fd, const char* name) {
- grpc_fd* new_fd = NULL;
+ grpc_fd* new_fd = nullptr;
gpr_mu_lock(&fd_freelist_mu);
- if (fd_freelist != NULL) {
+ if (fd_freelist != nullptr) {
new_fd = fd_freelist;
fd_freelist = fd_freelist->freelist_next;
}
gpr_mu_unlock(&fd_freelist_mu);
- if (new_fd == NULL) {
+ if (new_fd == nullptr) {
new_fd = (grpc_fd*)gpr_malloc(sizeof(grpc_fd));
}
new_fd->fd = fd;
new_fd->read_closure.Init();
new_fd->write_closure.Init();
- gpr_atm_no_barrier_store(&new_fd->read_notifier_pollset, (gpr_atm)NULL);
+ gpr_atm_no_barrier_store(&new_fd->read_notifier_pollset, (gpr_atm) nullptr);
- new_fd->freelist_next = NULL;
+ new_fd->freelist_next = nullptr;
char* fd_name;
gpr_asprintf(&fd_name, "%s fd=%d", name, fd);
@@ -316,7 +316,7 @@ static void fd_shutdown(grpc_fd* fd, grpc_error* why) {
static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd,
bool already_closed, const char* reason) {
grpc_error* error = GRPC_ERROR_NONE;
- bool is_release_fd = (release_fd != NULL);
+ bool is_release_fd = (release_fd != nullptr);
if (!fd->read_closure->IsShutdown()) {
fd_shutdown_internal(fd, GRPC_ERROR_CREATE_FROM_COPIED_STRING(reason),
@@ -383,7 +383,7 @@ static size_t g_num_neighborhoods;
/* Return true if first in list */
static bool worker_insert(grpc_pollset* pollset, grpc_pollset_worker* worker) {
- if (pollset->root_worker == NULL) {
+ if (pollset->root_worker == nullptr) {
pollset->root_worker = worker;
worker->next = worker->prev = worker;
return true;
@@ -403,7 +403,7 @@ static worker_remove_result worker_remove(grpc_pollset* pollset,
grpc_pollset_worker* worker) {
if (worker == pollset->root_worker) {
if (worker == worker->next) {
- pollset->root_worker = NULL;
+ pollset->root_worker = nullptr;
return EMPTIED;
} else {
pollset->root_worker = worker->next;
@@ -460,13 +460,13 @@ static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) {
*mu = &pollset->mu;
pollset->neighborhood = &g_neighborhoods[choose_neighborhood()];
pollset->reassigning_neighborhood = false;
- pollset->root_worker = NULL;
+ pollset->root_worker = nullptr;
pollset->kicked_without_poller = false;
pollset->seen_inactive = true;
pollset->shutting_down = false;
- pollset->shutdown_closure = NULL;
+ pollset->shutdown_closure = nullptr;
pollset->begin_refs = 0;
- pollset->next = pollset->prev = NULL;
+ pollset->next = pollset->prev = nullptr;
}
static void pollset_destroy(grpc_pollset* pollset) {
@@ -488,7 +488,7 @@ static void pollset_destroy(grpc_pollset* pollset) {
pollset->next->prev = pollset->prev;
if (pollset == pollset->neighborhood->active_root) {
pollset->neighborhood->active_root =
- pollset->next == pollset ? NULL : pollset->next;
+ pollset->next == pollset ? nullptr : pollset->next;
}
}
gpr_mu_unlock(&pollset->neighborhood->mu);
@@ -500,7 +500,7 @@ static void pollset_destroy(grpc_pollset* pollset) {
static grpc_error* pollset_kick_all(grpc_pollset* pollset) {
GPR_TIMER_BEGIN("pollset_kick_all", 0);
grpc_error* error = GRPC_ERROR_NONE;
- if (pollset->root_worker != NULL) {
+ if (pollset->root_worker != nullptr) {
grpc_pollset_worker* worker = pollset->root_worker;
do {
GRPC_STATS_INC_POLLSET_KICK();
@@ -533,17 +533,17 @@ static grpc_error* pollset_kick_all(grpc_pollset* pollset) {
}
static void pollset_maybe_finish_shutdown(grpc_pollset* pollset) {
- if (pollset->shutdown_closure != NULL && pollset->root_worker == NULL &&
+ if (pollset->shutdown_closure != nullptr && pollset->root_worker == nullptr &&
pollset->begin_refs == 0) {
GPR_TIMER_MARK("pollset_finish_shutdown", 0);
GRPC_CLOSURE_SCHED(pollset->shutdown_closure, GRPC_ERROR_NONE);
- pollset->shutdown_closure = NULL;
+ pollset->shutdown_closure = nullptr;
}
}
static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) {
GPR_TIMER_BEGIN("pollset_shutdown", 0);
- GPR_ASSERT(pollset->shutdown_closure == NULL);
+ GPR_ASSERT(pollset->shutdown_closure == nullptr);
GPR_ASSERT(!pollset->shutting_down);
pollset->shutdown_closure = closure;
pollset->shutting_down = true;
@@ -652,7 +652,7 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker,
grpc_pollset_worker** worker_hdl,
grpc_millis deadline) {
GPR_TIMER_BEGIN("begin_worker", 0);
- if (worker_hdl != NULL) *worker_hdl = worker;
+ if (worker_hdl != nullptr) *worker_hdl = worker;
worker->initialized_cv = false;
SET_KICK_STATE(worker, UNKICKED);
worker->schedule_on_end_work = (grpc_closure_list)GRPC_CLOSURE_LIST_INIT;
@@ -701,7 +701,7 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker,
not visible in the "kick any" path yet */
if (worker->state == UNKICKED) {
pollset->seen_inactive = false;
- if (neighborhood->active_root == NULL) {
+ if (neighborhood->active_root == nullptr) {
neighborhood->active_root = pollset->next = pollset->prev = pollset;
/* Make this the designated poller if there isn't one already */
if (worker->state == UNKICKED &&
@@ -779,13 +779,13 @@ static bool check_neighborhood_for_available_poller(
bool found_worker = false;
do {
grpc_pollset* inspect = neighborhood->active_root;
- if (inspect == NULL) {
+ if (inspect == nullptr) {
break;
}
gpr_mu_lock(&inspect->mu);
GPR_ASSERT(!inspect->seen_inactive);
grpc_pollset_worker* inspect_worker = inspect->root_worker;
- if (inspect_worker != NULL) {
+ if (inspect_worker != nullptr) {
do {
switch (inspect_worker->state) {
case UNKICKED:
@@ -826,11 +826,11 @@ static bool check_neighborhood_for_available_poller(
inspect->seen_inactive = true;
if (inspect == neighborhood->active_root) {
neighborhood->active_root =
- inspect->next == inspect ? NULL : inspect->next;
+ inspect->next == inspect ? nullptr : inspect->next;
}
inspect->next->prev = inspect->prev;
inspect->prev->next = inspect->next;
- inspect->next = inspect->prev = NULL;
+ inspect->next = inspect->prev = nullptr;
}
gpr_mu_unlock(&inspect->mu);
} while (!found_worker);
@@ -844,7 +844,7 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker,
if (GRPC_TRACER_ON(grpc_polling_trace)) {
gpr_log(GPR_DEBUG, "PS:%p END_WORKER:%p", pollset, worker);
}
- if (worker_hdl != NULL) *worker_hdl = NULL;
+ if (worker_hdl != nullptr) *worker_hdl = nullptr;
/* Make sure we appear kicked */
SET_KICK_STATE(worker, KICKED);
grpc_closure_list_move(&worker->schedule_on_end_work,
@@ -984,28 +984,28 @@ static grpc_error* pollset_kick(grpc_pollset* pollset,
(void*)gpr_tls_get(&g_current_thread_worker),
pollset->root_worker);
gpr_strvec_add(&log, tmp);
- if (pollset->root_worker != NULL) {
+ if (pollset->root_worker != nullptr) {
gpr_asprintf(&tmp, " {kick_state=%s next=%p {kick_state=%s}}",
kick_state_string(pollset->root_worker->state),
pollset->root_worker->next,
kick_state_string(pollset->root_worker->next->state));
gpr_strvec_add(&log, tmp);
}
- if (specific_worker != NULL) {
+ if (specific_worker != nullptr) {
gpr_asprintf(&tmp, " worker_kick_state=%s",
kick_state_string(specific_worker->state));
gpr_strvec_add(&log, tmp);
}
- tmp = gpr_strvec_flatten(&log, NULL);
+ tmp = gpr_strvec_flatten(&log, nullptr);
gpr_strvec_destroy(&log);
gpr_log(GPR_ERROR, "%s", tmp);
gpr_free(tmp);
}
- if (specific_worker == NULL) {
+ if (specific_worker == nullptr) {
if (gpr_tls_get(&g_current_thread_pollset) != (intptr_t)pollset) {
grpc_pollset_worker* root_worker = pollset->root_worker;
- if (root_worker == NULL) {
+ if (root_worker == nullptr) {
GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER();
pollset->kicked_without_poller = true;
if (GRPC_TRACER_ON(grpc_polling_trace)) {
@@ -1206,11 +1206,11 @@ static const grpc_event_engine_vtable vtable = {
const grpc_event_engine_vtable* grpc_init_epoll1_linux(bool explicit_request) {
if (!grpc_has_wakeup_fd()) {
gpr_log(GPR_ERROR, "Skipping epoll1 because of no wakeup fd.");
- return NULL;
+ return nullptr;
}
if (!epoll_set_init()) {
- return NULL;
+ return nullptr;
}
fd_global_init();
@@ -1218,7 +1218,7 @@ const grpc_event_engine_vtable* grpc_init_epoll1_linux(bool explicit_request) {
if (!GRPC_LOG_IF_ERROR("pollset_global_init", pollset_global_init())) {
fd_global_shutdown();
epoll_set_shutdown();
- return NULL;
+ return nullptr;
}
return &vtable;
@@ -1232,7 +1232,7 @@ const grpc_event_engine_vtable* grpc_init_epoll1_linux(bool explicit_request) {
const grpc_event_engine_vtable* grpc_init_epoll1_linux(bool explicit_request) {
gpr_log(GPR_ERROR,
"Skipping epoll1 becuase GRPC_LINUX_EPOLL is not defined.");
- return NULL;
+ return nullptr;
}
#endif /* defined(GRPC_POSIX_SOCKET) */
#endif /* !defined(GRPC_LINUX_EPOLL) */
diff --git a/src/core/lib/iomgr/ev_epollex_linux.cc b/src/core/lib/iomgr/ev_epollex_linux.cc
index 5b4edd1e74..d83fe8f80a 100644
--- a/src/core/lib/iomgr/ev_epollex_linux.cc
+++ b/src/core/lib/iomgr/ev_epollex_linux.cc
@@ -254,7 +254,7 @@ static bool append_error(grpc_error** composite, grpc_error* error,
* becomes a spurious read notification on a reused fd.
*/
-static grpc_fd* fd_freelist = NULL;
+static grpc_fd* fd_freelist = nullptr;
static gpr_mu fd_freelist_mu;
#ifndef NDEBUG
@@ -320,7 +320,7 @@ static void fd_global_init(void) { gpr_mu_init(&fd_freelist_mu); }
static void fd_global_shutdown(void) {
gpr_mu_lock(&fd_freelist_mu);
gpr_mu_unlock(&fd_freelist_mu);
- while (fd_freelist != NULL) {
+ while (fd_freelist != nullptr) {
grpc_fd* fd = fd_freelist;
fd_freelist = fd_freelist->freelist_next;
gpr_free(fd);
@@ -329,30 +329,30 @@ static void fd_global_shutdown(void) {
}
static grpc_fd* fd_create(int fd, const char* name) {
- grpc_fd* new_fd = NULL;
+ grpc_fd* new_fd = nullptr;
gpr_mu_lock(&fd_freelist_mu);
- if (fd_freelist != NULL) {
+ if (fd_freelist != nullptr) {
new_fd = fd_freelist;
fd_freelist = fd_freelist->freelist_next;
}
gpr_mu_unlock(&fd_freelist_mu);
- if (new_fd == NULL) {
+ if (new_fd == nullptr) {
new_fd = (grpc_fd*)gpr_malloc(sizeof(grpc_fd));
}
gpr_mu_init(&new_fd->pollable_mu);
gpr_mu_init(&new_fd->orphan_mu);
- new_fd->pollable_obj = NULL;
+ new_fd->pollable_obj = nullptr;
gpr_atm_rel_store(&new_fd->refst, (gpr_atm)1);
new_fd->fd = fd;
new_fd->read_closure.Init();
new_fd->write_closure.Init();
- gpr_atm_no_barrier_store(&new_fd->read_notifier_pollset, (gpr_atm)NULL);
+ gpr_atm_no_barrier_store(&new_fd->read_notifier_pollset, (gpr_atm) nullptr);
- new_fd->freelist_next = NULL;
- new_fd->on_done_closure = NULL;
+ new_fd->freelist_next = nullptr;
+ new_fd->on_done_closure = nullptr;
char* fd_name;
gpr_asprintf(&fd_name, "%s fd=%d", name, fd);
@@ -381,7 +381,7 @@ static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd,
/* If release_fd is not NULL, we should be relinquishing control of the file
descriptor fd->fd (but we still own the grpc_fd structure). */
- if (release_fd != NULL) {
+ if (release_fd != nullptr) {
*release_fd = fd->fd;
} else if (!is_fd_closed) {
close(fd->fd);
@@ -434,7 +434,7 @@ static void fd_notify_on_write(grpc_fd* fd, grpc_closure* closure) {
*/
static grpc_error* pollable_create(pollable_type type, pollable** p) {
- *p = NULL;
+ *p = nullptr;
int epfd = epoll_create1(EPOLL_CLOEXEC);
if (epfd == -1) {
@@ -445,7 +445,7 @@ static grpc_error* pollable_create(pollable_type type, pollable** p) {
if (err != GRPC_ERROR_NONE) {
close(epfd);
gpr_free(*p);
- *p = NULL;
+ *p = nullptr;
return err;
}
struct epoll_event ev;
@@ -456,7 +456,7 @@ static grpc_error* pollable_create(pollable_type type, pollable** p) {
close(epfd);
grpc_wakeup_fd_destroy(&(*p)->wakeup);
gpr_free(*p);
- *p = NULL;
+ *p = nullptr;
return err;
}
@@ -464,10 +464,10 @@ static grpc_error* pollable_create(pollable_type type, pollable** p) {
gpr_ref_init(&(*p)->refs, 1);
gpr_mu_init(&(*p)->mu);
(*p)->epfd = epfd;
- (*p)->owner_fd = NULL;
- (*p)->pollset_set = NULL;
+ (*p)->owner_fd = nullptr;
+ (*p)->pollset_set = nullptr;
(*p)->next = (*p)->prev = *p;
- (*p)->root_worker = NULL;
+ (*p)->root_worker = nullptr;
(*p)->event_cursor = 0;
(*p)->event_count = 0;
return GRPC_ERROR_NONE;
@@ -491,14 +491,14 @@ static pollable* pollable_ref(pollable* p, int line, const char* reason) {
static void pollable_unref(pollable* p) {
#else
static void pollable_unref(pollable* p, int line, const char* reason) {
- if (p == NULL) return;
+ if (p == nullptr) return;
if (GRPC_TRACER_ON(grpc_trace_pollable_refcount)) {
int r = (int)gpr_atm_no_barrier_load(&p->refs.count);
gpr_log(__FILE__, line, GPR_LOG_SEVERITY_DEBUG,
"POLLABLE:%p unref %d->%d %s", p, r, r - 1, reason);
}
#endif
- if (p != NULL && gpr_unref(&p->refs)) {
+ if (p != nullptr && gpr_unref(&p->refs)) {
close(p->epfd);
grpc_wakeup_fd_destroy(&p->wakeup);
gpr_free(p);
@@ -558,10 +558,10 @@ static void pollset_maybe_finish_shutdown(grpc_pollset* pollset) {
pollset, pollset->active_pollable, pollset->shutdown_closure,
pollset->root_worker, pollset->containing_pollset_set_count);
}
- if (pollset->shutdown_closure != NULL && pollset->root_worker == NULL &&
+ if (pollset->shutdown_closure != nullptr && pollset->root_worker == nullptr &&
pollset->containing_pollset_set_count == 0) {
GRPC_CLOSURE_SCHED(pollset->shutdown_closure, GRPC_ERROR_NONE);
- pollset->shutdown_closure = NULL;
+ pollset->shutdown_closure = nullptr;
}
}
@@ -571,7 +571,7 @@ static void pollset_maybe_finish_shutdown(grpc_pollset* pollset) {
static grpc_error* kick_one_worker(grpc_pollset_worker* specific_worker) {
pollable* p = specific_worker->pollable_obj;
grpc_core::mu_guard lock(&p->mu);
- GPR_ASSERT(specific_worker != NULL);
+ GPR_ASSERT(specific_worker != nullptr);
if (specific_worker->kicked) {
if (GRPC_TRACER_ON(grpc_polling_trace)) {
gpr_log(GPR_DEBUG, "PS:%p kicked_specific_but_already_kicked", p);
@@ -620,9 +620,9 @@ static grpc_error* pollset_kick(grpc_pollset* pollset,
(void*)gpr_tls_get(&g_current_thread_pollset),
(void*)gpr_tls_get(&g_current_thread_worker), pollset->root_worker);
}
- if (specific_worker == NULL) {
+ if (specific_worker == nullptr) {
if (gpr_tls_get(&g_current_thread_pollset) != (intptr_t)pollset) {
- if (pollset->root_worker == NULL) {
+ if (pollset->root_worker == nullptr) {
if (GRPC_TRACER_ON(grpc_polling_trace)) {
gpr_log(GPR_DEBUG, "PS:%p kicked_any_without_poller", pollset);
}
@@ -664,7 +664,7 @@ static grpc_error* pollset_kick_all(grpc_pollset* pollset) {
grpc_error* error = GRPC_ERROR_NONE;
const char* err_desc = "pollset_kick_all";
grpc_pollset_worker* w = pollset->root_worker;
- if (w != NULL) {
+ if (w != nullptr) {
do {
GRPC_STATS_INC_POLLSET_KICK();
append_error(&error, kick_one_worker(w), err_desc);
@@ -709,23 +709,23 @@ static grpc_error* fd_get_or_become_pollable(grpc_fd* fd, pollable** p) {
gpr_mu_lock(&fd->pollable_mu);
grpc_error* error = GRPC_ERROR_NONE;
static const char* err_desc = "fd_get_or_become_pollable";
- if (fd->pollable_obj == NULL) {
+ if (fd->pollable_obj == nullptr) {
if (append_error(&error, pollable_create(PO_FD, &fd->pollable_obj),
err_desc)) {
fd->pollable_obj->owner_fd = fd;
if (!append_error(&error, pollable_add_fd(fd->pollable_obj, fd),
err_desc)) {
POLLABLE_UNREF(fd->pollable_obj, "fd_pollable");
- fd->pollable_obj = NULL;
+ fd->pollable_obj = nullptr;
}
}
}
if (error == GRPC_ERROR_NONE) {
- GPR_ASSERT(fd->pollable_obj != NULL);
+ GPR_ASSERT(fd->pollable_obj != nullptr);
*p = POLLABLE_REF(fd->pollable_obj, "pollset");
} else {
- GPR_ASSERT(fd->pollable_obj == NULL);
- *p = NULL;
+ GPR_ASSERT(fd->pollable_obj == nullptr);
+ *p = nullptr;
}
gpr_mu_unlock(&fd->pollable_mu);
return error;
@@ -733,7 +733,7 @@ static grpc_error* fd_get_or_become_pollable(grpc_fd* fd, pollable** p) {
/* pollset->po.mu lock must be held by the caller before calling this */
static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) {
- GPR_ASSERT(pollset->shutdown_closure == NULL);
+ GPR_ASSERT(pollset->shutdown_closure == nullptr);
pollset->shutdown_closure = closure;
GRPC_LOG_IF_ERROR("pollset_shutdown", pollset_kick_all(pollset));
pollset_maybe_finish_shutdown(pollset);
@@ -783,7 +783,7 @@ static grpc_error* pollable_process_events(grpc_pollset* pollset,
/* pollset_shutdown is guaranteed to be called before pollset_destroy. */
static void pollset_destroy(grpc_pollset* pollset) {
POLLABLE_UNREF(pollset->active_pollable, "pollset");
- pollset->active_pollable = NULL;
+ pollset->active_pollable = nullptr;
}
static grpc_error* pollable_epoll(pollable* p, grpc_millis deadline) {
@@ -822,7 +822,7 @@ static grpc_error* pollable_epoll(pollable* p, grpc_millis deadline) {
/* Return true if first in list */
static bool worker_insert(grpc_pollset_worker** root_worker,
grpc_pollset_worker* worker, pwlinks link) {
- if (*root_worker == NULL) {
+ if (*root_worker == nullptr) {
*root_worker = worker;
worker->links[link].next = worker->links[link].prev = worker;
return true;
@@ -843,7 +843,7 @@ static worker_remove_result worker_remove(grpc_pollset_worker** root_worker,
pwlinks link) {
if (worker == *root_worker) {
if (worker == worker->links[link].next) {
- *root_worker = NULL;
+ *root_worker = nullptr;
return WRR_EMPTIED;
} else {
*root_worker = worker->links[link].next;
@@ -863,7 +863,7 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker,
grpc_pollset_worker** worker_hdl,
grpc_millis deadline) {
bool do_poll = (pollset->shutdown_closure == nullptr);
- if (worker_hdl != NULL) *worker_hdl = worker;
+ if (worker_hdl != nullptr) *worker_hdl = worker;
worker->initialized_cv = false;
worker->kicked = false;
worker->pollset = pollset;
@@ -1033,12 +1033,12 @@ static grpc_error* pollset_transition_pollable_from_fd_to_multi_locked(
append_error(&error, pollset_kick_all(pollset), err_desc);
grpc_fd* initial_fd = pollset->active_pollable->owner_fd;
POLLABLE_UNREF(pollset->active_pollable, "pollset");
- pollset->active_pollable = NULL;
+ pollset->active_pollable = nullptr;
if (append_error(&error, pollable_create(PO_MULTI, &pollset->active_pollable),
err_desc)) {
append_error(&error, pollable_add_fd(pollset->active_pollable, initial_fd),
err_desc);
- if (and_add_fd != NULL) {
+ if (and_add_fd != nullptr) {
append_error(&error,
pollable_add_fd(pollset->active_pollable, and_add_fd),
err_desc);
@@ -1100,8 +1100,8 @@ static grpc_error* pollset_as_multipollable_locked(grpc_pollset* pollset,
POLLABLE_UNREF(pollset->active_pollable, "pollset");
error = pollable_create(PO_MULTI, &pollset->active_pollable);
} else {
- error =
- pollset_transition_pollable_from_fd_to_multi_locked(pollset, NULL);
+ error = pollset_transition_pollable_from_fd_to_multi_locked(pollset,
+ nullptr);
}
gpr_mu_unlock(&po_at_start->owner_fd->orphan_mu);
break;
@@ -1111,7 +1111,7 @@ static grpc_error* pollset_as_multipollable_locked(grpc_pollset* pollset,
if (error != GRPC_ERROR_NONE) {
POLLABLE_UNREF(pollset->active_pollable, "pollset");
pollset->active_pollable = po_at_start;
- *pollable_obj = NULL;
+ *pollable_obj = nullptr;
} else {
*pollable_obj = POLLABLE_REF(pollset->active_pollable, "pollset_set");
POLLABLE_UNREF(po_at_start, "pollset_as_multipollable");
@@ -1132,7 +1132,7 @@ static void pollset_add_fd(grpc_pollset* pollset, grpc_fd* fd) {
static grpc_pollset_set* pss_lock_adam(grpc_pollset_set* pss) {
gpr_mu_lock(&pss->mu);
- while (pss->parent != NULL) {
+ while (pss->parent != nullptr) {
gpr_mu_unlock(&pss->mu);
pss = pss->parent;
gpr_mu_lock(&pss->mu);
@@ -1148,7 +1148,7 @@ static grpc_pollset_set* pollset_set_create(void) {
}
static void pollset_set_unref(grpc_pollset_set* pss) {
- if (pss == NULL) return;
+ if (pss == nullptr) return;
if (!gpr_unref(&pss->refs)) return;
pollset_set_unref(pss->parent);
gpr_mu_destroy(&pss->mu);
@@ -1266,11 +1266,11 @@ static void pollset_set_add_pollset(grpc_pollset_set* pss, grpc_pollset* ps) {
}
grpc_error* error = GRPC_ERROR_NONE;
static const char* err_desc = "pollset_set_add_pollset";
- pollable* pollable_obj = NULL;
+ pollable* pollable_obj = nullptr;
gpr_mu_lock(&ps->mu);
if (!GRPC_LOG_IF_ERROR(err_desc,
pollset_as_multipollable_locked(ps, &pollable_obj))) {
- GPR_ASSERT(pollable_obj == NULL);
+ GPR_ASSERT(pollable_obj == nullptr);
gpr_mu_unlock(&ps->mu);
return;
}
@@ -1314,9 +1314,9 @@ static void pollset_set_add_pollset_set(grpc_pollset_set* a,
gpr_mu* b_mu = &b->mu;
gpr_mu_lock(a_mu);
gpr_mu_lock(b_mu);
- if (a->parent != NULL) {
+ if (a->parent != nullptr) {
a = a->parent;
- } else if (b->parent != NULL) {
+ } else if (b->parent != nullptr) {
b = b->parent;
} else {
break; // exit loop, both pollsets locked
@@ -1365,8 +1365,8 @@ static void pollset_set_add_pollset_set(grpc_pollset_set* a,
a->pollset_count += b->pollset_count;
gpr_free(b->fds);
gpr_free(b->pollsets);
- b->fds = NULL;
- b->pollsets = NULL;
+ b->fds = nullptr;
+ b->pollsets = nullptr;
b->fd_count = b->fd_capacity = b->pollset_count = b->pollset_capacity = 0;
gpr_mu_unlock(&a->mu);
gpr_mu_unlock(&b->mu);
@@ -1418,17 +1418,17 @@ static const grpc_event_engine_vtable vtable = {
const grpc_event_engine_vtable* grpc_init_epollex_linux(
bool explicitly_requested) {
if (!explicitly_requested) {
- return NULL;
+ return nullptr;
}
if (!grpc_has_wakeup_fd()) {
gpr_log(GPR_ERROR, "Skipping epollex because of no wakeup fd.");
- return NULL;
+ return nullptr;
}
if (!grpc_is_epollexclusive_available()) {
gpr_log(GPR_INFO, "Skipping epollex because it is not supported.");
- return NULL;
+ return nullptr;
}
#ifndef NDEBUG
@@ -1440,7 +1440,7 @@ const grpc_event_engine_vtable* grpc_init_epollex_linux(
if (!GRPC_LOG_IF_ERROR("pollset_global_init", pollset_global_init())) {
pollset_global_shutdown();
fd_global_shutdown();
- return NULL;
+ return nullptr;
}
return &vtable;
@@ -1455,7 +1455,7 @@ const grpc_event_engine_vtable* grpc_init_epollex_linux(
bool explicitly_requested) {
gpr_log(GPR_ERROR,
"Skipping epollex becuase GRPC_LINUX_EPOLL is not defined.");
- return NULL;
+ return nullptr;
}
#endif /* defined(GRPC_POSIX_SOCKET) */
diff --git a/src/core/lib/iomgr/ev_epollsig_linux.cc b/src/core/lib/iomgr/ev_epollsig_linux.cc
index 4ded7c0211..cbea6e4680 100644
--- a/src/core/lib/iomgr/ev_epollsig_linux.cc
+++ b/src/core/lib/iomgr/ev_epollsig_linux.cc
@@ -327,7 +327,7 @@ static void pi_unref(polling_island* pi) {
if (1 == gpr_atm_full_fetch_add(&pi->ref_count, -1)) {
polling_island* next = (polling_island*)gpr_atm_acq_load(&pi->merged_to);
polling_island_delete(pi);
- if (next != NULL) {
+ if (next != nullptr) {
PI_UNREF(next, "pi_delete"); /* Recursive call */
}
}
@@ -413,7 +413,7 @@ static void polling_island_remove_all_fds_locked(polling_island* pi,
const char* err_desc = "polling_island_remove_fds";
for (i = 0; i < pi->fd_cnt; i++) {
- err = epoll_ctl(pi->epoll_fd, EPOLL_CTL_DEL, pi->fds[i]->fd, NULL);
+ err = epoll_ctl(pi->epoll_fd, EPOLL_CTL_DEL, pi->fds[i]->fd, nullptr);
if (err < 0 && errno != ENOENT) {
gpr_asprintf(&err_msg,
"epoll_ctl (epoll_fd: %d) delete fds[%zu]: %d failed with "
@@ -443,7 +443,7 @@ static void polling_island_remove_fd_locked(polling_island* pi, grpc_fd* fd,
/* If fd is already closed, then it would have been automatically been removed
from the epoll set */
if (!is_fd_closed) {
- err = epoll_ctl(pi->epoll_fd, EPOLL_CTL_DEL, fd->fd, NULL);
+ err = epoll_ctl(pi->epoll_fd, EPOLL_CTL_DEL, fd->fd, nullptr);
if (err < 0 && errno != ENOENT) {
gpr_asprintf(
&err_msg,
@@ -466,7 +466,7 @@ static void polling_island_remove_fd_locked(polling_island* pi, grpc_fd* fd,
/* Might return NULL in case of an error */
static polling_island* polling_island_create(grpc_fd* initial_fd,
grpc_error** error) {
- polling_island* pi = NULL;
+ polling_island* pi = nullptr;
const char* err_desc = "polling_island_create";
*error = GRPC_ERROR_NONE;
@@ -475,12 +475,12 @@ static polling_island* polling_island_create(grpc_fd* initial_fd,
gpr_mu_init(&pi->mu);
pi->fd_cnt = 0;
pi->fd_capacity = 0;
- pi->fds = NULL;
+ pi->fds = nullptr;
pi->epoll_fd = -1;
gpr_atm_rel_store(&pi->ref_count, 0);
gpr_atm_rel_store(&pi->poller_count, 0);
- gpr_atm_rel_store(&pi->merged_to, (gpr_atm)NULL);
+ gpr_atm_rel_store(&pi->merged_to, (gpr_atm) nullptr);
pi->epoll_fd = epoll_create1(EPOLL_CLOEXEC);
@@ -489,14 +489,14 @@ static polling_island* polling_island_create(grpc_fd* initial_fd,
goto done;
}
- if (initial_fd != NULL) {
+ if (initial_fd != nullptr) {
polling_island_add_fds_locked(pi, &initial_fd, 1, true, error);
}
done:
if (*error != GRPC_ERROR_NONE) {
polling_island_delete(pi);
- pi = NULL;
+ pi = nullptr;
}
return pi;
}
@@ -517,7 +517,7 @@ static void polling_island_delete(polling_island* pi) {
* guarantees that the island returned is the last island */
static polling_island* polling_island_maybe_get_latest(polling_island* pi) {
polling_island* next = (polling_island*)gpr_atm_acq_load(&pi->merged_to);
- while (next != NULL) {
+ while (next != nullptr) {
pi = next;
next = (polling_island*)gpr_atm_acq_load(&pi->merged_to);
}
@@ -535,18 +535,18 @@ static polling_island* polling_island_maybe_get_latest(polling_island* pi) {
...
gpr_mu_unlock(&pi_latest->mu); // NOTE: use pi_latest->mu. NOT pi->mu */
static polling_island* polling_island_lock(polling_island* pi) {
- polling_island* next = NULL;
+ polling_island* next = nullptr;
while (true) {
next = (polling_island*)gpr_atm_acq_load(&pi->merged_to);
- if (next == NULL) {
+ if (next == nullptr) {
/* Looks like 'pi' is the last node in the linked list but unless we check
this by holding the pi->mu lock, we cannot be sure (i.e without the
pi->mu lock, we don't prevent island merges).
To be absolutely sure, check once more by holding the pi->mu lock */
gpr_mu_lock(&pi->mu);
next = (polling_island*)gpr_atm_acq_load(&pi->merged_to);
- if (next == NULL) {
+ if (next == nullptr) {
/* pi is infact the last node and we have the pi->mu lock. we're done */
break;
}
@@ -586,8 +586,8 @@ static polling_island* polling_island_lock(polling_island* pi) {
static void polling_island_lock_pair(polling_island** p, polling_island** q) {
polling_island* pi_1 = *p;
polling_island* pi_2 = *q;
- polling_island* next_1 = NULL;
- polling_island* next_2 = NULL;
+ polling_island* next_1 = nullptr;
+ polling_island* next_2 = nullptr;
/* The algorithm is simple:
- Go to the last polling islands in the linked lists *pi_1 and *pi_2 (and
@@ -605,13 +605,13 @@ static void polling_island_lock_pair(polling_island** p, polling_island** q) {
release the locks and continue the process from the first step */
while (true) {
next_1 = (polling_island*)gpr_atm_acq_load(&pi_1->merged_to);
- while (next_1 != NULL) {
+ while (next_1 != nullptr) {
pi_1 = next_1;
next_1 = (polling_island*)gpr_atm_acq_load(&pi_1->merged_to);
}
next_2 = (polling_island*)gpr_atm_acq_load(&pi_2->merged_to);
- while (next_2 != NULL) {
+ while (next_2 != nullptr) {
pi_2 = next_2;
next_2 = (polling_island*)gpr_atm_acq_load(&pi_2->merged_to);
}
@@ -631,7 +631,7 @@ static void polling_island_lock_pair(polling_island** p, polling_island** q) {
next_1 = (polling_island*)gpr_atm_acq_load(&pi_1->merged_to);
next_2 = (polling_island*)gpr_atm_acq_load(&pi_2->merged_to);
- if (next_1 == NULL && next_2 == NULL) {
+ if (next_1 == nullptr && next_2 == nullptr) {
break;
}
@@ -723,7 +723,7 @@ static void polling_island_global_shutdown() {
* alarm 'epoch'). This wakeup_fd gives us something to alert on when such a
* case occurs. */
-static grpc_fd* fd_freelist = NULL;
+static grpc_fd* fd_freelist = nullptr;
static gpr_mu fd_freelist_mu;
#ifndef NDEBUG
@@ -795,7 +795,7 @@ static void fd_global_init(void) { gpr_mu_init(&fd_freelist_mu); }
static void fd_global_shutdown(void) {
gpr_mu_lock(&fd_freelist_mu);
gpr_mu_unlock(&fd_freelist_mu);
- while (fd_freelist != NULL) {
+ while (fd_freelist != nullptr) {
grpc_fd* fd = fd_freelist;
fd_freelist = fd_freelist->freelist_next;
gpr_mu_destroy(&fd->po.mu);
@@ -805,16 +805,16 @@ static void fd_global_shutdown(void) {
}
static grpc_fd* fd_create(int fd, const char* name) {
- grpc_fd* new_fd = NULL;
+ grpc_fd* new_fd = nullptr;
gpr_mu_lock(&fd_freelist_mu);
- if (fd_freelist != NULL) {
+ if (fd_freelist != nullptr) {
new_fd = fd_freelist;
fd_freelist = fd_freelist->freelist_next;
}
gpr_mu_unlock(&fd_freelist_mu);
- if (new_fd == NULL) {
+ if (new_fd == nullptr) {
new_fd = (grpc_fd*)gpr_malloc(sizeof(grpc_fd));
gpr_mu_init(&new_fd->po.mu);
}
@@ -823,7 +823,7 @@ static grpc_fd* fd_create(int fd, const char* name) {
* is a newly created fd (or an fd we got from the freelist), no one else
* would be holding a lock to it anyway. */
gpr_mu_lock(&new_fd->po.mu);
- new_fd->po.pi = NULL;
+ new_fd->po.pi = nullptr;
#ifndef NDEBUG
new_fd->po.obj_type = POLL_OBJ_FD;
#endif
@@ -833,10 +833,10 @@ static grpc_fd* fd_create(int fd, const char* name) {
new_fd->orphaned = false;
new_fd->read_closure.Init();
new_fd->write_closure.Init();
- gpr_atm_no_barrier_store(&new_fd->read_notifier_pollset, (gpr_atm)NULL);
+ gpr_atm_no_barrier_store(&new_fd->read_notifier_pollset, (gpr_atm) nullptr);
- new_fd->freelist_next = NULL;
- new_fd->on_done_closure = NULL;
+ new_fd->freelist_next = nullptr;
+ new_fd->on_done_closure = nullptr;
gpr_mu_unlock(&new_fd->po.mu);
@@ -861,7 +861,7 @@ static int fd_wrapped_fd(grpc_fd* fd) {
static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd,
bool already_closed, const char* reason) {
grpc_error* error = GRPC_ERROR_NONE;
- polling_island* unref_pi = NULL;
+ polling_island* unref_pi = nullptr;
gpr_mu_lock(&fd->po.mu);
fd->on_done_closure = on_done;
@@ -878,18 +878,18 @@ static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd,
- Unlock the latest polling island
- Set fd->po.pi to NULL (but remove the ref on the polling island
before doing this.) */
- if (fd->po.pi != NULL) {
+ if (fd->po.pi != nullptr) {
polling_island* pi_latest = polling_island_lock(fd->po.pi);
polling_island_remove_fd_locked(pi_latest, fd, already_closed, &error);
gpr_mu_unlock(&pi_latest->mu);
unref_pi = fd->po.pi;
- fd->po.pi = NULL;
+ fd->po.pi = nullptr;
}
/* If release_fd is not NULL, we should be relinquishing control of the file
descriptor fd->fd (but we still own the grpc_fd structure). */
- if (release_fd != NULL) {
+ if (release_fd != nullptr) {
*release_fd = fd->fd;
} else {
close(fd->fd);
@@ -901,7 +901,7 @@ static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd,
gpr_mu_unlock(&fd->po.mu);
UNREF_BY(fd, 2, reason); /* Drop the reference */
- if (unref_pi != NULL) {
+ if (unref_pi != nullptr) {
/* Unref stale polling island here, outside the fd lock above.
The polling island owns a workqueue which owns an fd, and unreffing
inside the lock can cause an eventual lock loop that makes TSAN very
@@ -1003,7 +1003,7 @@ static grpc_pollset_worker* pop_front_worker(grpc_pollset* p) {
remove_worker(p, w);
return w;
} else {
- return NULL;
+ return nullptr;
}
}
@@ -1027,7 +1027,7 @@ static grpc_error* pollset_kick(grpc_pollset* p,
GRPC_STATS_INC_POLLSET_KICK();
const char* err_desc = "Kick Failure";
grpc_pollset_worker* worker = specific_worker;
- if (worker != NULL) {
+ if (worker != nullptr) {
if (worker == GRPC_POLLSET_KICK_BROADCAST) {
if (pollset_has_workers(p)) {
GPR_TIMER_BEGIN("pollset_kick.broadcast", 0);
@@ -1057,7 +1057,7 @@ static grpc_error* pollset_kick(grpc_pollset* p,
GPR_TIMER_MARK("kick_anonymous", 0);
worker = pop_front_worker(p);
- if (worker != NULL) {
+ if (worker != nullptr) {
GPR_TIMER_MARK("finally_kick", 0);
push_back_worker(p, worker);
append_error(&error, pollset_worker_kick(worker), err_desc);
@@ -1075,7 +1075,7 @@ static grpc_error* pollset_kick(grpc_pollset* p,
static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) {
gpr_mu_init(&pollset->po.mu);
*mu = &pollset->po.mu;
- pollset->po.pi = NULL;
+ pollset->po.pi = nullptr;
#ifndef NDEBUG
pollset->po.obj_type = POLL_OBJ_POLLSET;
#endif
@@ -1085,7 +1085,7 @@ static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) {
pollset->shutting_down = false;
pollset->finish_shutdown_called = false;
- pollset->shutdown_done = NULL;
+ pollset->shutdown_done = nullptr;
}
static int poll_deadline_to_millis_timeout(grpc_millis millis) {
@@ -1115,10 +1115,10 @@ static void fd_become_writable(grpc_fd* fd) { fd->write_closure->SetReady(); }
static void pollset_release_polling_island(grpc_pollset* ps,
const char* reason) {
- if (ps->po.pi != NULL) {
+ if (ps->po.pi != nullptr) {
PI_UNREF(ps->po.pi, reason);
}
- ps->po.pi = NULL;
+ ps->po.pi = nullptr;
}
static void finish_shutdown_locked(grpc_pollset* pollset) {
@@ -1167,7 +1167,7 @@ static void pollset_work_and_unlock(grpc_pollset* pollset,
struct epoll_event ep_ev[GRPC_EPOLL_MAX_EVENTS];
int epoll_fd = -1;
int ep_rv;
- polling_island* pi = NULL;
+ polling_island* pi = nullptr;
char* err_msg;
const char* err_desc = "pollset_work_and_unlock";
GPR_TIMER_BEGIN("pollset_work_and_unlock", 0);
@@ -1182,9 +1182,9 @@ static void pollset_work_and_unlock(grpc_pollset* pollset,
right-away from epoll_wait() and pick up the latest polling_island the next
this function (i.e pollset_work_and_unlock()) is called */
- if (pollset->po.pi == NULL) {
- pollset->po.pi = polling_island_create(NULL, error);
- if (pollset->po.pi == NULL) {
+ if (pollset->po.pi == nullptr) {
+ pollset->po.pi = polling_island_create(nullptr, error);
+ if (pollset->po.pi == nullptr) {
GPR_TIMER_END("pollset_work_and_unlock", 0);
return; /* Fatal error. We cannot continue */
}
@@ -1266,10 +1266,10 @@ static void pollset_work_and_unlock(grpc_pollset* pollset,
}
}
- g_current_thread_polling_island = NULL;
+ g_current_thread_polling_island = nullptr;
gpr_atm_no_barrier_fetch_add(&pi->poller_count, -1);
- GPR_ASSERT(pi != NULL);
+ GPR_ASSERT(pi != nullptr);
/* Before leaving, release the extra ref we added to the polling island. It
is important to use "pi" here (i.e our old copy of pollset->po.pi
@@ -1295,7 +1295,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset,
sigset_t new_mask;
grpc_pollset_worker worker;
- worker.next = worker.prev = NULL;
+ worker.next = worker.prev = nullptr;
worker.pt_id = pthread_self();
gpr_atm_no_barrier_store(&worker.is_kicked, (gpr_atm)0);
@@ -1377,7 +1377,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset,
gpr_mu_lock(&pollset->po.mu);
}
- if (worker_hdl) *worker_hdl = NULL;
+ if (worker_hdl) *worker_hdl = nullptr;
gpr_tls_set(&g_current_thread_pollset, (intptr_t)0);
gpr_tls_set(&g_current_thread_worker, (intptr_t)0);
@@ -1398,7 +1398,7 @@ static void add_poll_object(poll_obj* bag, poll_obj_type bag_type,
#endif
grpc_error* error = GRPC_ERROR_NONE;
- polling_island* pi_new = NULL;
+ polling_island* pi_new = nullptr;
gpr_mu_lock(&bag->mu);
gpr_mu_lock(&item->mu);
@@ -1425,7 +1425,7 @@ retry:
if (item->pi == bag->pi) {
pi_new = item->pi;
- if (pi_new == NULL) {
+ if (pi_new == nullptr) {
/* GPR_ASSERT(item->pi == bag->pi == NULL) */
/* If we are adding an fd to a bag (i.e pollset or pollset_set), then
@@ -1445,7 +1445,7 @@ retry:
/* Need to reverify any assumptions made between the initial lock and
getting to this branch: if they've changed, we need to throw away our
work and figure things out again. */
- if (item->pi != NULL) {
+ if (item->pi != nullptr) {
GRPC_POLLING_TRACE(
"add_poll_object: Raced creating new polling island. pi_new: %p "
"(fd: %d, %s: %p)",
@@ -1462,7 +1462,7 @@ retry:
goto retry;
}
} else {
- pi_new = polling_island_create(NULL, &error);
+ pi_new = polling_island_create(nullptr, &error);
}
GRPC_POLLING_TRACE(
@@ -1475,7 +1475,7 @@ retry:
"add_poll_object: Same polling island. pi: %p (%s, %s)",
(void*)pi_new, poll_obj_string(item_type), poll_obj_string(bag_type));
}
- } else if (item->pi == NULL) {
+ } else if (item->pi == nullptr) {
/* GPR_ASSERT(bag->pi != NULL) */
/* Make pi_new point to latest pi*/
pi_new = polling_island_lock(bag->pi);
@@ -1491,7 +1491,7 @@ retry:
"bag(%s): %p)",
(void*)pi_new, poll_obj_string(item_type), (void*)item,
poll_obj_string(bag_type), (void*)bag);
- } else if (bag->pi == NULL) {
+ } else if (bag->pi == nullptr) {
/* GPR_ASSERT(item->pi != NULL) */
/* Make pi_new to point to latest pi */
pi_new = polling_island_lock(item->pi);
@@ -1515,7 +1515,7 @@ retry:
if (item->pi != pi_new) {
PI_ADD_REF(pi_new, poll_obj_string(item_type));
- if (item->pi != NULL) {
+ if (item->pi != nullptr) {
PI_UNREF(item->pi, poll_obj_string(item_type));
}
item->pi = pi_new;
@@ -1523,7 +1523,7 @@ retry:
if (bag->pi != pi_new) {
PI_ADD_REF(pi_new, poll_obj_string(bag_type));
- if (bag->pi != NULL) {
+ if (bag->pi != nullptr) {
PI_UNREF(bag->pi, poll_obj_string(bag_type));
}
bag->pi = pi_new;
@@ -1547,7 +1547,7 @@ static void pollset_add_fd(grpc_pollset* pollset, grpc_fd* fd) {
static grpc_pollset_set* pollset_set_create(void) {
grpc_pollset_set* pss = (grpc_pollset_set*)gpr_malloc(sizeof(*pss));
gpr_mu_init(&pss->po.mu);
- pss->po.pi = NULL;
+ pss->po.pi = nullptr;
#ifndef NDEBUG
pss->po.obj_type = POLL_OBJ_POLLSET_SET;
#endif
@@ -1557,7 +1557,7 @@ static grpc_pollset_set* pollset_set_create(void) {
static void pollset_set_destroy(grpc_pollset_set* pss) {
gpr_mu_destroy(&pss->po.mu);
- if (pss->po.pi != NULL) {
+ if (pss->po.pi != nullptr) {
PI_UNREF(pss->po.pi, "pss_destroy");
}
@@ -1686,17 +1686,17 @@ const grpc_event_engine_vtable* grpc_init_epollsig_linux(
/* If use of signals is disabled, we cannot use epoll engine*/
if (is_grpc_wakeup_signal_initialized && grpc_wakeup_signal < 0) {
gpr_log(GPR_ERROR, "Skipping epollsig because use of signals is disabled.");
- return NULL;
+ return nullptr;
}
if (!grpc_has_wakeup_fd()) {
gpr_log(GPR_ERROR, "Skipping epollsig because of no wakeup fd.");
- return NULL;
+ return nullptr;
}
if (!is_epoll_available()) {
gpr_log(GPR_ERROR, "Skipping epollsig because epoll is unavailable.");
- return NULL;
+ return nullptr;
}
if (!is_grpc_wakeup_signal_initialized) {
@@ -1705,19 +1705,19 @@ const grpc_event_engine_vtable* grpc_init_epollsig_linux(
} else {
gpr_log(GPR_ERROR,
"Skipping epollsig because uninitialized wakeup signal.");
- return NULL;
+ return nullptr;
}
}
fd_global_init();
if (!GRPC_LOG_IF_ERROR("pollset_global_init", pollset_global_init())) {
- return NULL;
+ return nullptr;
}
if (!GRPC_LOG_IF_ERROR("polling_island_global_init",
polling_island_global_init())) {
- return NULL;
+ return nullptr;
}
return &vtable;
@@ -1732,7 +1732,7 @@ const grpc_event_engine_vtable* grpc_init_epollsig_linux(
bool explicit_request) {
gpr_log(GPR_ERROR,
"Skipping epollsig becuase GRPC_LINUX_EPOLL is not defined.");
- return NULL;
+ return nullptr;
}
#endif /* defined(GRPC_POSIX_SOCKET) */
diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc
index b6546aa4b4..09ebe894fa 100644
--- a/src/core/lib/iomgr/ev_poll_posix.cc
+++ b/src/core/lib/iomgr/ev_poll_posix.cc
@@ -331,11 +331,11 @@ static grpc_fd* fd_create(int fd, const char* name) {
r->fd = fd;
r->inactive_watcher_root.next = r->inactive_watcher_root.prev =
&r->inactive_watcher_root;
- r->read_watcher = r->write_watcher = NULL;
- r->on_done_closure = NULL;
+ r->read_watcher = r->write_watcher = nullptr;
+ r->on_done_closure = nullptr;
r->closed = 0;
r->released = 0;
- r->read_notifier_pollset = NULL;
+ r->read_notifier_pollset = nullptr;
char* name2;
gpr_asprintf(&name2, "%s fd=%d", name, fd);
@@ -350,7 +350,7 @@ static bool fd_is_orphaned(grpc_fd* fd) {
/* Return the read-notifier pollset */
static grpc_pollset* fd_get_read_notifier_pollset(grpc_fd* fd) {
- grpc_pollset* notifier = NULL;
+ grpc_pollset* notifier = nullptr;
gpr_mu_lock(&fd->mu);
notifier = fd->read_notifier_pollset;
@@ -393,7 +393,7 @@ static void wake_all_watchers_locked(grpc_fd* fd) {
}
static int has_watchers(grpc_fd* fd) {
- return fd->read_watcher != NULL || fd->write_watcher != NULL ||
+ return fd->read_watcher != nullptr || fd->write_watcher != nullptr ||
fd->inactive_watcher_root.next != &fd->inactive_watcher_root;
}
@@ -416,8 +416,8 @@ static int fd_wrapped_fd(grpc_fd* fd) {
static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd,
bool already_closed, const char* reason) {
fd->on_done_closure = on_done;
- fd->released = release_fd != NULL;
- if (release_fd != NULL) {
+ fd->released = release_fd != nullptr;
+ if (release_fd != nullptr) {
*release_fd = fd->fd;
fd->released = true;
} else if (already_closed) {
@@ -553,9 +553,9 @@ static uint32_t fd_begin_poll(grpc_fd* fd, grpc_pollset* pollset,
/* if we are shutdown, then don't add to the watcher set */
if (fd->shutdown) {
- watcher->fd = NULL;
- watcher->pollset = NULL;
- watcher->worker = NULL;
+ watcher->fd = nullptr;
+ watcher->pollset = nullptr;
+ watcher->worker = nullptr;
gpr_mu_unlock(&fd->mu);
GRPC_FD_UNREF(fd, "poll");
return 0;
@@ -564,7 +564,7 @@ static uint32_t fd_begin_poll(grpc_fd* fd, grpc_pollset* pollset,
/* if there is nobody polling for read, but we need to, then start doing so */
cur = fd->read_closure;
requested = cur != CLOSURE_READY;
- if (read_mask && fd->read_watcher == NULL && requested) {
+ if (read_mask && fd->read_watcher == nullptr && requested) {
fd->read_watcher = watcher;
mask |= read_mask;
}
@@ -572,12 +572,12 @@ static uint32_t fd_begin_poll(grpc_fd* fd, grpc_pollset* pollset,
*/
cur = fd->write_closure;
requested = cur != CLOSURE_READY;
- if (write_mask && fd->write_watcher == NULL && requested) {
+ if (write_mask && fd->write_watcher == nullptr && requested) {
fd->write_watcher = watcher;
mask |= write_mask;
}
/* if not polling, remember this watcher in case we need someone to later */
- if (mask == 0 && worker != NULL) {
+ if (mask == 0 && worker != nullptr) {
watcher->next = &fd->inactive_watcher_root;
watcher->prev = watcher->next->prev;
watcher->next->prev = watcher->prev->next = watcher;
@@ -596,7 +596,7 @@ static void fd_end_poll(grpc_fd_watcher* watcher, int got_read, int got_write,
int kick = 0;
grpc_fd* fd = watcher->fd;
- if (fd == NULL) {
+ if (fd == nullptr) {
return;
}
@@ -608,7 +608,7 @@ static void fd_end_poll(grpc_fd_watcher* watcher, int got_read, int got_write,
if (!got_read) {
kick = 1;
}
- fd->read_watcher = NULL;
+ fd->read_watcher = nullptr;
}
if (watcher == fd->write_watcher) {
/* remove write watcher, kick if we still need a write */
@@ -616,9 +616,9 @@ static void fd_end_poll(grpc_fd_watcher* watcher, int got_read, int got_write,
if (!got_write) {
kick = 1;
}
- fd->write_watcher = NULL;
+ fd->write_watcher = nullptr;
}
- if (!was_polling && watcher->worker != NULL) {
+ if (!was_polling && watcher->worker != nullptr) {
/* remove from inactive list */
watcher->next->prev = watcher->prev;
watcher->prev->next = watcher->next;
@@ -627,7 +627,7 @@ static void fd_end_poll(grpc_fd_watcher* watcher, int got_read, int got_write,
if (set_ready_locked(fd, &fd->read_closure)) {
kick = 1;
}
- if (read_notifier_pollset != NULL) {
+ if (read_notifier_pollset != nullptr) {
set_read_notifier_pollset_locked(fd, read_notifier_pollset);
}
}
@@ -677,7 +677,7 @@ static grpc_pollset_worker* pop_front_worker(grpc_pollset* p) {
remove_worker(p, w);
return w;
} else {
- return NULL;
+ return nullptr;
}
}
@@ -709,7 +709,7 @@ static grpc_error* pollset_kick_ext(grpc_pollset* p,
GRPC_STATS_INC_POLLSET_KICK();
/* pollset->mu already held */
- if (specific_worker != NULL) {
+ if (specific_worker != nullptr) {
if (specific_worker == GRPC_POLLSET_KICK_BROADCAST) {
GPR_TIMER_BEGIN("pollset_kick_ext.broadcast", 0);
GPR_ASSERT((flags & GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP) == 0);
@@ -743,7 +743,7 @@ static grpc_error* pollset_kick_ext(grpc_pollset* p,
GPR_ASSERT((flags & GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP) == 0);
GPR_TIMER_MARK("kick_anonymous", 0);
specific_worker = pop_front_worker(p);
- if (specific_worker != NULL) {
+ if (specific_worker != nullptr) {
if (gpr_tls_get(&g_current_thread_worker) == (intptr_t)specific_worker) {
GPR_TIMER_MARK("kick_anonymous_not_self", 0);
push_back_worker(p, specific_worker);
@@ -752,10 +752,10 @@ static grpc_error* pollset_kick_ext(grpc_pollset* p,
gpr_tls_get(&g_current_thread_worker) ==
(intptr_t)specific_worker) {
push_back_worker(p, specific_worker);
- specific_worker = NULL;
+ specific_worker = nullptr;
}
}
- if (specific_worker != NULL) {
+ if (specific_worker != nullptr) {
GPR_TIMER_MARK("finally_kick", 0);
push_back_worker(p, specific_worker);
kick_append_error(
@@ -799,12 +799,12 @@ static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) {
pollset->shutting_down = 0;
pollset->called_shutdown = 0;
pollset->kicked_without_pollers = 0;
- pollset->idle_jobs.head = pollset->idle_jobs.tail = NULL;
- pollset->local_wakeup_cache = NULL;
+ pollset->idle_jobs.head = pollset->idle_jobs.tail = nullptr;
+ pollset->local_wakeup_cache = nullptr;
pollset->kicked_without_pollers = 0;
pollset->fd_count = 0;
pollset->fd_capacity = 0;
- pollset->fds = NULL;
+ pollset->fds = nullptr;
pollset->pollset_set_count = 0;
}
@@ -836,7 +836,7 @@ static void pollset_add_fd(grpc_pollset* pollset, grpc_fd* fd) {
}
pollset->fds[pollset->fd_count++] = fd;
GRPC_FD_REF(fd, "multipoller");
- pollset_kick(pollset, NULL);
+ pollset_kick(pollset, nullptr);
exit:
gpr_mu_unlock(&pollset->mu);
}
@@ -878,9 +878,9 @@ static grpc_error* pollset_work(grpc_pollset* pollset,
int keep_polling = 0;
GPR_TIMER_BEGIN("pollset_work", 0);
/* this must happen before we (potentially) drop pollset->mu */
- worker.next = worker.prev = NULL;
+ worker.next = worker.prev = nullptr;
worker.reevaluate_polling_on_wakeup = 0;
- if (pollset->local_wakeup_cache != NULL) {
+ if (pollset->local_wakeup_cache != nullptr) {
worker.wakeup_fd = pollset->local_wakeup_cache;
pollset->local_wakeup_cache = worker.wakeup_fd->next;
} else {
@@ -988,8 +988,8 @@ static grpc_error* pollset_work(grpc_pollset* pollset,
}
for (i = 1; i < pfd_count; i++) {
- if (watchers[i].fd == NULL) {
- fd_end_poll(&watchers[i], 0, 0, NULL);
+ if (watchers[i].fd == nullptr) {
+ fd_end_poll(&watchers[i], 0, 0, nullptr);
} else {
// Wake up all the file descriptors, if we have an invalid one
// we can identify it on the next pollset_work()
@@ -998,7 +998,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset,
}
} else if (r == 0) {
for (i = 1; i < pfd_count; i++) {
- fd_end_poll(&watchers[i], 0, 0, NULL);
+ fd_end_poll(&watchers[i], 0, 0, nullptr);
}
} else {
if (pfds[0].revents & POLLIN_CHECK) {
@@ -1009,8 +1009,8 @@ static grpc_error* pollset_work(grpc_pollset* pollset,
&error, grpc_wakeup_fd_consume_wakeup(&worker.wakeup_fd->fd));
}
for (i = 1; i < pfd_count; i++) {
- if (watchers[i].fd == NULL) {
- fd_end_poll(&watchers[i], 0, 0, NULL);
+ if (watchers[i].fd == nullptr) {
+ fd_end_poll(&watchers[i], 0, 0, nullptr);
} else {
if (GRPC_TRACER_ON(grpc_polling_trace)) {
gpr_log(GPR_DEBUG, "%p got_event: %d r:%d w:%d [%d]", pollset,
@@ -1069,7 +1069,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset,
/* check shutdown conditions */
if (pollset->shutting_down) {
if (pollset_has_workers(pollset)) {
- pollset_kick(pollset, NULL);
+ pollset_kick(pollset, nullptr);
} else if (!pollset->called_shutdown && !pollset_has_observers(pollset)) {
pollset->called_shutdown = 1;
gpr_mu_unlock(&pollset->mu);
@@ -1087,7 +1087,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset,
gpr_mu_lock(&pollset->mu);
}
}
- if (worker_hdl) *worker_hdl = NULL;
+ if (worker_hdl) *worker_hdl = nullptr;
GPR_TIMER_END("pollset_work", 0);
GRPC_LOG_IF_ERROR("pollset_work", GRPC_ERROR_REF(error));
return error;
@@ -1296,7 +1296,7 @@ static void cache_insert_locked(poll_args* args) {
poll_cache.active_pollers[key]->prev = args;
}
args->next = poll_cache.active_pollers[key];
- args->prev = NULL;
+ args->prev = nullptr;
poll_cache.active_pollers[key] = args;
poll_cache.count++;
}
@@ -1304,7 +1304,7 @@ static void cache_insert_locked(poll_args* args) {
static void init_result(poll_args* pargs) {
pargs->result = (poll_result*)gpr_malloc(sizeof(poll_result));
gpr_ref_init(&pargs->result->refcount, 1);
- pargs->result->watchers = NULL;
+ pargs->result->watchers = nullptr;
pargs->result->watchcount = 0;
pargs->result->fds =
(struct pollfd*)gpr_malloc(sizeof(struct pollfd) * pargs->nfds);
@@ -1335,12 +1335,12 @@ static poll_args* get_poller_locked(struct pollfd* fds, nfds_t count) {
poll_args* pargs = poll_cache.free_pollers;
poll_cache.free_pollers = pargs->next;
if (poll_cache.free_pollers) {
- poll_cache.free_pollers->prev = NULL;
+ poll_cache.free_pollers->prev = nullptr;
}
pargs->fds = fds;
pargs->nfds = count;
- pargs->next = NULL;
- pargs->prev = NULL;
+ pargs->next = nullptr;
+ pargs->prev = nullptr;
init_result(pargs);
cache_poller_locked(pargs);
return pargs;
@@ -1350,8 +1350,8 @@ static poll_args* get_poller_locked(struct pollfd* fds, nfds_t count) {
gpr_cv_init(&pargs->trigger);
pargs->fds = fds;
pargs->nfds = count;
- pargs->next = NULL;
- pargs->prev = NULL;
+ pargs->next = nullptr;
+ pargs->prev = nullptr;
pargs->trigger_set = 0;
init_result(pargs);
cache_poller_locked(pargs);
@@ -1382,7 +1382,7 @@ static void cache_delete_locked(poll_args* args) {
if (poll_cache.free_pollers) {
poll_cache.free_pollers->prev = args;
}
- args->prev = NULL;
+ args->prev = nullptr;
args->next = poll_cache.free_pollers;
gpr_free(args->fds);
poll_cache.free_pollers = args;
@@ -1396,11 +1396,11 @@ static void cache_poller_locked(poll_args* args) {
poll_cache.active_pollers =
(poll_args**)gpr_malloc(sizeof(void*) * poll_cache.size);
for (unsigned int i = 0; i < poll_cache.size; i++) {
- poll_cache.active_pollers[i] = NULL;
+ poll_cache.active_pollers[i] = nullptr;
}
for (unsigned int i = 0; i < poll_cache.size / 2; i++) {
poll_args* curr = old_active_pollers[i];
- poll_args* next = NULL;
+ poll_args* next = nullptr;
while (curr) {
next = curr->next;
cache_insert_locked(curr);
@@ -1497,10 +1497,10 @@ static int cvfd_poll(struct pollfd* fds, nfds_t nfds, int timeout) {
cv_node* pollcv;
int skip_poll = 0;
nfds_t nsockfds = 0;
- poll_result* result = NULL;
+ poll_result* result = nullptr;
gpr_mu_lock(&g_cvfds.mu);
pollcv = (cv_node*)gpr_malloc(sizeof(cv_node));
- pollcv->next = NULL;
+ pollcv->next = nullptr;
gpr_cv pollcv_cv;
gpr_cv_init(&pollcv_cv);
pollcv->cv = &pollcv_cv;
@@ -1511,7 +1511,7 @@ static int cvfd_poll(struct pollfd* fds, nfds_t nfds, int timeout) {
if (fds[i].fd < 0 && (fds[i].events & POLLIN)) {
idx = GRPC_FD_TO_IDX(fds[i].fd);
fd_cvs[i].cv = &pollcv_cv;
- fd_cvs[i].prev = NULL;
+ fd_cvs[i].prev = nullptr;
fd_cvs[i].next = g_cvfds.cvfds[idx].cvs;
if (g_cvfds.cvfds[idx].cvs) {
g_cvfds.cvfds[idx].cvs->prev = &(fd_cvs[i]);
@@ -1550,7 +1550,7 @@ static int cvfd_poll(struct pollfd* fds, nfds_t nfds, int timeout) {
poll_args* pargs = get_poller_locked(pollfds, nsockfds);
result = pargs->result;
pollcv->next = result->watchers;
- pollcv->prev = NULL;
+ pollcv->prev = nullptr;
if (result->watchers) {
result->watchers->prev = pollcv;
}
@@ -1601,11 +1601,11 @@ static void global_cv_fd_table_init() {
gpr_ref_init(&g_cvfds.pollcount, 1);
g_cvfds.size = CV_DEFAULT_TABLE_SIZE;
g_cvfds.cvfds = (fd_node*)gpr_malloc(sizeof(fd_node) * CV_DEFAULT_TABLE_SIZE);
- g_cvfds.free_fds = NULL;
+ g_cvfds.free_fds = nullptr;
thread_grace = gpr_time_from_millis(POLLCV_THREAD_GRACE_MS, GPR_TIMESPAN);
for (int i = 0; i < CV_DEFAULT_TABLE_SIZE; i++) {
g_cvfds.cvfds[i].is_set = 0;
- g_cvfds.cvfds[i].cvs = NULL;
+ g_cvfds.cvfds[i].cvs = nullptr;
g_cvfds.cvfds[i].next_free = g_cvfds.free_fds;
g_cvfds.free_fds = &g_cvfds.cvfds[i];
}
@@ -1616,10 +1616,10 @@ static void global_cv_fd_table_init() {
// Initialize the cache
poll_cache.size = 32;
poll_cache.count = 0;
- poll_cache.free_pollers = NULL;
+ poll_cache.free_pollers = nullptr;
poll_cache.active_pollers = (poll_args**)gpr_malloc(sizeof(void*) * 32);
for (unsigned int i = 0; i < poll_cache.size; i++) {
- poll_cache.active_pollers[i] = NULL;
+ poll_cache.active_pollers[i] = nullptr;
}
gpr_mu_unlock(&g_cvfds.mu);
@@ -1690,10 +1690,10 @@ static const grpc_event_engine_vtable vtable = {
const grpc_event_engine_vtable* grpc_init_poll_posix(bool explicit_request) {
if (!grpc_has_wakeup_fd()) {
gpr_log(GPR_ERROR, "Skipping poll because of no wakeup fd.");
- return NULL;
+ return nullptr;
}
if (!GRPC_LOG_IF_ERROR("pollset_global_init", pollset_global_init())) {
- return NULL;
+ return nullptr;
}
return &vtable;
}
@@ -1704,7 +1704,7 @@ const grpc_event_engine_vtable* grpc_init_poll_cv_posix(bool explicit_request) {
if (!GRPC_LOG_IF_ERROR("pollset_global_init", pollset_global_init())) {
global_cv_fd_table_shutdown();
grpc_enable_cv_wakeup_fds(0);
- return NULL;
+ return nullptr;
}
return &vtable;
}
diff --git a/src/core/lib/iomgr/ev_posix.cc b/src/core/lib/iomgr/ev_posix.cc
index 9f84f67e5c..985469942f 100644
--- a/src/core/lib/iomgr/ev_posix.cc
+++ b/src/core/lib/iomgr/ev_posix.cc
@@ -51,7 +51,7 @@ grpc_poll_function_type grpc_poll_function = poll;
grpc_wakeup_fd grpc_global_wakeup_fd;
static const grpc_event_engine_vtable* g_event_engine;
-static const char* g_poll_strategy_name = NULL;
+static const char* g_poll_strategy_name = nullptr;
typedef const grpc_event_engine_vtable* (*event_engine_factory_fn)(
bool explicit_request);
@@ -114,7 +114,7 @@ static void add(const char* beg, const char* end, char*** ss, size_t* ns) {
static void split(const char* s, char*** ss, size_t* ns) {
const char* c = strchr(s, ',');
- if (c == NULL) {
+ if (c == nullptr) {
add(s, s + strlen(s), ss, ns);
} else {
add(s, c, ss, ns);
@@ -156,15 +156,15 @@ void grpc_event_engine_init(void) {
grpc_register_tracer(&grpc_polling_trace);
char* s = gpr_getenv("GRPC_POLL_STRATEGY");
- if (s == NULL) {
+ if (s == nullptr) {
s = gpr_strdup("all");
}
- char** strings = NULL;
+ char** strings = nullptr;
size_t nstrings = 0;
split(s, &strings, &nstrings);
- for (size_t i = 0; g_event_engine == NULL && i < nstrings; i++) {
+ for (size_t i = 0; g_event_engine == nullptr && i < nstrings; i++) {
try_engine(strings[i]);
}
@@ -173,7 +173,7 @@ void grpc_event_engine_init(void) {
}
gpr_free(strings);
- if (g_event_engine == NULL) {
+ if (g_event_engine == nullptr) {
gpr_log(GPR_ERROR, "No event engine could be initialized from %s", s);
abort();
}
@@ -182,7 +182,7 @@ void grpc_event_engine_init(void) {
void grpc_event_engine_shutdown(void) {
g_event_engine->shutdown_engine();
- g_event_engine = NULL;
+ g_event_engine = nullptr;
}
grpc_fd* grpc_fd_create(int fd, const char* name) {
diff --git a/src/core/lib/iomgr/exec_ctx.cc b/src/core/lib/iomgr/exec_ctx.cc
index de71c1cf9c..8a4b489ebb 100644
--- a/src/core/lib/iomgr/exec_ctx.cc
+++ b/src/core/lib/iomgr/exec_ctx.cc
@@ -25,7 +25,10 @@
#include "src/core/lib/iomgr/combiner.h"
#include "src/core/lib/profiling/timers.h"
-void exec_ctx_run(grpc_closure* closure, grpc_error* error) {
+#define GRPC_START_TIME_UPDATE_INTERVAL 10000
+extern "C" grpc_tracer_flag grpc_timer_check_trace;
+
+static void exec_ctx_run(grpc_closure* closure, grpc_error* error) {
#ifndef NDEBUG
closure->scheduled = false;
if (GRPC_TRACER_ON(grpc_trace_closure)) {
@@ -44,18 +47,44 @@ void exec_ctx_run(grpc_closure* closure, grpc_error* error) {
GRPC_ERROR_UNREF(error);
}
-static gpr_timespec
+static void exec_ctx_sched(grpc_closure* closure, grpc_error* error) {
+ grpc_closure_list_append(grpc_core::ExecCtx::Get()->closure_list(), closure,
+ error);
+}
+
+/* This time pair is not entirely thread-safe as store/load of tv_sec and
+ * tv_nsec are performed separately. However g_start_time do not need to have
+ * sub-second precision, so it is ok if the value of tv_nsec is off in this
+ * case. */
+typedef struct time_atm_pair {
+ gpr_atm tv_sec;
+ gpr_atm tv_nsec;
+} time_atm_pair;
+
+static time_atm_pair
g_start_time[GPR_TIMESPAN + 1]; // assumes GPR_TIMESPAN is the
// last enum value in
// gpr_clock_type
+static grpc_millis g_last_start_time_update;
+
+static gpr_timespec timespec_from_time_atm_pair(const time_atm_pair* src,
+ gpr_clock_type clock_type) {
+ gpr_timespec time;
+ time.tv_nsec = (int32_t)gpr_atm_no_barrier_load(&src->tv_nsec);
+ time.tv_sec = (int64_t)gpr_atm_no_barrier_load(&src->tv_sec);
+ time.clock_type = clock_type;
+ return time;
+}
-void exec_ctx_sched(grpc_closure* closure, grpc_error* error) {
- grpc_closure_list_append(grpc_core::ExecCtx::Get()->closure_list(), closure,
- error);
+static void time_atm_pair_store(time_atm_pair* dst, const gpr_timespec src) {
+ gpr_atm_no_barrier_store(&dst->tv_sec, src.tv_sec);
+ gpr_atm_no_barrier_store(&dst->tv_nsec, src.tv_nsec);
}
static gpr_atm timespec_to_atm_round_down(gpr_timespec ts) {
- ts = gpr_time_sub(ts, g_start_time[ts.clock_type]);
+ gpr_timespec start_time =
+ timespec_from_time_atm_pair(&g_start_time[ts.clock_type], ts.clock_type);
+ ts = gpr_time_sub(ts, start_time);
double x =
GPR_MS_PER_SEC * (double)ts.tv_sec + (double)ts.tv_nsec / GPR_NS_PER_MS;
if (x < 0) return 0;
@@ -64,7 +93,9 @@ static gpr_atm timespec_to_atm_round_down(gpr_timespec ts) {
}
static gpr_atm timespec_to_atm_round_up(gpr_timespec ts) {
- ts = gpr_time_sub(ts, g_start_time[ts.clock_type]);
+ gpr_timespec start_time =
+ timespec_from_time_atm_pair(&g_start_time[ts.clock_type], ts.clock_type);
+ ts = gpr_time_sub(ts, start_time);
double x = GPR_MS_PER_SEC * (double)ts.tv_sec +
(double)ts.tv_nsec / GPR_NS_PER_MS +
(double)(GPR_NS_PER_SEC - 1) / (double)GPR_NS_PER_SEC;
@@ -87,8 +118,9 @@ gpr_timespec grpc_millis_to_timespec(grpc_millis millis,
if (clock_type == GPR_TIMESPAN) {
return gpr_time_from_millis(millis, GPR_TIMESPAN);
}
- return gpr_time_add(g_start_time[clock_type],
- gpr_time_from_millis(millis, GPR_TIMESPAN));
+ gpr_timespec start_time =
+ timespec_from_time_atm_pair(&g_start_time[clock_type], clock_type);
+ return gpr_time_add(start_time, gpr_time_from_millis(millis, GPR_TIMESPAN));
}
grpc_millis grpc_timespec_to_millis_round_down(gpr_timespec ts) {
@@ -99,6 +131,30 @@ grpc_millis grpc_timespec_to_millis_round_up(gpr_timespec ts) {
return timespec_to_atm_round_up(ts);
}
+void grpc_exec_ctx_maybe_update_start_time() {
+ grpc_millis now = grpc_core::ExecCtx::Get()->Now();
+ grpc_millis last_start_time_update =
+ gpr_atm_no_barrier_load(&g_last_start_time_update);
+
+ if (now > last_start_time_update &&
+ now - last_start_time_update > GRPC_START_TIME_UPDATE_INTERVAL) {
+ /* Get the current system time and subtract \a now from it, where \a now is
+ * the relative time from grpc_init() from monotonic clock. This calibrates
+ * the time when grpc_exec_ctx_global_init was called based on current
+ * system clock. */
+ gpr_atm_no_barrier_store(&g_last_start_time_update, now);
+ gpr_timespec real_now = gpr_now(GPR_CLOCK_REALTIME);
+ gpr_timespec real_start_time =
+ gpr_time_sub(real_now, gpr_time_from_millis(now, GPR_TIMESPAN));
+ time_atm_pair_store(&g_start_time[GPR_CLOCK_REALTIME], real_start_time);
+
+ if (GRPC_TRACER_ON(grpc_timer_check_trace)) {
+ gpr_log(GPR_DEBUG, "Update realtime clock start time: %" PRId64 "s %dns",
+ real_start_time.tv_sec, real_start_time.tv_nsec);
+ }
+ }
+}
+
static const grpc_closure_scheduler_vtable exec_ctx_scheduler_vtable = {
exec_ctx_run, exec_ctx_sched, "exec_ctx"};
static grpc_closure_scheduler exec_ctx_scheduler = {&exec_ctx_scheduler_vtable};
@@ -113,8 +169,8 @@ bool ExecCtx::Flush() {
for (;;) {
if (!grpc_closure_list_empty(closure_list_)) {
grpc_closure* c = closure_list_.head;
- closure_list_.head = closure_list_.tail = NULL;
- while (c != NULL) {
+ closure_list_.head = closure_list_.tail = nullptr;
+ while (c != nullptr) {
grpc_closure* next = c->next_data.next;
grpc_error* error = c->error_data.error;
did_something = true;
@@ -132,10 +188,10 @@ bool ExecCtx::Flush() {
void ExecCtx::GlobalInit(void) {
for (int i = 0; i < GPR_TIMESPAN; i++) {
- g_start_time[i] = gpr_now((gpr_clock_type)i);
+ time_atm_pair_store(&g_start_time[i], gpr_now((gpr_clock_type)i));
}
// allows uniform treatment in conversion functions
- g_start_time[GPR_TIMESPAN] = gpr_time_0(GPR_TIMESPAN);
+ time_atm_pair_store(&g_start_time[GPR_TIMESPAN], gpr_time_0(GPR_TIMESPAN));
}
void ExecCtx::GlobalShutdown(void) {}
diff --git a/src/core/lib/iomgr/exec_ctx.h b/src/core/lib/iomgr/exec_ctx.h
index 7b8da2f0af..0f2ee8d4fa 100644
--- a/src/core/lib/iomgr/exec_ctx.h
+++ b/src/core/lib/iomgr/exec_ctx.h
@@ -192,6 +192,8 @@ gpr_timespec grpc_millis_to_timespec(grpc_millis millis, gpr_clock_type clock);
grpc_millis grpc_timespec_to_millis_round_down(gpr_timespec timespec);
grpc_millis grpc_timespec_to_millis_round_up(gpr_timespec timespec);
+void grpc_exec_ctx_maybe_update_start_time();
+
#ifdef __cplusplus
}
#endif
diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc
index d26b89aea3..12f336cb37 100644
--- a/src/core/lib/iomgr/executor.cc
+++ b/src/core/lib/iomgr/executor.cc
@@ -60,7 +60,7 @@ static size_t run_closures(grpc_closure_list list) {
size_t n = 0;
grpc_closure* c = list.head;
- while (c != NULL) {
+ while (c != nullptr) {
grpc_closure* next = c->next_data.next;
grpc_error* error = c->error_data.error;
if (GRPC_TRACER_ON(executor_trace)) {
@@ -205,7 +205,7 @@ static void executor_push(grpc_closure* closure, grpc_error* error,
return;
}
thread_state* ts = (thread_state*)gpr_tls_get(&g_this_thread_state);
- if (ts == NULL) {
+ if (ts == nullptr) {
ts = &g_thread_state[GPR_HASH_POINTER(grpc_core::ExecCtx::Get(),
cur_thread_count)];
} else {
diff --git a/src/core/lib/iomgr/gethostname_host_name_max.cc b/src/core/lib/iomgr/gethostname_host_name_max.cc
index 987ff1eac1..2487160916 100644
--- a/src/core/lib/iomgr/gethostname_host_name_max.cc
+++ b/src/core/lib/iomgr/gethostname_host_name_max.cc
@@ -30,7 +30,7 @@ char* grpc_gethostname() {
char* hostname = (char*)gpr_malloc(HOST_NAME_MAX);
if (gethostname(hostname, HOST_NAME_MAX) != 0) {
gpr_free(hostname);
- return NULL;
+ return nullptr;
}
return hostname;
}
diff --git a/src/core/lib/iomgr/iocp_windows.h b/src/core/lib/iomgr/iocp_windows.h
index 51dcd98b94..4e6f6ed106 100644
--- a/src/core/lib/iomgr/iocp_windows.h
+++ b/src/core/lib/iomgr/iocp_windows.h
@@ -21,6 +21,10 @@
#include <grpc/support/sync.h>
+#include "src/core/lib/iomgr/port.h"
+
+#ifdef GRPC_WINSOCK_SOCKET
+
#include "src/core/lib/iomgr/socket_windows.h"
#ifdef __cplusplus
@@ -44,4 +48,6 @@ void grpc_iocp_add_socket(grpc_winsocket*);
}
#endif
+#endif
+
#endif /* GRPC_CORE_LIB_IOMGR_IOCP_WINDOWS_H */
diff --git a/src/core/lib/iomgr/iomgr.cc b/src/core/lib/iomgr/iomgr.cc
index 9c74b5d1c3..f3f080e315 100644
--- a/src/core/lib/iomgr/iomgr.cc
+++ b/src/core/lib/iomgr/iomgr.cc
@@ -99,7 +99,7 @@ void grpc_iomgr_shutdown() {
last_warning_time = gpr_now(GPR_CLOCK_REALTIME);
}
grpc_core::ExecCtx::Get()->SetNowIomgrShutdown();
- if (grpc_timer_check(NULL) == GRPC_TIMERS_FIRED) {
+ if (grpc_timer_check(nullptr) == GRPC_TIMERS_FIRED) {
gpr_mu_unlock(&g_mu);
grpc_core::ExecCtx::Get()->Flush();
grpc_iomgr_platform_flush();
diff --git a/src/core/lib/iomgr/is_epollexclusive_available.cc b/src/core/lib/iomgr/is_epollexclusive_available.cc
index d08844c0df..e5803532e7 100644
--- a/src/core/lib/iomgr/is_epollexclusive_available.cc
+++ b/src/core/lib/iomgr/is_epollexclusive_available.cc
@@ -62,7 +62,7 @@ bool grpc_is_epollexclusive_available(void) {
EPOLLEXCLUSIVE enabled kernels - specifically the combination of
EPOLLONESHOT and EPOLLEXCLUSIVE */
ev.events = (uint32_t)(EPOLLET | EPOLLIN | EPOLLEXCLUSIVE | EPOLLONESHOT);
- ev.data.ptr = NULL;
+ ev.data.ptr = nullptr;
if (epoll_ctl(fd, EPOLL_CTL_ADD, evfd, &ev) != 0) {
if (errno != EINVAL) {
if (!logged_why_not) {
diff --git a/src/core/lib/iomgr/load_file.cc b/src/core/lib/iomgr/load_file.cc
index feef65cc34..03ed98f3ba 100644
--- a/src/core/lib/iomgr/load_file.cc
+++ b/src/core/lib/iomgr/load_file.cc
@@ -30,7 +30,7 @@
grpc_error* grpc_load_file(const char* filename, int add_null_terminator,
grpc_slice* output) {
- unsigned char* contents = NULL;
+ unsigned char* contents = nullptr;
size_t contents_size = 0;
grpc_slice result = grpc_empty_slice();
FILE* file;
@@ -39,7 +39,7 @@ grpc_error* grpc_load_file(const char* filename, int add_null_terminator,
GRPC_SCHEDULING_START_BLOCKING_REGION;
file = fopen(filename, "rb");
- if (file == NULL) {
+ if (file == nullptr) {
error = GRPC_OS_ERROR(errno, "fopen");
goto end;
}
@@ -62,7 +62,7 @@ grpc_error* grpc_load_file(const char* filename, int add_null_terminator,
end:
*output = result;
- if (file != NULL) fclose(file);
+ if (file != nullptr) fclose(file);
if (error != GRPC_ERROR_NONE) {
grpc_error* error_out =
grpc_error_set_str(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
diff --git a/src/core/lib/iomgr/polling_entity.cc b/src/core/lib/iomgr/polling_entity.cc
index b6f7d79e25..126f6f45d6 100644
--- a/src/core/lib/iomgr/polling_entity.cc
+++ b/src/core/lib/iomgr/polling_entity.cc
@@ -41,7 +41,7 @@ grpc_pollset* grpc_polling_entity_pollset(grpc_polling_entity* pollent) {
if (pollent->tag == GRPC_POLLS_POLLSET) {
return pollent->pollent.pollset;
}
- return NULL;
+ return nullptr;
}
grpc_pollset_set* grpc_polling_entity_pollset_set(
@@ -49,7 +49,7 @@ grpc_pollset_set* grpc_polling_entity_pollset_set(
if (pollent->tag == GRPC_POLLS_POLLSET_SET) {
return pollent->pollent.pollset_set;
}
- return NULL;
+ return nullptr;
}
bool grpc_polling_entity_is_empty(const grpc_polling_entity* pollent) {
@@ -59,10 +59,10 @@ bool grpc_polling_entity_is_empty(const grpc_polling_entity* pollent) {
void grpc_polling_entity_add_to_pollset_set(grpc_polling_entity* pollent,
grpc_pollset_set* pss_dst) {
if (pollent->tag == GRPC_POLLS_POLLSET) {
- GPR_ASSERT(pollent->pollent.pollset != NULL);
+ GPR_ASSERT(pollent->pollent.pollset != nullptr);
grpc_pollset_set_add_pollset(pss_dst, pollent->pollent.pollset);
} else if (pollent->tag == GRPC_POLLS_POLLSET_SET) {
- GPR_ASSERT(pollent->pollent.pollset_set != NULL);
+ GPR_ASSERT(pollent->pollent.pollset_set != nullptr);
grpc_pollset_set_add_pollset_set(pss_dst, pollent->pollent.pollset_set);
} else {
gpr_log(GPR_ERROR, "Invalid grpc_polling_entity tag '%d'", pollent->tag);
@@ -73,10 +73,10 @@ void grpc_polling_entity_add_to_pollset_set(grpc_polling_entity* pollent,
void grpc_polling_entity_del_from_pollset_set(grpc_polling_entity* pollent,
grpc_pollset_set* pss_dst) {
if (pollent->tag == GRPC_POLLS_POLLSET) {
- GPR_ASSERT(pollent->pollent.pollset != NULL);
+ GPR_ASSERT(pollent->pollent.pollset != nullptr);
grpc_pollset_set_del_pollset(pss_dst, pollent->pollent.pollset);
} else if (pollent->tag == GRPC_POLLS_POLLSET_SET) {
- GPR_ASSERT(pollent->pollent.pollset_set != NULL);
+ GPR_ASSERT(pollent->pollent.pollset_set != nullptr);
grpc_pollset_set_del_pollset_set(pss_dst, pollent->pollent.pollset_set);
} else {
gpr_log(GPR_ERROR, "Invalid grpc_polling_entity tag '%d'", pollent->tag);
diff --git a/src/core/lib/iomgr/pollset_windows.h b/src/core/lib/iomgr/pollset_windows.h
index aaeb5f585f..f6da9da601 100644
--- a/src/core/lib/iomgr/pollset_windows.h
+++ b/src/core/lib/iomgr/pollset_windows.h
@@ -21,6 +21,9 @@
#include <grpc/support/sync.h>
+#include "src/core/lib/iomgr/port.h"
+
+#ifdef GRPC_WINSOCK_SOCKET
#include "src/core/lib/iomgr/socket_windows.h"
#ifdef __cplusplus
@@ -68,4 +71,6 @@ void grpc_pollset_global_shutdown(void);
}
#endif
+#endif
+
#endif /* GRPC_CORE_LIB_IOMGR_POLLSET_WINDOWS_H */
diff --git a/src/core/lib/iomgr/resolve_address_posix.cc b/src/core/lib/iomgr/resolve_address_posix.cc
index 80a1a45cc0..6c9534a291 100644
--- a/src/core/lib/iomgr/resolve_address_posix.cc
+++ b/src/core/lib/iomgr/resolve_address_posix.cc
@@ -43,7 +43,7 @@ static grpc_error* blocking_resolve_address_impl(
const char* name, const char* default_port,
grpc_resolved_addresses** addresses) {
struct addrinfo hints;
- struct addrinfo *result = NULL, *resp;
+ struct addrinfo *result = nullptr, *resp;
char* host;
char* port;
int s;
@@ -57,14 +57,14 @@ static grpc_error* blocking_resolve_address_impl(
/* parse name, splitting it into host and port parts */
gpr_split_host_port(name, &host, &port);
- if (host == NULL) {
+ if (host == nullptr) {
err = grpc_error_set_str(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("unparseable host:port"),
GRPC_ERROR_STR_TARGET_ADDRESS, grpc_slice_from_copied_string(name));
goto done;
}
- if (port == NULL) {
- if (default_port == NULL) {
+ if (port == nullptr) {
+ if (default_port == nullptr) {
err = grpc_error_set_str(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("no port in name"),
GRPC_ERROR_STR_TARGET_ADDRESS, grpc_slice_from_copied_string(name));
@@ -115,13 +115,13 @@ static grpc_error* blocking_resolve_address_impl(
*addresses =
(grpc_resolved_addresses*)gpr_malloc(sizeof(grpc_resolved_addresses));
(*addresses)->naddrs = 0;
- for (resp = result; resp != NULL; resp = resp->ai_next) {
+ for (resp = result; resp != nullptr; resp = resp->ai_next) {
(*addresses)->naddrs++;
}
(*addresses)->addrs = (grpc_resolved_address*)gpr_malloc(
sizeof(grpc_resolved_address) * (*addresses)->naddrs);
i = 0;
- for (resp = result; resp != NULL; resp = resp->ai_next) {
+ for (resp = result; resp != nullptr; resp = resp->ai_next) {
memcpy(&(*addresses)->addrs[i].addr, resp->ai_addr, resp->ai_addrlen);
(*addresses)->addrs[i].len = resp->ai_addrlen;
i++;
@@ -162,7 +162,7 @@ static void do_request_thread(void* rp, grpc_error* error) {
}
void grpc_resolved_addresses_destroy(grpc_resolved_addresses* addrs) {
- if (addrs != NULL) {
+ if (addrs != nullptr) {
gpr_free(addrs->addrs);
}
gpr_free(addrs);
diff --git a/src/core/lib/iomgr/resource_quota.cc b/src/core/lib/iomgr/resource_quota.cc
index 11cb5ddbee..819d997ce9 100644
--- a/src/core/lib/iomgr/resource_quota.cc
+++ b/src/core/lib/iomgr/resource_quota.cc
@@ -165,7 +165,7 @@ static void rulist_add_head(grpc_resource_user* resource_user,
grpc_rulist list) {
grpc_resource_quota* resource_quota = resource_user->resource_quota;
grpc_resource_user** root = &resource_quota->roots[list];
- if (*root == NULL) {
+ if (*root == nullptr) {
*root = resource_user;
resource_user->links[list].next = resource_user->links[list].prev =
resource_user;
@@ -182,7 +182,7 @@ static void rulist_add_tail(grpc_resource_user* resource_user,
grpc_rulist list) {
grpc_resource_quota* resource_quota = resource_user->resource_quota;
grpc_resource_user** root = &resource_quota->roots[list];
- if (*root == NULL) {
+ if (*root == nullptr) {
*root = resource_user;
resource_user->links[list].next = resource_user->links[list].prev =
resource_user;
@@ -196,18 +196,18 @@ static void rulist_add_tail(grpc_resource_user* resource_user,
static bool rulist_empty(grpc_resource_quota* resource_quota,
grpc_rulist list) {
- return resource_quota->roots[list] == NULL;
+ return resource_quota->roots[list] == nullptr;
}
static grpc_resource_user* rulist_pop_head(grpc_resource_quota* resource_quota,
grpc_rulist list) {
grpc_resource_user** root = &resource_quota->roots[list];
grpc_resource_user* resource_user = *root;
- if (resource_user == NULL) {
- return NULL;
+ if (resource_user == nullptr) {
+ return nullptr;
}
if (resource_user->links[list].next == resource_user) {
- *root = NULL;
+ *root = nullptr;
} else {
resource_user->links[list].next->links[list].prev =
resource_user->links[list].prev;
@@ -215,24 +215,24 @@ static grpc_resource_user* rulist_pop_head(grpc_resource_quota* resource_quota,
resource_user->links[list].next;
*root = resource_user->links[list].next;
}
- resource_user->links[list].next = resource_user->links[list].prev = NULL;
+ resource_user->links[list].next = resource_user->links[list].prev = nullptr;
return resource_user;
}
static void rulist_remove(grpc_resource_user* resource_user, grpc_rulist list) {
- if (resource_user->links[list].next == NULL) return;
+ if (resource_user->links[list].next == nullptr) return;
grpc_resource_quota* resource_quota = resource_user->resource_quota;
if (resource_quota->roots[list] == resource_user) {
resource_quota->roots[list] = resource_user->links[list].next;
if (resource_quota->roots[list] == resource_user) {
- resource_quota->roots[list] = NULL;
+ resource_quota->roots[list] = nullptr;
}
}
resource_user->links[list].next->links[list].prev =
resource_user->links[list].prev;
resource_user->links[list].prev->links[list].next =
resource_user->links[list].next;
- resource_user->links[list].next = resource_user->links[list].prev = NULL;
+ resource_user->links[list].next = resource_user->links[list].prev = nullptr;
}
/*******************************************************************************
@@ -373,7 +373,7 @@ static bool rq_reclaim(grpc_resource_quota* resource_quota, bool destructive) {
grpc_rulist list = destructive ? GRPC_RULIST_RECLAIMER_DESTRUCTIVE
: GRPC_RULIST_RECLAIMER_BENIGN;
grpc_resource_user* resource_user = rulist_pop_head(resource_quota, list);
- if (resource_user == NULL) return false;
+ if (resource_user == nullptr) return false;
if (GRPC_TRACER_ON(grpc_resource_quota_trace)) {
gpr_log(GPR_DEBUG, "RQ %s %s: initiate %s reclamation",
resource_quota->name, resource_user->name,
@@ -385,7 +385,7 @@ static bool rq_reclaim(grpc_resource_quota* resource_quota, bool destructive) {
GPR_ASSERT(c);
resource_quota->debug_only_last_reclaimer_resource_user = resource_user;
resource_quota->debug_only_last_initiated_reclaimer = c;
- resource_user->reclaimers[destructive] = NULL;
+ resource_user->reclaimers[destructive] = nullptr;
GRPC_CLOSURE_RUN(c, GRPC_ERROR_NONE);
return true;
}
@@ -462,9 +462,9 @@ static void ru_add_to_free_pool(void* ru, grpc_error* error) {
static bool ru_post_reclaimer(grpc_resource_user* resource_user,
bool destructive) {
grpc_closure* closure = resource_user->new_reclaimers[destructive];
- GPR_ASSERT(closure != NULL);
- resource_user->new_reclaimers[destructive] = NULL;
- GPR_ASSERT(resource_user->reclaimers[destructive] == NULL);
+ GPR_ASSERT(closure != nullptr);
+ resource_user->new_reclaimers[destructive] = nullptr;
+ GPR_ASSERT(resource_user->reclaimers[destructive] == nullptr);
if (gpr_atm_acq_load(&resource_user->shutdown) > 0) {
GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_CANCELLED);
return false;
@@ -510,8 +510,8 @@ static void ru_shutdown(void* ru, grpc_error* error) {
grpc_resource_user* resource_user = (grpc_resource_user*)ru;
GRPC_CLOSURE_SCHED(resource_user->reclaimers[0], GRPC_ERROR_CANCELLED);
GRPC_CLOSURE_SCHED(resource_user->reclaimers[1], GRPC_ERROR_CANCELLED);
- resource_user->reclaimers[0] = NULL;
- resource_user->reclaimers[1] = NULL;
+ resource_user->reclaimers[0] = nullptr;
+ resource_user->reclaimers[1] = nullptr;
rulist_remove(resource_user, GRPC_RULIST_RECLAIMER_BENIGN);
rulist_remove(resource_user, GRPC_RULIST_RECLAIMER_DESTRUCTIVE);
if (resource_user->allocating) {
@@ -595,7 +595,7 @@ grpc_resource_quota* grpc_resource_quota_create(const char* name) {
resource_quota->step_scheduled = false;
resource_quota->reclaiming = false;
gpr_atm_no_barrier_store(&resource_quota->memory_usage_estimation, 0);
- if (name != NULL) {
+ if (name != nullptr) {
resource_quota->name = gpr_strdup(name);
} else {
gpr_asprintf(&resource_quota->name, "anonymous_pool_%" PRIxPTR,
@@ -607,7 +607,7 @@ grpc_resource_quota* grpc_resource_quota_create(const char* name) {
rq_reclamation_done, resource_quota,
grpc_combiner_scheduler(resource_quota->combiner));
for (int i = 0; i < GRPC_RULIST_COUNT; i++) {
- resource_quota->roots[i] = NULL;
+ resource_quota->roots[i] = nullptr;
}
return resource_quota;
}
@@ -677,7 +677,7 @@ grpc_resource_quota* grpc_resource_quota_from_channel_args(
}
}
}
- return grpc_resource_quota_create(NULL);
+ return grpc_resource_quota_create(nullptr);
}
static void* rq_copy(void* rq) {
@@ -727,15 +727,15 @@ grpc_resource_user* grpc_resource_user_create(
grpc_closure_list_init(&resource_user->on_allocated);
resource_user->allocating = false;
resource_user->added_to_free_pool = false;
- resource_user->reclaimers[0] = NULL;
- resource_user->reclaimers[1] = NULL;
- resource_user->new_reclaimers[0] = NULL;
- resource_user->new_reclaimers[1] = NULL;
+ resource_user->reclaimers[0] = nullptr;
+ resource_user->reclaimers[1] = nullptr;
+ resource_user->new_reclaimers[0] = nullptr;
+ resource_user->new_reclaimers[1] = nullptr;
resource_user->outstanding_allocations = 0;
for (int i = 0; i < GRPC_RULIST_COUNT; i++) {
- resource_user->links[i].next = resource_user->links[i].prev = NULL;
+ resource_user->links[i].next = resource_user->links[i].prev = nullptr;
}
- if (name != NULL) {
+ if (name != nullptr) {
resource_user->name = gpr_strdup(name);
} else {
gpr_asprintf(&resource_user->name, "anonymous_resource_user_%" PRIxPTR,
@@ -829,7 +829,7 @@ void grpc_resource_user_free(grpc_resource_user* resource_user, size_t size) {
void grpc_resource_user_post_reclaimer(grpc_resource_user* resource_user,
bool destructive,
grpc_closure* closure) {
- GPR_ASSERT(resource_user->new_reclaimers[destructive] == NULL);
+ GPR_ASSERT(resource_user->new_reclaimers[destructive] == nullptr);
resource_user->new_reclaimers[destructive] = closure;
GRPC_CLOSURE_SCHED(&resource_user->post_reclaimer_closure[destructive],
GRPC_ERROR_NONE);
@@ -867,6 +867,6 @@ void grpc_resource_user_alloc_slices(
grpc_slice grpc_resource_user_slice_malloc(grpc_resource_user* resource_user,
size_t size) {
- grpc_resource_user_alloc(resource_user, size, NULL);
+ grpc_resource_user_alloc(resource_user, size, nullptr);
return ru_slice_create(resource_user, size);
}
diff --git a/src/core/lib/iomgr/sockaddr_utils.cc b/src/core/lib/iomgr/sockaddr_utils.cc
index 2dbc5aa6e7..3477fb52cd 100644
--- a/src/core/lib/iomgr/sockaddr_utils.cc
+++ b/src/core/lib/iomgr/sockaddr_utils.cc
@@ -41,14 +41,14 @@ int grpc_sockaddr_is_v4mapped(const grpc_resolved_address* resolved_addr,
GPR_ASSERT(resolved_addr != resolved_addr4_out);
const struct sockaddr* addr = (const struct sockaddr*)resolved_addr->addr;
struct sockaddr_in* addr4_out =
- resolved_addr4_out == NULL
- ? NULL
+ resolved_addr4_out == nullptr
+ ? nullptr
: (struct sockaddr_in*)resolved_addr4_out->addr;
if (addr->sa_family == AF_INET6) {
const struct sockaddr_in6* addr6 = (const struct sockaddr_in6*)addr;
if (memcmp(addr6->sin6_addr.s6_addr, kV4MappedPrefix,
sizeof(kV4MappedPrefix)) == 0) {
- if (resolved_addr4_out != NULL) {
+ if (resolved_addr4_out != nullptr) {
/* Normalize ::ffff:0.0.0.0/96 to IPv4. */
memset(resolved_addr4_out, 0, sizeof(*resolved_addr4_out));
addr4_out->sin_family = AF_INET;
@@ -147,12 +147,12 @@ int grpc_sockaddr_to_string(char** out,
const int save_errno = errno;
grpc_resolved_address addr_normalized;
char ntop_buf[INET6_ADDRSTRLEN];
- const void* ip = NULL;
+ const void* ip = nullptr;
int port;
uint32_t sin6_scope_id = 0;
int ret;
- *out = NULL;
+ *out = nullptr;
if (normalize && grpc_sockaddr_is_v4mapped(resolved_addr, &addr_normalized)) {
resolved_addr = &addr_normalized;
}
@@ -167,8 +167,8 @@ int grpc_sockaddr_to_string(char** out,
port = ntohs(addr6->sin6_port);
sin6_scope_id = addr6->sin6_scope_id;
}
- if (ip != NULL &&
- grpc_inet_ntop(addr->sa_family, ip, ntop_buf, sizeof(ntop_buf)) != NULL) {
+ if (ip != nullptr && grpc_inet_ntop(addr->sa_family, ip, ntop_buf,
+ sizeof(ntop_buf)) != nullptr) {
if (sin6_scope_id != 0) {
char* host_with_scope;
/* Enclose sin6_scope_id with the format defined in RFC 6784 section 2. */
@@ -192,18 +192,18 @@ char* grpc_sockaddr_to_uri(const grpc_resolved_address* resolved_addr) {
resolved_addr = &addr_normalized;
}
const char* scheme = grpc_sockaddr_get_uri_scheme(resolved_addr);
- if (scheme == NULL || strcmp("unix", scheme) == 0) {
+ if (scheme == nullptr || strcmp("unix", scheme) == 0) {
return grpc_sockaddr_to_uri_unix_if_possible(resolved_addr);
}
- char* path = NULL;
- char* uri_str = NULL;
+ char* path = nullptr;
+ char* uri_str = nullptr;
if (grpc_sockaddr_to_string(&path, resolved_addr,
false /* suppress errors */) &&
- scheme != NULL) {
+ scheme != nullptr) {
gpr_asprintf(&uri_str, "%s:%s", scheme, path);
}
gpr_free(path);
- return uri_str != NULL ? uri_str : NULL;
+ return uri_str != nullptr ? uri_str : nullptr;
}
const char* grpc_sockaddr_get_uri_scheme(
@@ -217,7 +217,7 @@ const char* grpc_sockaddr_get_uri_scheme(
case AF_UNIX:
return "unix";
}
- return NULL;
+ return nullptr;
}
int grpc_sockaddr_get_family(const grpc_resolved_address* resolved_addr) {
diff --git a/src/core/lib/iomgr/sockaddr_windows.h b/src/core/lib/iomgr/sockaddr_windows.h
index cf0f6b914d..20e37c9fc4 100644
--- a/src/core/lib/iomgr/sockaddr_windows.h
+++ b/src/core/lib/iomgr/sockaddr_windows.h
@@ -19,10 +19,16 @@
#ifndef GRPC_CORE_LIB_IOMGR_SOCKADDR_WINDOWS_H
#define GRPC_CORE_LIB_IOMGR_SOCKADDR_WINDOWS_H
+#include "src/core/lib/iomgr/port.h"
+
+#ifdef GRPC_WINSOCK_SOCKET
+
#include <winsock2.h>
#include <ws2tcpip.h>
// must be included after the above
#include <mswsock.h>
+#endif
+
#endif /* GRPC_CORE_LIB_IOMGR_SOCKADDR_WINDOWS_H */
diff --git a/src/core/lib/iomgr/socket_utils_common_posix.cc b/src/core/lib/iomgr/socket_utils_common_posix.cc
index 88b757a4ae..2d4b8f0add 100644
--- a/src/core/lib/iomgr/socket_utils_common_posix.cc
+++ b/src/core/lib/iomgr/socket_utils_common_posix.cc
@@ -263,13 +263,13 @@ static grpc_error* error_for_fd(int fd, const grpc_resolved_address* addr) {
grpc_error* grpc_create_dualstack_socket(
const grpc_resolved_address* resolved_addr, int type, int protocol,
grpc_dualstack_mode* dsmode, int* newfd) {
- return grpc_create_dualstack_socket_using_factory(NULL, resolved_addr, type,
- protocol, dsmode, newfd);
+ return grpc_create_dualstack_socket_using_factory(
+ nullptr, resolved_addr, type, protocol, dsmode, newfd);
}
static int create_socket(grpc_socket_factory* factory, int domain, int type,
int protocol) {
- return (factory != NULL)
+ return (factory != nullptr)
? grpc_socket_factory_socket(factory, domain, type, protocol)
: socket(domain, type, protocol);
}
@@ -292,7 +292,7 @@ grpc_error* grpc_create_dualstack_socket_using_factory(
return GRPC_ERROR_NONE;
}
/* If this isn't an IPv4 address, then return whatever we've got. */
- if (!grpc_sockaddr_is_v4mapped(resolved_addr, NULL)) {
+ if (!grpc_sockaddr_is_v4mapped(resolved_addr, nullptr)) {
*dsmode = GRPC_DSMODE_IPV6;
return error_for_fd(*newfd, resolved_addr);
}
diff --git a/src/core/lib/iomgr/socket_windows.h b/src/core/lib/iomgr/socket_windows.h
index 196a980201..4a1c624916 100644
--- a/src/core/lib/iomgr/socket_windows.h
+++ b/src/core/lib/iomgr/socket_windows.h
@@ -20,6 +20,9 @@
#define GRPC_CORE_LIB_IOMGR_SOCKET_WINDOWS_H
#include <grpc/support/port_platform.h>
+#include "src/core/lib/iomgr/port.h"
+
+#ifdef GRPC_WINSOCK_SOCKET
#include <winsock2.h>
#include <grpc/support/atm.h>
@@ -112,4 +115,6 @@ void grpc_socket_become_ready(grpc_winsocket* winsocket,
}
#endif
+#endif
+
#endif /* GRPC_CORE_LIB_IOMGR_SOCKET_WINDOWS_H */
diff --git a/src/core/lib/iomgr/tcp_client_posix.cc b/src/core/lib/iomgr/tcp_client_posix.cc
index 840a4e28ac..6e0fbf2a3c 100644
--- a/src/core/lib/iomgr/tcp_client_posix.cc
+++ b/src/core/lib/iomgr/tcp_client_posix.cc
@@ -105,7 +105,7 @@ static void tc_on_alarm(void* acp, grpc_error* error) {
str);
}
gpr_mu_lock(&ac->mu);
- if (ac->fd != NULL) {
+ if (ac->fd != nullptr) {
grpc_fd_shutdown(
ac->fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("connect() timed out"));
}
@@ -145,7 +145,7 @@ static void on_writable(void* acp, grpc_error* error) {
gpr_mu_lock(&ac->mu);
GPR_ASSERT(ac->fd);
fd = ac->fd;
- ac->fd = NULL;
+ ac->fd = nullptr;
gpr_mu_unlock(&ac->mu);
grpc_timer_cancel(&ac->alarm);
@@ -172,7 +172,7 @@ static void on_writable(void* acp, grpc_error* error) {
case 0:
grpc_pollset_set_del_fd(ac->interested_parties, fd);
*ep = grpc_tcp_client_create_from_fd(fd, ac->channel_args, ac->addr_str);
- fd = NULL;
+ fd = nullptr;
break;
case ENOBUFS:
/* We will get one of these errors if we have run out of
@@ -205,11 +205,11 @@ static void on_writable(void* acp, grpc_error* error) {
}
finish:
- if (fd != NULL) {
+ if (fd != nullptr) {
grpc_pollset_set_del_fd(ac->interested_parties, fd);
- grpc_fd_orphan(fd, NULL, NULL, false /* already_closed */,
+ grpc_fd_orphan(fd, nullptr, nullptr, false /* already_closed */,
"tcp_client_orphan");
- fd = NULL;
+ fd = nullptr;
}
done = (--ac->refs == 0);
gpr_mu_unlock(&ac->mu);
@@ -252,7 +252,7 @@ static void tcp_client_connect_impl(grpc_closure* closure, grpc_endpoint** ep,
char* addr_str;
grpc_error* error;
- *ep = NULL;
+ *ep = nullptr;
/* Use dualstack sockets where available. */
if (grpc_sockaddr_to_v4mapped(addr, &addr6_v4mapped)) {
@@ -291,7 +291,7 @@ static void tcp_client_connect_impl(grpc_closure* closure, grpc_endpoint** ep,
}
if (errno != EWOULDBLOCK && errno != EINPROGRESS) {
- grpc_fd_orphan(fdobj, NULL, NULL, false /* already_closed */,
+ grpc_fd_orphan(fdobj, nullptr, nullptr, false /* already_closed */,
"tcp_client_connect_error");
GRPC_CLOSURE_SCHED(closure, GRPC_OS_ERROR(errno, "connect"));
goto done;
@@ -305,7 +305,7 @@ static void tcp_client_connect_impl(grpc_closure* closure, grpc_endpoint** ep,
ac->fd = fdobj;
ac->interested_parties = interested_parties;
ac->addr_str = addr_str;
- addr_str = NULL;
+ addr_str = nullptr;
gpr_mu_init(&ac->mu);
ac->refs = 2;
GRPC_CLOSURE_INIT(&ac->write_closure, on_writable, ac,
diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc
index 04d4440f9e..c1305bef8e 100644
--- a/src/core/lib/iomgr/tcp_posix.cc
+++ b/src/core/lib/iomgr/tcp_posix.cc
@@ -134,7 +134,7 @@ static void run_poller(void* bp, grpc_error* error_ignored) {
GRPC_STATS_INC_TCP_BACKUP_POLLER_POLLS();
GRPC_LOG_IF_ERROR(
"backup_poller:pollset_work",
- grpc_pollset_work(BACKUP_POLLER_POLLSET(p), NULL, deadline));
+ grpc_pollset_work(BACKUP_POLLER_POLLSET(p), nullptr, deadline));
gpr_mu_unlock(p->pollset_mu);
/* last "uncovered" notification is the ref that keeps us polling, if we get
* there try a cas to release it */
@@ -192,7 +192,8 @@ static void cover_self(grpc_tcp* tcp) {
grpc_executor_scheduler(GRPC_EXECUTOR_LONG)),
GRPC_ERROR_NONE);
} else {
- while ((p = (backup_poller*)gpr_atm_acq_load(&g_backup_poller)) == NULL) {
+ while ((p = (backup_poller*)gpr_atm_acq_load(&g_backup_poller)) ==
+ nullptr) {
// spin waiting for backup poller
}
}
@@ -356,8 +357,8 @@ static void call_read_cb(grpc_tcp* tcp, grpc_error* error) {
}
}
- tcp->read_cb = NULL;
- tcp->incoming_buffer = NULL;
+ tcp->read_cb = nullptr;
+ tcp->incoming_buffer = nullptr;
GRPC_CLOSURE_RUN(cb, error);
}
@@ -377,11 +378,11 @@ static void tcp_do_read(grpc_tcp* tcp) {
iov[i].iov_len = GRPC_SLICE_LENGTH(tcp->incoming_buffer->slices[i]);
}
- msg.msg_name = NULL;
+ msg.msg_name = nullptr;
msg.msg_namelen = 0;
msg.msg_iov = iov;
msg.msg_iovlen = (msg_iovlen_type)tcp->incoming_buffer->count;
- msg.msg_control = NULL;
+ msg.msg_control = nullptr;
msg.msg_controllen = 0;
msg.msg_flags = 0;
@@ -486,7 +487,7 @@ static void tcp_handle_read(void* arg /* grpc_tcp */, grpc_error* error) {
static void tcp_read(grpc_endpoint* ep, grpc_slice_buffer* incoming_buffer,
grpc_closure* cb) {
grpc_tcp* tcp = (grpc_tcp*)ep;
- GPR_ASSERT(tcp->read_cb == NULL);
+ GPR_ASSERT(tcp->read_cb == nullptr);
tcp->read_cb = cb;
tcp->incoming_buffer = incoming_buffer;
grpc_slice_buffer_reset_and_unref_internal(incoming_buffer);
@@ -533,11 +534,11 @@ static bool tcp_flush(grpc_tcp* tcp, grpc_error** error) {
}
GPR_ASSERT(iov_size > 0);
- msg.msg_name = NULL;
+ msg.msg_name = nullptr;
msg.msg_namelen = 0;
msg.msg_iov = iov;
msg.msg_iovlen = iov_size;
- msg.msg_control = NULL;
+ msg.msg_control = nullptr;
msg.msg_controllen = 0;
msg.msg_flags = 0;
@@ -597,7 +598,7 @@ static void tcp_handle_write(void* arg /* grpc_tcp */, grpc_error* error) {
if (error != GRPC_ERROR_NONE) {
cb = tcp->write_cb;
- tcp->write_cb = NULL;
+ tcp->write_cb = nullptr;
cb->cb(cb->cb_arg, error);
TCP_UNREF(tcp, "write");
return;
@@ -610,7 +611,7 @@ static void tcp_handle_write(void* arg /* grpc_tcp */, grpc_error* error) {
notify_on_write(tcp);
} else {
cb = tcp->write_cb;
- tcp->write_cb = NULL;
+ tcp->write_cb = nullptr;
if (GRPC_TRACER_ON(grpc_tcp_trace)) {
const char* str = grpc_error_string(error);
gpr_log(GPR_DEBUG, "write: %s", str);
@@ -638,7 +639,7 @@ static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf,
}
GPR_TIMER_BEGIN("tcp_write", 0);
- GPR_ASSERT(tcp->write_cb == NULL);
+ GPR_ASSERT(tcp->write_cb == nullptr);
if (buf->length == 0) {
GPR_TIMER_END("tcp_write", 0);
@@ -722,8 +723,8 @@ grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd,
int tcp_read_chunk_size = GRPC_TCP_DEFAULT_READ_SLICE_SIZE;
int tcp_max_read_chunk_size = 4 * 1024 * 1024;
int tcp_min_read_chunk_size = 256;
- grpc_resource_quota* resource_quota = grpc_resource_quota_create(NULL);
- if (channel_args != NULL) {
+ grpc_resource_quota* resource_quota = grpc_resource_quota_create(nullptr);
+ if (channel_args != nullptr) {
for (size_t i = 0; i < channel_args->num_args; i++) {
if (0 ==
strcmp(channel_args->args[i].key, GRPC_ARG_TCP_READ_CHUNK_SIZE)) {
@@ -762,11 +763,11 @@ grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd,
tcp->base.vtable = &vtable;
tcp->peer_string = gpr_strdup(peer_string);
tcp->fd = grpc_fd_wrapped_fd(em_fd);
- tcp->read_cb = NULL;
- tcp->write_cb = NULL;
- tcp->release_fd_cb = NULL;
- tcp->release_fd = NULL;
- tcp->incoming_buffer = NULL;
+ tcp->read_cb = nullptr;
+ tcp->write_cb = nullptr;
+ tcp->release_fd_cb = nullptr;
+ tcp->release_fd = nullptr;
+ tcp->incoming_buffer = nullptr;
tcp->target_length = (double)tcp_read_chunk_size;
tcp->min_read_chunk_size = tcp_min_read_chunk_size;
tcp->max_read_chunk_size = tcp_max_read_chunk_size;
diff --git a/src/core/lib/iomgr/tcp_server_posix.cc b/src/core/lib/iomgr/tcp_server_posix.cc
index 18af50d038..475e9fef79 100644
--- a/src/core/lib/iomgr/tcp_server_posix.cc
+++ b/src/core/lib/iomgr/tcp_server_posix.cc
@@ -76,7 +76,7 @@ grpc_error* grpc_tcp_server_create(grpc_closure* shutdown_complete,
grpc_tcp_server* s = (grpc_tcp_server*)gpr_zalloc(sizeof(grpc_tcp_server));
s->so_reuseport = has_so_reuseport;
s->expand_wildcard_addrs = false;
- for (size_t i = 0; i < (args == NULL ? 0 : args->num_args); i++) {
+ for (size_t i = 0; i < (args == nullptr ? 0 : args->num_args); i++) {
if (0 == strcmp(GRPC_ARG_ALLOW_REUSEPORT, args->args[i].key)) {
if (args->args[i].type == GRPC_ARG_INTEGER) {
s->so_reuseport =
@@ -101,13 +101,13 @@ grpc_error* grpc_tcp_server_create(grpc_closure* shutdown_complete,
s->active_ports = 0;
s->destroyed_ports = 0;
s->shutdown = false;
- s->shutdown_starting.head = NULL;
- s->shutdown_starting.tail = NULL;
+ s->shutdown_starting.head = nullptr;
+ s->shutdown_starting.tail = nullptr;
s->shutdown_complete = shutdown_complete;
- s->on_accept_cb = NULL;
- s->on_accept_cb_arg = NULL;
- s->head = NULL;
- s->tail = NULL;
+ s->on_accept_cb = nullptr;
+ s->on_accept_cb_arg = nullptr;
+ s->head = nullptr;
+ s->tail = nullptr;
s->nports = 0;
s->channel_args = grpc_channel_args_copy(args);
gpr_atm_no_barrier_store(&s->next_pollset_to_assign, 0);
@@ -119,7 +119,7 @@ static void finish_shutdown(grpc_tcp_server* s) {
gpr_mu_lock(&s->mu);
GPR_ASSERT(s->shutdown);
gpr_mu_unlock(&s->mu);
- if (s->shutdown_complete != NULL) {
+ if (s->shutdown_complete != nullptr) {
GRPC_CLOSURE_SCHED(s->shutdown_complete, GRPC_ERROR_NONE);
}
@@ -163,7 +163,7 @@ static void deactivated_all_ports(grpc_tcp_server* s) {
grpc_unlink_if_unix_domain_socket(&sp->addr);
GRPC_CLOSURE_INIT(&sp->destroyed_closure, destroyed_port, s,
grpc_schedule_on_exec_ctx);
- grpc_fd_orphan(sp->emfd, &sp->destroyed_closure, NULL,
+ grpc_fd_orphan(sp->emfd, &sp->destroyed_closure, nullptr,
false /* already_closed */, "tcp_listener_shutdown");
}
gpr_mu_unlock(&s->mu);
@@ -285,8 +285,8 @@ static grpc_error* add_wildcard_addrs_to_server(grpc_tcp_server* s,
grpc_resolved_address wild6;
unsigned fd_index = 0;
grpc_dualstack_mode dsmode;
- grpc_tcp_listener* sp = NULL;
- grpc_tcp_listener* sp2 = NULL;
+ grpc_tcp_listener* sp = nullptr;
+ grpc_tcp_listener* sp2 = nullptr;
grpc_error* v6_err = GRPC_ERROR_NONE;
grpc_error* v4_err = GRPC_ERROR_NONE;
*out_port = -1;
@@ -311,7 +311,7 @@ static grpc_error* add_wildcard_addrs_to_server(grpc_tcp_server* s,
if ((v4_err = grpc_tcp_server_add_addr(s, &wild4, port_index, fd_index,
&dsmode, &sp2)) == GRPC_ERROR_NONE) {
*out_port = sp2->port;
- if (sp != NULL) {
+ if (sp != nullptr) {
sp2->is_sibling = 1;
sp->sibling = sp2;
}
@@ -343,7 +343,7 @@ static grpc_error* add_wildcard_addrs_to_server(grpc_tcp_server* s,
}
static grpc_error* clone_port(grpc_tcp_listener* listener, unsigned count) {
- grpc_tcp_listener* sp = NULL;
+ grpc_tcp_listener* sp = nullptr;
char* addr_str;
char* name;
grpc_error* err;
@@ -380,7 +380,7 @@ static grpc_error* clone_port(grpc_tcp_listener* listener, unsigned count) {
sp->port_index = listener->port_index;
sp->fd_index = listener->fd_index + count - i;
GPR_ASSERT(sp->emfd);
- while (listener->server->tail->next != NULL) {
+ while (listener->server->tail->next != nullptr) {
listener->server->tail = listener->server->tail->next;
}
gpr_free(addr_str);
@@ -401,7 +401,7 @@ grpc_error* grpc_tcp_server_add_port(grpc_tcp_server* s,
grpc_dualstack_mode dsmode;
grpc_error* err;
*out_port = -1;
- if (s->tail != NULL) {
+ if (s->tail != nullptr) {
port_index = s->tail->port_index + 1;
}
grpc_unlink_if_unix_domain_socket(addr);
@@ -451,7 +451,7 @@ static grpc_tcp_listener* get_port_index(grpc_tcp_server* s,
}
}
}
- return NULL;
+ return nullptr;
}
unsigned grpc_tcp_server_port_fd_count(grpc_tcp_server* s,
@@ -495,7 +495,7 @@ void grpc_tcp_server_start(grpc_tcp_server* s, grpc_pollset** pollsets,
s->pollsets = pollsets;
s->pollset_count = pollset_count;
sp = s->head;
- while (sp != NULL) {
+ while (sp != nullptr) {
if (s->so_reuseport && !grpc_is_unix_socket(&sp->addr) &&
pollset_count > 1) {
GPR_ASSERT(GRPC_LOG_IF_ERROR(
diff --git a/src/core/lib/iomgr/tcp_server_utils_posix_common.cc b/src/core/lib/iomgr/tcp_server_utils_posix_common.cc
index 51e6731729..72443cc29e 100644
--- a/src/core/lib/iomgr/tcp_server_utils_posix_common.cc
+++ b/src/core/lib/iomgr/tcp_server_utils_posix_common.cc
@@ -47,7 +47,7 @@ static void init_max_accept_queue_size(void) {
int n = SOMAXCONN;
char buf[64];
FILE* fp = fopen("/proc/sys/net/core/somaxconn", "r");
- if (fp == NULL) {
+ if (fp == nullptr) {
/* 2.4 kernel. */
s_max_accept_queue_size = SOMAXCONN;
return;
@@ -79,7 +79,7 @@ static grpc_error* add_socket_to_server(grpc_tcp_server* s, int fd,
const grpc_resolved_address* addr,
unsigned port_index, unsigned fd_index,
grpc_tcp_listener** listener) {
- grpc_tcp_listener* sp = NULL;
+ grpc_tcp_listener* sp = nullptr;
int port = -1;
char* addr_str;
char* name;
@@ -94,8 +94,8 @@ static grpc_error* add_socket_to_server(grpc_tcp_server* s, int fd,
s->nports++;
GPR_ASSERT(!s->on_accept_cb && "must add ports before starting server");
sp = (grpc_tcp_listener*)gpr_malloc(sizeof(grpc_tcp_listener));
- sp->next = NULL;
- if (s->head == NULL) {
+ sp->next = nullptr;
+ if (s->head == nullptr) {
s->head = sp;
} else {
s->tail->next = sp;
@@ -109,7 +109,7 @@ static grpc_error* add_socket_to_server(grpc_tcp_server* s, int fd,
sp->port_index = port_index;
sp->fd_index = fd_index;
sp->is_sibling = 0;
- sp->sibling = NULL;
+ sp->sibling = nullptr;
GPR_ASSERT(sp->emfd);
gpr_mu_unlock(&s->mu);
gpr_free(addr_str);
diff --git a/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc b/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc
index b7437dbf4d..227bf94aa7 100644
--- a/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc
+++ b/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc
@@ -40,7 +40,7 @@ static grpc_tcp_listener* find_listener_with_addr(grpc_tcp_server* s,
grpc_resolved_address* addr) {
grpc_tcp_listener* l;
gpr_mu_lock(&s->mu);
- for (l = s->head; l != NULL; l = l->next) {
+ for (l = s->head; l != nullptr; l = l->next) {
if (l->addr.len != addr->len) {
continue;
}
@@ -87,10 +87,10 @@ grpc_error* grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s,
unsigned port_index,
int requested_port,
int* out_port) {
- struct ifaddrs* ifa = NULL;
+ struct ifaddrs* ifa = nullptr;
struct ifaddrs* ifa_it;
unsigned fd_index = 0;
- grpc_tcp_listener* sp = NULL;
+ grpc_tcp_listener* sp = nullptr;
grpc_error* err = GRPC_ERROR_NONE;
if (requested_port == 0) {
/* Note: There could be a race where some local addrs can listen on the
@@ -104,16 +104,16 @@ grpc_error* grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s,
}
gpr_log(GPR_DEBUG, "Picked unused port %d", requested_port);
}
- if (getifaddrs(&ifa) != 0 || ifa == NULL) {
+ if (getifaddrs(&ifa) != 0 || ifa == nullptr) {
return GRPC_OS_ERROR(errno, "getifaddrs");
}
- for (ifa_it = ifa; ifa_it != NULL; ifa_it = ifa_it->ifa_next) {
+ for (ifa_it = ifa; ifa_it != nullptr; ifa_it = ifa_it->ifa_next) {
grpc_resolved_address addr;
- char* addr_str = NULL;
+ char* addr_str = nullptr;
grpc_dualstack_mode dsmode;
- grpc_tcp_listener* new_sp = NULL;
+ grpc_tcp_listener* new_sp = nullptr;
const char* ifa_name = (ifa_it->ifa_name ? ifa_it->ifa_name : "<unknown>");
- if (ifa_it->ifa_addr == NULL) {
+ if (ifa_it->ifa_addr == nullptr) {
continue;
} else if (ifa_it->ifa_addr->sa_family == AF_INET) {
addr.len = sizeof(struct sockaddr_in);
@@ -136,7 +136,7 @@ grpc_error* grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s,
ifa_name, ifa_it->ifa_flags, addr_str);
/* We could have multiple interfaces with the same address (e.g., bonding),
so look for duplicates. */
- if (find_listener_with_addr(s, &addr) != NULL) {
+ if (find_listener_with_addr(s, &addr) != nullptr) {
gpr_log(GPR_DEBUG, "Skipping duplicate addr %s on interface %s", addr_str,
ifa_name);
gpr_free(addr_str);
@@ -144,7 +144,7 @@ grpc_error* grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s,
}
if ((err = grpc_tcp_server_add_addr(s, &addr, port_index, fd_index, &dsmode,
&new_sp)) != GRPC_ERROR_NONE) {
- char* err_str = NULL;
+ char* err_str = nullptr;
grpc_error* root_err;
if (gpr_asprintf(&err_str, "Failed to add listener: %s", addr_str) < 0) {
err_str = gpr_strdup("Failed to add listener");
@@ -157,7 +157,7 @@ grpc_error* grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s,
} else {
GPR_ASSERT(requested_port == new_sp->port);
++fd_index;
- if (sp != NULL) {
+ if (sp != nullptr) {
new_sp->is_sibling = 1;
sp->sibling = new_sp;
}
@@ -168,7 +168,7 @@ grpc_error* grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s,
freeifaddrs(ifa);
if (err != GRPC_ERROR_NONE) {
return err;
- } else if (sp == NULL) {
+ } else if (sp == nullptr) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("No local addresses");
} else {
*out_port = sp->port;
diff --git a/src/core/lib/iomgr/tcp_uv.h b/src/core/lib/iomgr/tcp_uv.h
index 8a4914935a..708e8469e6 100644
--- a/src/core/lib/iomgr/tcp_uv.h
+++ b/src/core/lib/iomgr/tcp_uv.h
@@ -32,6 +32,10 @@
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/iomgr/endpoint.h"
+#include "src/core/lib/iomgr/port.h"
+
+#ifdef GRPC_UV
+
#include <uv.h>
extern grpc_tracer_flag grpc_tcp_trace;
@@ -50,4 +54,6 @@ grpc_endpoint* grpc_tcp_create(uv_tcp_t* handle,
}
#endif
+#endif /* GRPC_UV */
+
#endif /* GRPC_CORE_LIB_IOMGR_TCP_UV_H */
diff --git a/src/core/lib/iomgr/tcp_windows.h b/src/core/lib/iomgr/tcp_windows.h
index 78d78a22c5..693037cab7 100644
--- a/src/core/lib/iomgr/tcp_windows.h
+++ b/src/core/lib/iomgr/tcp_windows.h
@@ -29,6 +29,9 @@
otherwise specified.
*/
+#include "src/core/lib/iomgr/port.h"
+
+#ifdef GRPC_WINSOCK_SOCKET
#include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/iomgr/socket_windows.h"
@@ -49,4 +52,6 @@ grpc_error* grpc_tcp_prepare_socket(SOCKET sock);
}
#endif
+#endif
+
#endif /* GRPC_CORE_LIB_IOMGR_TCP_WINDOWS_H */
diff --git a/src/core/lib/iomgr/timer_generic.cc b/src/core/lib/iomgr/timer_generic.cc
index ae82701676..861a85577b 100644
--- a/src/core/lib/iomgr/timer_generic.cc
+++ b/src/core/lib/iomgr/timer_generic.cc
@@ -91,7 +91,7 @@ static timer_shard** g_shard_queue;
#define NUM_HASH_BUCKETS 1009 /* Prime number close to 1000 */
static gpr_mu g_hash_mu[NUM_HASH_BUCKETS]; /* One mutex per bucket */
-static grpc_timer* g_timer_ht[NUM_HASH_BUCKETS] = {NULL};
+static grpc_timer* g_timer_ht[NUM_HASH_BUCKETS] = {nullptr};
static void init_timer_ht() {
for (int i = 0; i < NUM_HASH_BUCKETS; i++) {
@@ -104,7 +104,7 @@ static bool is_in_ht(grpc_timer* t) {
gpr_mu_lock(&g_hash_mu[i]);
grpc_timer* p = g_timer_ht[i];
- while (p != NULL && p != t) {
+ while (p != nullptr && p != t) {
p = p->hash_table_next;
}
gpr_mu_unlock(&g_hash_mu[i]);
@@ -118,7 +118,7 @@ static void add_to_ht(grpc_timer* t) {
gpr_mu_lock(&g_hash_mu[i]);
grpc_timer* p = g_timer_ht[i];
- while (p != NULL && p != t) {
+ while (p != nullptr && p != t) {
p = p->hash_table_next;
}
@@ -146,9 +146,9 @@ static void remove_from_ht(grpc_timer* t) {
if (g_timer_ht[i] == t) {
g_timer_ht[i] = g_timer_ht[i]->hash_table_next;
removed = true;
- } else if (g_timer_ht[i] != NULL) {
+ } else if (g_timer_ht[i] != nullptr) {
grpc_timer* p = g_timer_ht[i];
- while (p->hash_table_next != NULL && p->hash_table_next != t) {
+ while (p->hash_table_next != nullptr && p->hash_table_next != t) {
p = p->hash_table_next;
}
@@ -169,7 +169,7 @@ static void remove_from_ht(grpc_timer* t) {
abort();
}
- t->hash_table_next = NULL;
+ t->hash_table_next = nullptr;
}
/* If a timer is added to a timer shard (either heap or a list), it cannot
@@ -274,7 +274,7 @@ void grpc_timer_list_init() {
void grpc_timer_list_shutdown() {
size_t i;
run_some_expired_timers(
- GPR_ATM_MAX, NULL,
+ GPR_ATM_MAX, nullptr,
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Timer list shutdown"));
for (i = 0; i < g_num_shards; i++) {
timer_shard* shard = &g_shards[i];
@@ -335,7 +335,7 @@ void grpc_timer_init(grpc_timer* timer, grpc_millis deadline,
timer->deadline = deadline;
#ifndef NDEBUG
- timer->hash_table_next = NULL;
+ timer->hash_table_next = nullptr;
#endif
if (GRPC_TRACER_ON(grpc_timer_trace)) {
@@ -498,8 +498,8 @@ static grpc_timer* pop_one(timer_shard* shard, gpr_atm now) {
grpc_timer_heap_is_empty(&shard->heap) ? "true" : "false");
}
if (grpc_timer_heap_is_empty(&shard->heap)) {
- if (now < shard->queue_deadline_cap) return NULL;
- if (!refill_heap(shard, now)) return NULL;
+ if (now < shard->queue_deadline_cap) return nullptr;
+ if (!refill_heap(shard, now)) return nullptr;
}
timer = grpc_timer_heap_top(&shard->heap);
if (GRPC_TRACER_ON(grpc_timer_check_trace)) {
@@ -507,7 +507,7 @@ static grpc_timer* pop_one(timer_shard* shard, gpr_atm now) {
" .. check top timer deadline=%" PRIdPTR " now=%" PRIdPTR,
timer->deadline, now);
}
- if (timer->deadline > now) return NULL;
+ if (timer->deadline > now) return nullptr;
if (GRPC_TRACER_ON(grpc_timer_trace)) {
gpr_log(GPR_DEBUG, "TIMER %p: FIRE %" PRIdPTR "ms late via %s scheduler",
timer, now - timer->deadline,
@@ -547,7 +547,7 @@ static grpc_timer_check_result run_some_expired_timers(gpr_atm now,
gpr_atm min_timer = gpr_atm_no_barrier_load(&g_shared_mutables.min_timer);
gpr_tls_set(&g_last_seen_min_timer, min_timer);
if (now < min_timer) {
- if (next != NULL) *next = GPR_MIN(*next, min_timer);
+ if (next != nullptr) *next = GPR_MIN(*next, min_timer);
return GRPC_TIMERS_CHECKED_AND_EMPTY;
}
@@ -613,7 +613,7 @@ grpc_timer_check_result grpc_timer_check(grpc_millis* next) {
mutable cacheline in the common case */
grpc_millis min_timer = gpr_tls_get(&g_last_seen_min_timer);
if (now < min_timer) {
- if (next != NULL) {
+ if (next != nullptr) {
*next = GPR_MIN(*next, min_timer);
}
if (GRPC_TRACER_ON(grpc_timer_check_trace)) {
@@ -632,7 +632,7 @@ grpc_timer_check_result grpc_timer_check(grpc_millis* next) {
// tracing
if (GRPC_TRACER_ON(grpc_timer_check_trace)) {
char* next_str;
- if (next == NULL) {
+ if (next == nullptr) {
next_str = gpr_strdup("NULL");
} else {
gpr_asprintf(&next_str, "%" PRIdPTR, *next);
@@ -650,7 +650,7 @@ grpc_timer_check_result grpc_timer_check(grpc_millis* next) {
// tracing
if (GRPC_TRACER_ON(grpc_timer_check_trace)) {
char* next_str;
- if (next == NULL) {
+ if (next == nullptr) {
next_str = gpr_strdup("NULL");
} else {
gpr_asprintf(&next_str, "%" PRIdPTR, *next);
diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc
index ed03e48b32..dfa381a1f1 100644
--- a/src/core/lib/iomgr/timer_manager.cc
+++ b/src/core/lib/iomgr/timer_manager.cc
@@ -62,11 +62,11 @@ static uint64_t g_timed_waiter_generation;
static void timer_thread(void* completed_thread_ptr);
static void gc_completed_threads(void) {
- if (g_completed_threads != NULL) {
+ if (g_completed_threads != nullptr) {
completed_thread* to_gc = g_completed_threads;
- g_completed_threads = NULL;
+ g_completed_threads = nullptr;
gpr_mu_unlock(&g_mu);
- while (to_gc != NULL) {
+ while (to_gc != nullptr) {
gpr_thd_join(to_gc->t);
completed_thread* next = to_gc->next;
gpr_free(to_gc);
@@ -224,6 +224,10 @@ static void timer_main_loop() {
for (;;) {
grpc_millis next = GRPC_MILLIS_INF_FUTURE;
grpc_core::ExecCtx::Get()->InvalidateNow();
+ /* Calibrate g_start_time in exec_ctx.cc with a regular interval in case the
+ * system clock has changed */
+ grpc_exec_ctx_maybe_update_start_time();
+
// check timer state, updates next to the next time to run a check
switch (grpc_timer_check(&next)) {
case GRPC_TIMERS_FIRED:
@@ -297,7 +301,7 @@ void grpc_timer_manager_init(void) {
g_threaded = false;
g_thread_count = 0;
g_waiter_count = 0;
- g_completed_threads = NULL;
+ g_completed_threads = nullptr;
g_has_timed_waiter = false;
g_timed_waiter_deadline = GRPC_MILLIS_INF_FUTURE;
diff --git a/src/core/lib/iomgr/udp_server.cc b/src/core/lib/iomgr/udp_server.cc
index 8e837e5e2f..d4de04a894 100644
--- a/src/core/lib/iomgr/udp_server.cc
+++ b/src/core/lib/iomgr/udp_server.cc
@@ -121,7 +121,7 @@ static grpc_socket_factory* get_socket_factory(const grpc_channel_args* args) {
return (grpc_socket_factory*)arg->value.pointer.p;
}
}
- return NULL;
+ return nullptr;
}
grpc_udp_server* grpc_udp_server_create(const grpc_channel_args* args) {
@@ -134,8 +134,8 @@ grpc_udp_server* grpc_udp_server_create(const grpc_channel_args* args) {
s->active_ports = 0;
s->destroyed_ports = 0;
s->shutdown = 0;
- s->head = NULL;
- s->tail = NULL;
+ s->head = nullptr;
+ s->tail = nullptr;
s->nports = 0;
return s;
@@ -154,7 +154,7 @@ static void dummy_cb(void* arg, grpc_error* error) {
}
static void finish_shutdown(grpc_udp_server* s) {
- if (s->shutdown_complete != NULL) {
+ if (s->shutdown_complete != nullptr) {
GRPC_CLOSURE_SCHED(s->shutdown_complete, GRPC_ERROR_NONE);
}
@@ -210,7 +210,7 @@ static void deactivated_all_ports(grpc_udp_server* s) {
GPR_ASSERT(sp->orphan_cb);
sp->orphan_cb(sp->emfd, &sp->orphan_fd_closure, sp->server->user_data);
}
- grpc_fd_orphan(sp->emfd, &sp->destroyed_closure, NULL,
+ grpc_fd_orphan(sp->emfd, &sp->destroyed_closure, nullptr,
false /* already_closed */, "udp_listener_shutdown");
}
gpr_mu_unlock(&s->mu);
@@ -251,7 +251,7 @@ void grpc_udp_server_destroy(grpc_udp_server* s, grpc_closure* on_done) {
static int bind_socket(grpc_socket_factory* socket_factory, int sockfd,
const grpc_resolved_address* addr) {
- return (socket_factory != NULL)
+ return (socket_factory != nullptr)
? grpc_socket_factory_bind(socket_factory, sockfd, addr)
: bind(sockfd, (struct sockaddr*)addr->addr, (socklen_t)addr->len);
}
@@ -389,8 +389,8 @@ static int add_socket_to_server(grpc_udp_server* s, int fd,
gpr_mu_lock(&s->mu);
s->nports++;
sp = (grpc_udp_listener*)gpr_malloc(sizeof(grpc_udp_listener));
- sp->next = NULL;
- if (s->head == NULL) {
+ sp->next = nullptr;
+ if (s->head == nullptr) {
s->head = sp;
} else {
s->tail->next = sp;
@@ -426,7 +426,7 @@ int grpc_udp_server_add_port(grpc_udp_server* s,
grpc_resolved_address wild4;
grpc_resolved_address wild6;
grpc_resolved_address addr4_copy;
- grpc_resolved_address* allocated_addr = NULL;
+ grpc_resolved_address* allocated_addr = nullptr;
grpc_resolved_address sockname_temp;
int port;
@@ -503,6 +503,7 @@ int grpc_udp_server_get_fd(grpc_udp_server* s, unsigned port_index) {
for (sp = s->head; sp && port_index != 0; sp = sp->next) {
--port_index;
}
+ GPR_ASSERT(sp); // if this fails, our check earlier was bogus
return sp->fd;
}
@@ -516,7 +517,7 @@ void grpc_udp_server_start(grpc_udp_server* s, grpc_pollset** pollsets,
s->user_data = user_data;
sp = s->head;
- while (sp != NULL) {
+ while (sp != nullptr) {
for (i = 0; i < pollset_count; i++) {
grpc_pollset_add_fd(pollsets[i], sp->emfd);
}
diff --git a/src/core/lib/iomgr/unix_sockets_posix.cc b/src/core/lib/iomgr/unix_sockets_posix.cc
index 5d3689c38f..af862c00dc 100644
--- a/src/core/lib/iomgr/unix_sockets_posix.cc
+++ b/src/core/lib/iomgr/unix_sockets_posix.cc
@@ -39,7 +39,8 @@ void grpc_create_socketpair_if_unix(int sv[2]) {
grpc_error* grpc_resolve_unix_domain_address(const char* name,
grpc_resolved_addresses** addrs) {
struct sockaddr_un* un;
- if (strlen(name) > GPR_ARRAY_SIZE(((struct sockaddr_un*)0)->sun_path) - 1) {
+ if (strlen(name) >
+ GPR_ARRAY_SIZE(((struct sockaddr_un*)nullptr)->sun_path) - 1) {
char* err_msg;
grpc_error* err;
gpr_asprintf(&err_msg,
@@ -56,7 +57,7 @@ grpc_error* grpc_resolve_unix_domain_address(const char* name,
(grpc_resolved_address*)gpr_malloc(sizeof(grpc_resolved_address));
un = (struct sockaddr_un*)(*addrs)->addrs->addr;
un->sun_family = AF_UNIX;
- strcpy(un->sun_path, name);
+ strncpy(un->sun_path, name, sizeof(un->sun_path));
(*addrs)->addrs->len = strlen(un->sun_path) + sizeof(un->sun_family) + 1;
return GRPC_ERROR_NONE;
}
@@ -84,7 +85,7 @@ char* grpc_sockaddr_to_uri_unix_if_possible(
const grpc_resolved_address* resolved_addr) {
const struct sockaddr* addr = (const struct sockaddr*)resolved_addr->addr;
if (addr->sa_family != AF_UNIX) {
- return NULL;
+ return nullptr;
}
char* result;
diff --git a/src/core/lib/iomgr/wakeup_fd_cv.cc b/src/core/lib/iomgr/wakeup_fd_cv.cc
index 268e0175dd..5c1f16d3fc 100644
--- a/src/core/lib/iomgr/wakeup_fd_cv.cc
+++ b/src/core/lib/iomgr/wakeup_fd_cv.cc
@@ -46,7 +46,7 @@ static grpc_error* cv_fd_init(grpc_wakeup_fd* fd_info) {
(fd_node*)gpr_realloc(g_cvfds.cvfds, sizeof(fd_node) * newsize);
for (i = g_cvfds.size; i < newsize; i++) {
g_cvfds.cvfds[i].is_set = 0;
- g_cvfds.cvfds[i].cvs = NULL;
+ g_cvfds.cvfds[i].cvs = nullptr;
g_cvfds.cvfds[i].next_free = g_cvfds.free_fds;
g_cvfds.free_fds = &g_cvfds.cvfds[i];
}
@@ -55,7 +55,7 @@ static grpc_error* cv_fd_init(grpc_wakeup_fd* fd_info) {
idx = (int)(g_cvfds.free_fds - g_cvfds.cvfds);
g_cvfds.free_fds = g_cvfds.free_fds->next_free;
- g_cvfds.cvfds[idx].cvs = NULL;
+ g_cvfds.cvfds[idx].cvs = nullptr;
g_cvfds.cvfds[idx].is_set = 0;
fd_info->read_fd = GRPC_IDX_TO_FD(idx);
fd_info->write_fd = -1;
diff --git a/src/core/lib/iomgr/wakeup_fd_posix.cc b/src/core/lib/iomgr/wakeup_fd_posix.cc
index dcad61b097..e8de208a25 100644
--- a/src/core/lib/iomgr/wakeup_fd_posix.cc
+++ b/src/core/lib/iomgr/wakeup_fd_posix.cc
@@ -25,7 +25,7 @@
#include "src/core/lib/iomgr/wakeup_fd_pipe.h"
#include "src/core/lib/iomgr/wakeup_fd_posix.h"
-static const grpc_wakeup_fd_vtable* wakeup_fd_vtable = NULL;
+static const grpc_wakeup_fd_vtable* wakeup_fd_vtable = nullptr;
int grpc_allow_specialized_wakeup_fd = 1;
int grpc_allow_pipe_wakeup_fd = 1;
@@ -45,7 +45,7 @@ void grpc_wakeup_fd_global_init(void) {
}
}
-void grpc_wakeup_fd_global_destroy(void) { wakeup_fd_vtable = NULL; }
+void grpc_wakeup_fd_global_destroy(void) { wakeup_fd_vtable = nullptr; }
int grpc_has_wakeup_fd(void) { return has_real_wakeup_fd; }