aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/iomgr
diff options
context:
space:
mode:
authorGravatar Noah Eisen <ncteisen@google.com>2017-11-13 16:44:02 -0800
committerGravatar Noah Eisen <ncteisen@google.com>2017-11-13 16:44:02 -0800
commit68bb1bf7480e87005220003985da19ea0a0929d0 (patch)
treec434576b07f94f427925dd7f7dfba4dbdeecee31 /src/core/lib/iomgr
parent6bf73e8cf6d9d2ede844ab628a0b88000ffc9afa (diff)
parentb0bad8f3864dc9c8745736fe68efe513b2b84932 (diff)
Merge branch 'master' of https://github.com/grpc/grpc into tracing++
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.cc18
-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.cc64
-rw-r--r--src/core/lib/iomgr/ev_epollsig_linux.cc120
-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.cc78
-rw-r--r--src/core/lib/iomgr/exec_ctx.h2
-rw-r--r--src/core/lib/iomgr/executor.cc6
-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/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.cc20
-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_manager.cc15
-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
36 files changed, 413 insertions, 307 deletions
diff --git a/src/core/lib/iomgr/call_combiner.cc b/src/core/lib/iomgr/call_combiner.cc
index 752303e260..b5910b42e4 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_exec_ctx* exec_ctx,
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_call_combiner_trace.enabled()) {
diff --git a/src/core/lib/iomgr/closure.cc b/src/core/lib/iomgr/closure.cc
index c5f127d12e..ee4f826eb7 100644
--- a/src/core/lib/iomgr/closure.cc
+++ b/src/core/lib/iomgr/closure.cc
@@ -41,7 +41,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;
@@ -51,18 +51,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 {
@@ -74,7 +74,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);
}
@@ -83,20 +83,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(grpc_exec_ctx* exec_ctx, 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;
@@ -163,7 +163,7 @@ void grpc_closure_sched(grpc_exec_ctx* exec_ctx, 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,
@@ -193,7 +193,7 @@ void grpc_closure_list_sched(const char* file, int line,
void grpc_closure_list_sched(grpc_exec_ctx* exec_ctx, 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) {
@@ -213,5 +213,5 @@ void grpc_closure_list_sched(grpc_exec_ctx* exec_ctx, grpc_closure_list* list) {
c->scheduler->vtable->sched(exec_ctx, 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 ab583ded0d..15c009dd77 100644
--- a/src/core/lib/iomgr/combiner.cc
+++ b/src/core/lib/iomgr/combiner.cc
@@ -131,8 +131,8 @@ grpc_combiner* grpc_combiner_ref(grpc_combiner* lock GRPC_COMBINER_DEBUG_ARGS) {
static void push_last_on_exec_ctx(grpc_exec_ctx* exec_ctx,
grpc_combiner* lock) {
- lock->next_combiner_on_this_exec_ctx = NULL;
- if (exec_ctx->active_combiner == NULL) {
+ lock->next_combiner_on_this_exec_ctx = nullptr;
+ if (exec_ctx->active_combiner == nullptr) {
exec_ctx->active_combiner = exec_ctx->last_combiner = lock;
} else {
exec_ctx->last_combiner->next_combiner_on_this_exec_ctx = lock;
@@ -144,7 +144,7 @@ static void push_first_on_exec_ctx(grpc_exec_ctx* exec_ctx,
grpc_combiner* lock) {
lock->next_combiner_on_this_exec_ctx = exec_ctx->active_combiner;
exec_ctx->active_combiner = lock;
- if (lock->next_combiner_on_this_exec_ctx == NULL) {
+ if (lock->next_combiner_on_this_exec_ctx == nullptr) {
exec_ctx->last_combiner = lock;
}
}
@@ -189,8 +189,8 @@ static void combiner_exec(grpc_exec_ctx* exec_ctx, grpc_closure* cl,
static void move_next(grpc_exec_ctx* exec_ctx) {
exec_ctx->active_combiner =
exec_ctx->active_combiner->next_combiner_on_this_exec_ctx;
- if (exec_ctx->active_combiner == NULL) {
- exec_ctx->last_combiner = NULL;
+ if (exec_ctx->active_combiner == nullptr) {
+ exec_ctx->last_combiner = nullptr;
}
}
@@ -209,7 +209,7 @@ static void queue_offload(grpc_exec_ctx* exec_ctx, grpc_combiner* lock) {
bool grpc_combiner_continue_exec_ctx(grpc_exec_ctx* exec_ctx) {
GPR_TIMER_BEGIN("combiner.continue_exec_ctx", 0);
grpc_combiner* lock = exec_ctx->active_combiner;
- if (lock == NULL) {
+ if (lock == nullptr) {
GPR_TIMER_END("combiner.continue_exec_ctx", 0);
return false;
}
@@ -243,7 +243,7 @@ bool grpc_combiner_continue_exec_ctx(grpc_exec_ctx* 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);
@@ -262,10 +262,10 @@ bool grpc_combiner_continue_exec_ctx(grpc_exec_ctx* 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 72f93536f8..46432e4ff2 100644
--- a/src/core/lib/iomgr/error.cc
+++ b/src/core/lib/iomgr/error.cc
@@ -323,7 +323,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
@@ -455,7 +455,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;
}
@@ -466,7 +466,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;
}
@@ -616,7 +616,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),
@@ -686,7 +686,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);
@@ -703,7 +703,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;
@@ -731,7 +731,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;
}
@@ -765,8 +765,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 c81429ef8a..d10bf0b359 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"
@@ -182,9 +183,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 fe1faa68fb..60446f7dd5 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,16 +252,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));
}
@@ -270,7 +270,7 @@ static grpc_fd* fd_create(int fd, const char* name) {
new_fd->write_closure.Init();
gpr_atm_no_barrier_store(&new_fd->read_notifier_pollset, (gpr_atm)NULL);
- new_fd->freelist_next = NULL;
+ new_fd->freelist_next = nullptr;
char* fd_name;
gpr_asprintf(&fd_name, "%s fd=%d", name, fd);
@@ -317,7 +317,7 @@ static void fd_orphan(grpc_exec_ctx* exec_ctx, 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(exec_ctx, fd,
@@ -391,7 +391,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;
@@ -411,7 +411,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;
@@ -468,13 +468,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_exec_ctx* exec_ctx, grpc_pollset* pollset) {
@@ -496,7 +496,7 @@ static void pollset_destroy(grpc_exec_ctx* exec_ctx, 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);
@@ -509,7 +509,7 @@ static grpc_error* pollset_kick_all(grpc_exec_ctx* exec_ctx,
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(exec_ctx);
@@ -543,18 +543,18 @@ static grpc_error* pollset_kick_all(grpc_exec_ctx* exec_ctx,
static void pollset_maybe_finish_shutdown(grpc_exec_ctx* exec_ctx,
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(exec_ctx, pollset->shutdown_closure, GRPC_ERROR_NONE);
- pollset->shutdown_closure = NULL;
+ pollset->shutdown_closure = nullptr;
}
}
static void pollset_shutdown(grpc_exec_ctx* exec_ctx, 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;
@@ -667,7 +667,7 @@ static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset,
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;
@@ -716,7 +716,7 @@ static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset,
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 &&
@@ -794,13 +794,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:
@@ -841,11 +841,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);
@@ -860,7 +860,7 @@ static void end_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset,
if (grpc_polling_trace.enabled()) {
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,
@@ -1002,28 +1002,28 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, 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(exec_ctx);
pollset->kicked_without_poller = true;
if (grpc_polling_trace.enabled()) {
@@ -1232,11 +1232,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();
@@ -1244,7 +1244,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;
diff --git a/src/core/lib/iomgr/ev_epollsig_linux.cc b/src/core/lib/iomgr/ev_epollsig_linux.cc
index 3ee63d7128..689c0d4573 100644
--- a/src/core/lib/iomgr/ev_epollsig_linux.cc
+++ b/src/core/lib/iomgr/ev_epollsig_linux.cc
@@ -328,7 +328,7 @@ static void pi_unref(grpc_exec_ctx* exec_ctx, 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(exec_ctx, pi);
- if (next != NULL) {
+ if (next != nullptr) {
PI_UNREF(exec_ctx, next, "pi_delete"); /* Recursive call */
}
}
@@ -414,7 +414,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 "
@@ -444,7 +444,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,
@@ -468,7 +468,7 @@ static void polling_island_remove_fd_locked(polling_island* pi, grpc_fd* fd,
static polling_island* polling_island_create(grpc_exec_ctx* exec_ctx,
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;
@@ -477,7 +477,7 @@ static polling_island* polling_island_create(grpc_exec_ctx* exec_ctx,
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);
@@ -491,14 +491,14 @@ static polling_island* polling_island_create(grpc_exec_ctx* exec_ctx,
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(exec_ctx, pi);
- pi = NULL;
+ pi = nullptr;
}
return pi;
}
@@ -519,7 +519,7 @@ static void polling_island_delete(grpc_exec_ctx* exec_ctx, 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);
}
@@ -537,18 +537,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;
}
@@ -588,8 +588,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
@@ -607,13 +607,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);
}
@@ -633,7 +633,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;
}
@@ -725,7 +725,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
@@ -797,7 +797,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);
@@ -807,16 +807,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);
}
@@ -825,7 +825,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
@@ -837,8 +837,8 @@ static grpc_fd* fd_create(int fd, const char* name) {
new_fd->write_closure.Init();
gpr_atm_no_barrier_store(&new_fd->read_notifier_pollset, (gpr_atm)NULL);
- 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);
@@ -864,7 +864,7 @@ static void fd_orphan(grpc_exec_ctx* exec_ctx, 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;
@@ -881,18 +881,18 @@ static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* 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);
@@ -904,7 +904,7 @@ static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* 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
@@ -1009,7 +1009,7 @@ static grpc_pollset_worker* pop_front_worker(grpc_pollset* p) {
remove_worker(p, w);
return w;
} else {
- return NULL;
+ return nullptr;
}
}
@@ -1033,7 +1033,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* p,
GRPC_STATS_INC_POLLSET_KICK(exec_ctx);
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);
@@ -1063,7 +1063,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, 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);
@@ -1081,7 +1081,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, 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
@@ -1091,7 +1091,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_exec_ctx* exec_ctx,
@@ -1126,10 +1126,10 @@ static void fd_become_writable(grpc_exec_ctx* exec_ctx, grpc_fd* fd) {
static void pollset_release_polling_island(grpc_exec_ctx* exec_ctx,
grpc_pollset* ps,
const char* reason) {
- if (ps->po.pi != NULL) {
+ if (ps->po.pi != nullptr) {
PI_UNREF(exec_ctx, ps->po.pi, reason);
}
- ps->po.pi = NULL;
+ ps->po.pi = nullptr;
}
static void finish_shutdown_locked(grpc_exec_ctx* exec_ctx,
@@ -1181,7 +1181,7 @@ static void pollset_work_and_unlock(grpc_exec_ctx* exec_ctx,
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);
@@ -1196,9 +1196,9 @@ static void pollset_work_and_unlock(grpc_exec_ctx* exec_ctx,
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(exec_ctx, NULL, error);
- if (pollset->po.pi == NULL) {
+ if (pollset->po.pi == nullptr) {
+ pollset->po.pi = polling_island_create(exec_ctx, nullptr, error);
+ if (pollset->po.pi == nullptr) {
GPR_TIMER_END("pollset_work_and_unlock", 0);
return; /* Fatal error. We cannot continue */
}
@@ -1280,10 +1280,10 @@ static void pollset_work_and_unlock(grpc_exec_ctx* exec_ctx,
}
}
- 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
@@ -1309,7 +1309,7 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, 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);
@@ -1391,7 +1391,7 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, 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);
@@ -1413,7 +1413,7 @@ static void add_poll_object(grpc_exec_ctx* exec_ctx, poll_obj* bag,
#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);
@@ -1440,7 +1440,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
@@ -1460,7 +1460,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)",
@@ -1477,7 +1477,7 @@ retry:
goto retry;
}
} else {
- pi_new = polling_island_create(exec_ctx, NULL, &error);
+ pi_new = polling_island_create(exec_ctx, nullptr, &error);
}
GRPC_POLLING_TRACE(
@@ -1490,7 +1490,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);
@@ -1506,7 +1506,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);
@@ -1530,7 +1530,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(exec_ctx, item->pi, poll_obj_string(item_type));
}
item->pi = pi_new;
@@ -1538,7 +1538,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(exec_ctx, bag->pi, poll_obj_string(bag_type));
}
bag->pi = pi_new;
@@ -1564,7 +1564,7 @@ static void pollset_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset,
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
@@ -1575,7 +1575,7 @@ static void pollset_set_destroy(grpc_exec_ctx* exec_ctx,
grpc_pollset_set* pss) {
gpr_mu_destroy(&pss->po.mu);
- if (pss->po.pi != NULL) {
+ if (pss->po.pi != nullptr) {
PI_UNREF(exec_ctx, pss->po.pi, "pss_destroy");
}
@@ -1712,17 +1712,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) {
@@ -1731,19 +1731,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;
diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc
index d34516f1d4..8659559f78 100644
--- a/src/core/lib/iomgr/ev_poll_posix.cc
+++ b/src/core/lib/iomgr/ev_poll_posix.cc
@@ -335,11 +335,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);
@@ -355,7 +355,7 @@ static bool fd_is_orphaned(grpc_fd* fd) {
/* Return the read-notifier pollset */
static grpc_pollset* fd_get_read_notifier_pollset(grpc_exec_ctx* exec_ctx,
grpc_fd* fd) {
- grpc_pollset* notifier = NULL;
+ grpc_pollset* notifier = nullptr;
gpr_mu_lock(&fd->mu);
notifier = fd->read_notifier_pollset;
@@ -401,7 +401,7 @@ static void wake_all_watchers_locked(grpc_exec_ctx* exec_ctx, 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;
}
@@ -425,8 +425,8 @@ static void fd_orphan(grpc_exec_ctx* exec_ctx, 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) {
@@ -565,9 +565,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;
@@ -576,7 +576,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;
}
@@ -584,12 +584,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;
@@ -609,7 +609,7 @@ static void fd_end_poll(grpc_exec_ctx* exec_ctx, grpc_fd_watcher* watcher,
int kick = 0;
grpc_fd* fd = watcher->fd;
- if (fd == NULL) {
+ if (fd == nullptr) {
return;
}
@@ -621,7 +621,7 @@ static void fd_end_poll(grpc_exec_ctx* exec_ctx, grpc_fd_watcher* watcher,
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 */
@@ -629,9 +629,9 @@ static void fd_end_poll(grpc_exec_ctx* exec_ctx, grpc_fd_watcher* watcher,
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;
@@ -640,7 +640,7 @@ static void fd_end_poll(grpc_exec_ctx* exec_ctx, grpc_fd_watcher* watcher,
if (set_ready_locked(exec_ctx, fd, &fd->read_closure)) {
kick = 1;
}
- if (read_notifier_pollset != NULL) {
+ if (read_notifier_pollset != nullptr) {
set_read_notifier_pollset_locked(exec_ctx, fd, read_notifier_pollset);
}
}
@@ -690,7 +690,7 @@ static grpc_pollset_worker* pop_front_worker(grpc_pollset* p) {
remove_worker(p, w);
return w;
} else {
- return NULL;
+ return nullptr;
}
}
@@ -722,7 +722,7 @@ static grpc_error* pollset_kick_ext(grpc_exec_ctx* exec_ctx, grpc_pollset* p,
GRPC_STATS_INC_POLLSET_KICK(exec_ctx);
/* 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);
@@ -756,7 +756,7 @@ static grpc_error* pollset_kick_ext(grpc_exec_ctx* exec_ctx, 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);
@@ -765,10 +765,10 @@ static grpc_error* pollset_kick_ext(grpc_exec_ctx* exec_ctx, 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(
@@ -812,12 +812,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;
}
@@ -850,7 +850,7 @@ static void pollset_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset,
}
pollset->fds[pollset->fd_count++] = fd;
GRPC_FD_REF(fd, "multipoller");
- pollset_kick(exec_ctx, pollset, NULL);
+ pollset_kick(exec_ctx, pollset, nullptr);
exit:
gpr_mu_unlock(&pollset->mu);
}
@@ -892,9 +892,9 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, 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 {
@@ -1002,8 +1002,8 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset,
}
for (i = 1; i < pfd_count; i++) {
- if (watchers[i].fd == NULL) {
- fd_end_poll(exec_ctx, &watchers[i], 0, 0, NULL);
+ if (watchers[i].fd == nullptr) {
+ fd_end_poll(exec_ctx, &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()
@@ -1012,7 +1012,7 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset,
}
} else if (r == 0) {
for (i = 1; i < pfd_count; i++) {
- fd_end_poll(exec_ctx, &watchers[i], 0, 0, NULL);
+ fd_end_poll(exec_ctx, &watchers[i], 0, 0, nullptr);
}
} else {
if (pfds[0].revents & POLLIN_CHECK) {
@@ -1023,8 +1023,8 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, 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(exec_ctx, &watchers[i], 0, 0, NULL);
+ if (watchers[i].fd == nullptr) {
+ fd_end_poll(exec_ctx, &watchers[i], 0, 0, nullptr);
} else {
if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, "%p got_event: %d r:%d w:%d [%d]", pollset,
@@ -1083,7 +1083,7 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset,
/* check shutdown conditions */
if (pollset->shutting_down) {
if (pollset_has_workers(pollset)) {
- pollset_kick(exec_ctx, pollset, NULL);
+ pollset_kick(exec_ctx, pollset, nullptr);
} else if (!pollset->called_shutdown && !pollset_has_observers(pollset)) {
pollset->called_shutdown = 1;
gpr_mu_unlock(&pollset->mu);
@@ -1101,7 +1101,7 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, 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;
@@ -1319,7 +1319,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++;
}
@@ -1327,7 +1327,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);
@@ -1358,12 +1358,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;
@@ -1373,8 +1373,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);
@@ -1405,7 +1405,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;
@@ -1419,11 +1419,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);
@@ -1520,10 +1520,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;
@@ -1534,7 +1534,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]);
@@ -1573,7 +1573,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;
}
@@ -1624,11 +1624,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];
}
@@ -1639,10 +1639,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);
@@ -1713,10 +1713,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;
}
@@ -1727,7 +1727,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 d5ea169cb6..80dde6d857 100644
--- a/src/core/lib/iomgr/ev_posix.cc
+++ b/src/core/lib/iomgr/ev_posix.cc
@@ -47,7 +47,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);
@@ -110,7 +110,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);
@@ -150,15 +150,15 @@ const char* grpc_get_poll_strategy_name() { return g_poll_strategy_name; }
void grpc_event_engine_init(void) {
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]);
}
@@ -167,7 +167,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();
}
@@ -176,7 +176,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 6661f677f7..b637da377e 100644
--- a/src/core/lib/iomgr/exec_ctx.cc
+++ b/src/core/lib/iomgr/exec_ctx.cc
@@ -25,6 +25,9 @@
#include "src/core/lib/iomgr/combiner.h"
#include "src/core/lib/profiling/timers.h"
+#define GRPC_START_TIME_UPDATE_INTERVAL 10000
+extern grpc_core::TraceFlag grpc_timer_check_trace;
+
bool grpc_exec_ctx_ready_to_finish(grpc_exec_ctx* exec_ctx) {
if ((exec_ctx->flags & GRPC_EXEC_CTX_FLAG_IS_FINISHED) == 0) {
if (exec_ctx->check_ready_to_finish(exec_ctx,
@@ -47,7 +50,7 @@ bool grpc_always_ready_to_finish(grpc_exec_ctx* exec_ctx, void* arg_ignored) {
}
bool grpc_exec_ctx_has_work(grpc_exec_ctx* exec_ctx) {
- return exec_ctx->active_combiner != NULL ||
+ return exec_ctx->active_combiner != nullptr ||
!grpc_closure_list_empty(exec_ctx->closure_list);
}
@@ -82,8 +85,8 @@ bool grpc_exec_ctx_flush(grpc_exec_ctx* exec_ctx) {
for (;;) {
if (!grpc_closure_list_empty(exec_ctx->closure_list)) {
grpc_closure* c = exec_ctx->closure_list.head;
- exec_ctx->closure_list.head = exec_ctx->closure_list.tail = NULL;
- while (c != NULL) {
+ exec_ctx->closure_list.head = exec_ctx->closure_list.tail = nullptr;
+ while (c != nullptr) {
grpc_closure* next = c->next_data.next;
grpc_error* error = c->error_data.error;
did_something = true;
@@ -94,7 +97,7 @@ bool grpc_exec_ctx_flush(grpc_exec_ctx* exec_ctx) {
break;
}
}
- GPR_ASSERT(exec_ctx->active_combiner == NULL);
+ GPR_ASSERT(exec_ctx->active_combiner == nullptr);
GPR_TIMER_END("grpc_exec_ctx_flush", 0);
return did_something;
}
@@ -104,23 +107,49 @@ static void exec_ctx_sched(grpc_exec_ctx* exec_ctx, grpc_closure* closure,
grpc_closure_list_append(&exec_ctx->closure_list, closure, error);
}
-static gpr_timespec
+/* 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;
+}
+
+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);
+}
void grpc_exec_ctx_global_init(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 grpc_exec_ctx_global_shutdown(void) {}
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;
@@ -129,7 +158,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;
@@ -164,8 +195,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) {
@@ -176,6 +208,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_exec_ctx* exec_ctx) {
+ grpc_millis now = grpc_exec_ctx_now(exec_ctx);
+ 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_timer_check_trace.enabled()) {
+ 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};
diff --git a/src/core/lib/iomgr/exec_ctx.h b/src/core/lib/iomgr/exec_ctx.h
index bd27506152..6035e08361 100644
--- a/src/core/lib/iomgr/exec_ctx.h
+++ b/src/core/lib/iomgr/exec_ctx.h
@@ -124,6 +124,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(grpc_exec_ctx* exec_ctx);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc
index da5877479b..d8a195f010 100644
--- a/src/core/lib/iomgr/executor.cc
+++ b/src/core/lib/iomgr/executor.cc
@@ -59,7 +59,7 @@ static size_t run_closures(grpc_exec_ctx* exec_ctx, 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 (executor_trace.enabled()) {
@@ -146,7 +146,7 @@ static void executor_thread(void* arg) {
gpr_tls_set(&g_this_thread_state, (intptr_t)ts);
grpc_exec_ctx exec_ctx =
- GRPC_EXEC_CTX_INITIALIZER(0, grpc_never_ready_to_finish, NULL);
+ GRPC_EXEC_CTX_INITIALIZER(0, grpc_never_ready_to_finish, nullptr);
size_t subtract_depth = 0;
for (;;) {
@@ -206,7 +206,7 @@ static void executor_push(grpc_exec_ctx* exec_ctx, grpc_closure* closure,
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(exec_ctx, cur_thread_count)];
} else {
GRPC_STATS_INC_EXECUTOR_SCHEDULED_TO_SELF(exec_ctx);
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 ff9b31efe2..d112c50538 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
@@ -45,4 +49,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 86ea08e901..e077b35014 100644
--- a/src/core/lib/iomgr/iomgr.cc
+++ b/src/core/lib/iomgr/iomgr.cc
@@ -100,7 +100,7 @@ void grpc_iomgr_shutdown(grpc_exec_ctx* exec_ctx) {
}
exec_ctx->now_is_valid = true;
exec_ctx->now = GRPC_MILLIS_INF_FUTURE;
- if (grpc_timer_check(exec_ctx, NULL) == GRPC_TIMERS_FIRED) {
+ if (grpc_timer_check(exec_ctx, nullptr) == GRPC_TIMERS_FIRED) {
gpr_mu_unlock(&g_mu);
grpc_exec_ctx_flush(exec_ctx);
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 97e448fb32..4a05de1410 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 f0ef2cfe3d..0ee4ea1255 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) {
@@ -60,10 +60,10 @@ void grpc_polling_entity_add_to_pollset_set(grpc_exec_ctx* exec_ctx,
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(exec_ctx, 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(exec_ctx, pss_dst,
pollent->pollent.pollset_set);
} else {
@@ -76,10 +76,10 @@ void grpc_polling_entity_del_from_pollset_set(grpc_exec_ctx* exec_ctx,
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(exec_ctx, 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(exec_ctx, pss_dst,
pollent->pollent.pollset_set);
} else {
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 e27c730204..fb5fa9d422 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++;
@@ -164,7 +164,7 @@ static void do_request_thread(grpc_exec_ctx* exec_ctx, void* rp,
}
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/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 6f6c7a7024..c3ad99d82f 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>
@@ -115,4 +118,6 @@ void grpc_socket_become_ready(grpc_exec_ctx* exec_ctx,
}
#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 f2e759dae7..8a6262b53d 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(grpc_exec_ctx* exec_ctx, void* acp, grpc_error* error) {
str);
}
gpr_mu_lock(&ac->mu);
- if (ac->fd != NULL) {
+ if (ac->fd != nullptr) {
grpc_fd_shutdown(
exec_ctx, ac->fd,
GRPC_ERROR_CREATE_FROM_STATIC_STRING("connect() timed out"));
@@ -147,7 +147,7 @@ static void on_writable(grpc_exec_ctx* exec_ctx, 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(exec_ctx, &ac->alarm);
@@ -175,7 +175,7 @@ static void on_writable(grpc_exec_ctx* exec_ctx, void* acp, grpc_error* error) {
grpc_pollset_set_del_fd(exec_ctx, ac->interested_parties, fd);
*ep = grpc_tcp_client_create_from_fd(exec_ctx, 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
@@ -208,11 +208,11 @@ static void on_writable(grpc_exec_ctx* exec_ctx, void* acp, grpc_error* error) {
}
finish:
- if (fd != NULL) {
+ if (fd != nullptr) {
grpc_pollset_set_del_fd(exec_ctx, ac->interested_parties, fd);
- grpc_fd_orphan(exec_ctx, fd, NULL, NULL, false /* already_closed */,
+ grpc_fd_orphan(exec_ctx, fd, nullptr, nullptr, false /* already_closed */,
"tcp_client_orphan");
- fd = NULL;
+ fd = nullptr;
}
done = (--ac->refs == 0);
gpr_mu_unlock(&ac->mu);
@@ -256,7 +256,7 @@ static void tcp_client_connect_impl(grpc_exec_ctx* exec_ctx,
char* addr_str;
grpc_error* error;
- *ep = NULL;
+ *ep = nullptr;
/* Use dualstack sockets where available. */
if (grpc_sockaddr_to_v4mapped(addr, &addr6_v4mapped)) {
@@ -296,8 +296,8 @@ static void tcp_client_connect_impl(grpc_exec_ctx* exec_ctx,
}
if (errno != EWOULDBLOCK && errno != EINPROGRESS) {
- grpc_fd_orphan(exec_ctx, fdobj, NULL, NULL, false /* already_closed */,
- "tcp_client_connect_error");
+ grpc_fd_orphan(exec_ctx, fdobj, nullptr, nullptr,
+ false /* already_closed */, "tcp_client_connect_error");
GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_OS_ERROR(errno, "connect"));
goto done;
}
@@ -310,7 +310,7 @@ static void tcp_client_connect_impl(grpc_exec_ctx* exec_ctx,
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_server_posix.cc b/src/core/lib/iomgr/tcp_server_posix.cc
index de3f4a6c31..6fed13c6c7 100644
--- a/src/core/lib/iomgr/tcp_server_posix.cc
+++ b/src/core/lib/iomgr/tcp_server_posix.cc
@@ -77,7 +77,7 @@ grpc_error* grpc_tcp_server_create(grpc_exec_ctx* exec_ctx,
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 =
@@ -102,13 +102,13 @@ grpc_error* grpc_tcp_server_create(grpc_exec_ctx* exec_ctx,
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);
@@ -120,7 +120,7 @@ static void finish_shutdown(grpc_exec_ctx* exec_ctx, 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(exec_ctx, s->shutdown_complete, GRPC_ERROR_NONE);
}
@@ -165,7 +165,7 @@ static void deactivated_all_ports(grpc_exec_ctx* exec_ctx, 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(exec_ctx, sp->emfd, &sp->destroyed_closure, NULL,
+ grpc_fd_orphan(exec_ctx, sp->emfd, &sp->destroyed_closure, nullptr,
false /* already_closed */, "tcp_listener_shutdown");
}
gpr_mu_unlock(&s->mu);
@@ -288,8 +288,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;
@@ -314,7 +314,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;
}
@@ -346,7 +346,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;
@@ -383,7 +383,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);
@@ -404,7 +404,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);
@@ -454,7 +454,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,
@@ -498,7 +498,7 @@ void grpc_tcp_server_start(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s,
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 37c0f845fa..4b4da3608f 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_core::TraceFlag 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 aea5bab47d..9c7ccdf132 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_manager.cc b/src/core/lib/iomgr/timer_manager.cc
index 5e06bd657e..383cc6881f 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,11 @@ static void timer_main_loop(grpc_exec_ctx* exec_ctx) {
for (;;) {
grpc_millis next = GRPC_MILLIS_INF_FUTURE;
grpc_exec_ctx_invalidate_now(exec_ctx);
+
+ /* 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(exec_ctx);
+
// check timer state, updates next to the next time to run a check
switch (grpc_timer_check(exec_ctx, &next)) {
case GRPC_TIMERS_FIRED:
@@ -274,7 +279,7 @@ static void timer_thread(void* completed_thread_ptr) {
// this threads exec_ctx: we try to run things through to completion here
// since it's easy to spin up new threads
grpc_exec_ctx exec_ctx =
- GRPC_EXEC_CTX_INITIALIZER(0, grpc_never_ready_to_finish, NULL);
+ GRPC_EXEC_CTX_INITIALIZER(0, grpc_never_ready_to_finish, nullptr);
timer_main_loop(&exec_ctx);
grpc_exec_ctx_finish(&exec_ctx);
timer_thread_cleanup((completed_thread*)completed_thread_ptr);
@@ -298,7 +303,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 8ce8b961ff..68ab9355ca 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;
@@ -155,7 +155,7 @@ static void dummy_cb(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {
}
static void finish_shutdown(grpc_exec_ctx* exec_ctx, grpc_udp_server* s) {
- if (s->shutdown_complete != NULL) {
+ if (s->shutdown_complete != nullptr) {
GRPC_CLOSURE_SCHED(exec_ctx, s->shutdown_complete, GRPC_ERROR_NONE);
}
@@ -213,7 +213,7 @@ static void deactivated_all_ports(grpc_exec_ctx* exec_ctx, grpc_udp_server* s) {
sp->orphan_cb(exec_ctx, sp->emfd, &sp->orphan_fd_closure,
sp->server->user_data);
}
- grpc_fd_orphan(exec_ctx, sp->emfd, &sp->destroyed_closure, NULL,
+ grpc_fd_orphan(exec_ctx, sp->emfd, &sp->destroyed_closure, nullptr,
false /* already_closed */, "udp_listener_shutdown");
}
gpr_mu_unlock(&s->mu);
@@ -256,7 +256,7 @@ void grpc_udp_server_destroy(grpc_exec_ctx* exec_ctx, grpc_udp_server* s,
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);
}
@@ -394,8 +394,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;
@@ -431,7 +431,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;
@@ -508,6 +508,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;
}
@@ -522,7 +523,7 @@ void grpc_udp_server_start(grpc_exec_ctx* exec_ctx, grpc_udp_server* s,
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(exec_ctx, 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; }