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_executor_set_threading(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(); }
43
44 static grpc_iomgr_platform_vtable vtable = {
45 iomgr_platform_init, iomgr_platform_flush, iomgr_platform_shutdown};
46
grpc_custom_iomgr_init(grpc_socket_vtable * socket,grpc_custom_resolver_vtable * resolver,grpc_custom_timer_vtable * timer,grpc_custom_poller_vtable * poller)47 void grpc_custom_iomgr_init(grpc_socket_vtable* socket,
48 grpc_custom_resolver_vtable* resolver,
49 grpc_custom_timer_vtable* timer,
50 grpc_custom_poller_vtable* poller) {
51 grpc_custom_endpoint_init(socket);
52 grpc_custom_timer_init(timer);
53 grpc_custom_pollset_init(poller);
54 grpc_custom_pollset_set_init();
55 grpc_custom_resolver_init(resolver);
56 grpc_set_iomgr_platform_vtable(&vtable);
57 }
58
59 #ifdef GRPC_CUSTOM_SOCKET
grpc_default_iomgr_platform_vtable()60 grpc_iomgr_platform_vtable* grpc_default_iomgr_platform_vtable() {
61 return &vtable;
62 }
63 #endif
64