• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2015 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 #ifdef GRPC_POSIX_WAKEUP_FD
24 
25 #include <stddef.h>
26 #include "src/core/lib/iomgr/wakeup_fd_pipe.h"
27 #include "src/core/lib/iomgr/wakeup_fd_posix.h"
28 
29 static const grpc_wakeup_fd_vtable* wakeup_fd_vtable = nullptr;
30 
31 int grpc_allow_specialized_wakeup_fd = 1;
32 int grpc_allow_pipe_wakeup_fd = 1;
33 
34 int has_real_wakeup_fd = 1;
35 int cv_wakeup_fds_enabled = 0;
36 
grpc_wakeup_fd_global_init(void)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;
44   } else {
45     has_real_wakeup_fd = 0;
46   }
47 }
48 
grpc_wakeup_fd_global_destroy(void)49 void grpc_wakeup_fd_global_destroy(void) { wakeup_fd_vtable = nullptr; }
50 
grpc_has_wakeup_fd(void)51 int grpc_has_wakeup_fd(void) { return has_real_wakeup_fd; }
52 
grpc_wakeup_fd_init(grpc_wakeup_fd * fd_info)53 grpc_error* grpc_wakeup_fd_init(grpc_wakeup_fd* fd_info) {
54   return wakeup_fd_vtable->init(fd_info);
55 }
56 
grpc_wakeup_fd_consume_wakeup(grpc_wakeup_fd * fd_info)57 grpc_error* grpc_wakeup_fd_consume_wakeup(grpc_wakeup_fd* fd_info) {
58   return wakeup_fd_vtable->consume(fd_info);
59 }
60 
grpc_wakeup_fd_wakeup(grpc_wakeup_fd * fd_info)61 grpc_error* grpc_wakeup_fd_wakeup(grpc_wakeup_fd* fd_info) {
62   return wakeup_fd_vtable->wakeup(fd_info);
63 }
64 
grpc_wakeup_fd_destroy(grpc_wakeup_fd * fd_info)65 void grpc_wakeup_fd_destroy(grpc_wakeup_fd* fd_info) {
66   wakeup_fd_vtable->destroy(fd_info);
67 }
68 
69 #endif /* GRPC_POSIX_WAKEUP_FD */
70