1 /*
2 *
3 * Copyright 2018 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19 #include <grpc/support/port_platform.h>
20
21 #include "src/core/lib/iomgr/port.h"
22
23 #include <grpc/support/thd_id.h>
24
25 #include "src/core/lib/iomgr/exec_ctx.h"
26 #include "src/core/lib/iomgr/executor.h"
27 #include "src/core/lib/iomgr/iomgr_custom.h"
28 #include "src/core/lib/iomgr/iomgr_internal.h"
29 #include "src/core/lib/iomgr/pollset_custom.h"
30 #include "src/core/lib/iomgr/pollset_set_custom.h"
31 #include "src/core/lib/iomgr/resolve_address_custom.h"
32
33 gpr_thd_id g_init_thread;
34
iomgr_platform_init(void)35 static void iomgr_platform_init(void) {
36 grpc_core::ExecCtx exec_ctx;
37 grpc_core::Executor::SetThreadingAll(false);
38 g_init_thread = gpr_thd_currentid();
39 grpc_pollset_global_init();
40 }
iomgr_platform_flush(void)41 static void iomgr_platform_flush(void) {}
iomgr_platform_shutdown(void)42 static void iomgr_platform_shutdown(void) { grpc_pollset_global_shutdown(); }
iomgr_platform_shutdown_background_closure(void)43 static void iomgr_platform_shutdown_background_closure(void) {}
iomgr_platform_is_any_background_poller_thread(void)44 static bool iomgr_platform_is_any_background_poller_thread(void) {
45 return false;
46 }
iomgr_platform_add_closure_to_background_poller(grpc_closure *,grpc_error *)47 static bool iomgr_platform_add_closure_to_background_poller(
48 grpc_closure* /*closure*/, grpc_error* /*error*/) {
49 return false;
50 }
51
52 bool g_custom_iomgr_enabled = false;
53
54 static grpc_iomgr_platform_vtable vtable = {
55 iomgr_platform_init,
56 iomgr_platform_flush,
57 iomgr_platform_shutdown,
58 iomgr_platform_shutdown_background_closure,
59 iomgr_platform_is_any_background_poller_thread,
60 iomgr_platform_add_closure_to_background_poller};
61
grpc_custom_iomgr_init(grpc_socket_vtable * socket,grpc_custom_resolver_vtable * resolver,grpc_custom_timer_vtable * timer,grpc_custom_poller_vtable * poller)62 void grpc_custom_iomgr_init(grpc_socket_vtable* socket,
63 grpc_custom_resolver_vtable* resolver,
64 grpc_custom_timer_vtable* timer,
65 grpc_custom_poller_vtable* poller) {
66 g_custom_iomgr_enabled = true;
67 grpc_custom_endpoint_init(socket);
68 grpc_custom_timer_init(timer);
69 grpc_custom_pollset_init(poller);
70 grpc_custom_pollset_set_init();
71 grpc_custom_resolver_init(resolver);
72 grpc_set_iomgr_platform_vtable(&vtable);
73 }
74
75 #ifdef GRPC_CUSTOM_SOCKET
grpc_default_iomgr_platform_vtable()76 grpc_iomgr_platform_vtable* grpc_default_iomgr_platform_vtable() {
77 return &vtable;
78 }
79 #endif
80