3 * Copyright 2015 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <grpc/support/port_platform.h>
21 #include "src/core/lib/iomgr/port.h"
23 #ifdef GRPC_POSIX_WAKEUP_FD
26 #include "src/core/lib/iomgr/wakeup_fd_pipe.h"
27 #include "src/core/lib/iomgr/wakeup_fd_posix.h"
29 static const grpc_wakeup_fd_vtable* wakeup_fd_vtable = nullptr;
31 int grpc_allow_specialized_wakeup_fd = 1;
32 int grpc_allow_pipe_wakeup_fd = 1;
34 int has_real_wakeup_fd = 1;
35 int cv_wakeup_fds_enabled = 0;
37 void grpc_wakeup_fd_global_init(void) {
38 if (grpc_allow_specialized_wakeup_fd &&
39 grpc_specialized_wakeup_fd_vtable.check_availability()) {
40 wakeup_fd_vtable = &grpc_specialized_wakeup_fd_vtable;
41 } else if (grpc_allow_pipe_wakeup_fd &&
42 grpc_pipe_wakeup_fd_vtable.check_availability()) {
43 wakeup_fd_vtable = &grpc_pipe_wakeup_fd_vtable;
45 has_real_wakeup_fd = 0;
49 void grpc_wakeup_fd_global_destroy(void) { wakeup_fd_vtable = nullptr; }
51 int grpc_has_wakeup_fd(void) { return has_real_wakeup_fd; }
53 grpc_error* grpc_wakeup_fd_init(grpc_wakeup_fd* fd_info) {
54 return wakeup_fd_vtable->init(fd_info);
57 grpc_error* grpc_wakeup_fd_consume_wakeup(grpc_wakeup_fd* fd_info) {
58 return wakeup_fd_vtable->consume(fd_info);
61 grpc_error* grpc_wakeup_fd_wakeup(grpc_wakeup_fd* fd_info) {
62 return wakeup_fd_vtable->wakeup(fd_info);
65 void grpc_wakeup_fd_destroy(grpc_wakeup_fd* fd_info) {
66 wakeup_fd_vtable->destroy(fd_info);
69 #endif /* GRPC_POSIX_WAKEUP_FD */