diff options
author | 2017-10-13 16:07:13 -0700 | |
---|---|---|
committer | 2017-10-18 17:12:19 -0700 | |
commit | 0ee7574732a06e8cace4e099a678f4bd5dbff679 (patch) | |
tree | e43d5de442fdcc3d39cd5af687f319fa39612d3f /src/core/lib/iomgr/iocp_windows.cc | |
parent | 6bf5f833efe2cb9e2ecc14358dd9699cd5d05263 (diff) |
Removing instances of exec_ctx being passed around in functions in
src/core. exec_ctx is now a thread_local pointer of type ExecCtx instead of
grpc_exec_ctx which is initialized whenever ExecCtx is instantiated. ExecCtx
also keeps track of the previous exec_ctx so that nesting of exec_ctx is
allowed. This means that there is only one exec_ctx being used at any
time. Also, grpc_exec_ctx_finish is called in the destructor of the
object, and the previous exec_ctx is restored to avoid breaking current
functionality. The code still explicitly calls grpc_exec_ctx_finish
because removing all such instances causes the code to break.
Diffstat (limited to 'src/core/lib/iomgr/iocp_windows.cc')
-rw-r--r-- | src/core/lib/iomgr/iocp_windows.cc | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/src/core/lib/iomgr/iocp_windows.cc b/src/core/lib/iomgr/iocp_windows.cc index 78185cc084..885a78bdfa 100644 --- a/src/core/lib/iomgr/iocp_windows.cc +++ b/src/core/lib/iomgr/iocp_windows.cc @@ -42,20 +42,18 @@ static gpr_atm g_custom_events = 0; static HANDLE g_iocp; -static DWORD deadline_to_millis_timeout(grpc_exec_ctx *exec_ctx, - grpc_millis deadline) { +static DWORD deadline_to_millis_timeout(grpc_millis deadline) { if (deadline == GRPC_MILLIS_INF_FUTURE) { return INFINITE; } - grpc_millis now = grpc_exec_ctx_now(exec_ctx); + grpc_millis now = grpc_exec_ctx_now(); if (deadline < now) return 0; grpc_millis timeout = deadline - now; if (timeout > std::numeric_limits<DWORD>::max()) return INFINITE; return static_cast<DWORD>(deadline - now); } -grpc_iocp_work_status grpc_iocp_work(grpc_exec_ctx *exec_ctx, - grpc_millis deadline) { +grpc_iocp_work_status grpc_iocp_work(grpc_millis deadline) { BOOL success; DWORD bytes = 0; DWORD flags = 0; @@ -63,11 +61,11 @@ grpc_iocp_work_status grpc_iocp_work(grpc_exec_ctx *exec_ctx, LPOVERLAPPED overlapped; grpc_winsocket *socket; grpc_winsocket_callback_info *info; - GRPC_STATS_INC_SYSCALL_POLL(exec_ctx); + GRPC_STATS_INC_SYSCALL_POLL(); success = GetQueuedCompletionStatus(g_iocp, &bytes, &completion_key, &overlapped, - deadline_to_millis_timeout(exec_ctx, deadline)); - grpc_exec_ctx_invalidate_now(exec_ctx); + deadline_to_millis_timeout(deadline)); + grpc_exec_ctx_invalidate_now(); if (success == 0 && overlapped == NULL) { return GRPC_IOCP_WORK_TIMEOUT; } @@ -95,7 +93,7 @@ grpc_iocp_work_status grpc_iocp_work(grpc_exec_ctx *exec_ctx, info->bytes_transfered = bytes; info->wsa_error = success ? 0 : WSAGetLastError(); GPR_ASSERT(overlapped == &info->overlapped); - grpc_socket_become_ready(exec_ctx, socket, info); + grpc_socket_become_ready(socket, info); return GRPC_IOCP_WORK_WORK; } @@ -115,22 +113,21 @@ void grpc_iocp_kick(void) { } void grpc_iocp_flush(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + ExecCtx _local_exec_ctx; grpc_iocp_work_status work_status; do { - work_status = grpc_iocp_work(&exec_ctx, GRPC_MILLIS_INF_PAST); - } while (work_status == GRPC_IOCP_WORK_KICK || - grpc_exec_ctx_flush(&exec_ctx)); + work_status = grpc_iocp_work(GRPC_MILLIS_INF_PAST); + } while (work_status == GRPC_IOCP_WORK_KICK || grpc_exec_ctx_flush()); } void grpc_iocp_shutdown(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + ExecCtx _local_exec_ctx; while (gpr_atm_acq_load(&g_custom_events)) { - grpc_iocp_work(&exec_ctx, GRPC_MILLIS_INF_FUTURE); - grpc_exec_ctx_flush(&exec_ctx); + grpc_iocp_work(GRPC_MILLIS_INF_FUTURE); + grpc_exec_ctx_flush(); } - grpc_exec_ctx_finish(&exec_ctx); + grpc_exec_ctx_finish(); GPR_ASSERT(CloseHandle(g_iocp)); } |