grpc
src
core
lib
iomgr
wakeup_fd_eventfd.cc
Go to the documentation of this file.
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_LINUX_EVENTFD
24
25
#include <
errno.h
>
26
#include <sys/eventfd.h>
27
#include <unistd.h>
28
29
#include <
grpc/support/log.h
>
30
31
#include "
src/core/lib/iomgr/wakeup_fd_posix.h
"
32
#include "
src/core/lib/profiling/timers.h
"
33
34
static
grpc_error_handle
eventfd_create(
grpc_wakeup_fd
* fd_info) {
35
fd_info->
read_fd
= eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
36
fd_info->
write_fd
= -1;
37
if
(fd_info->
read_fd
< 0) {
38
return
GRPC_OS_ERROR
(errno,
"eventfd"
);
39
}
40
return
GRPC_ERROR_NONE
;
41
}
42
43
static
grpc_error_handle
eventfd_consume(
grpc_wakeup_fd
* fd_info) {
44
eventfd_t
value
;
45
int
err
;
46
do
{
47
err
= eventfd_read(fd_info->
read_fd
, &
value
);
48
}
while
(
err
< 0 && errno == EINTR);
49
if
(
err
< 0 && errno != EAGAIN) {
50
return
GRPC_OS_ERROR
(errno,
"eventfd_read"
);
51
}
52
return
GRPC_ERROR_NONE
;
53
}
54
55
static
grpc_error_handle
eventfd_wakeup(
grpc_wakeup_fd
* fd_info) {
56
GPR_TIMER_SCOPE
(
"eventfd_wakeup"
, 0);
57
int
err
;
58
do
{
59
err
= eventfd_write(fd_info->
read_fd
, 1);
60
}
while
(
err
< 0 && errno == EINTR);
61
if
(
err
< 0) {
62
return
GRPC_OS_ERROR
(errno,
"eventfd_write"
);
63
}
64
return
GRPC_ERROR_NONE
;
65
}
66
67
static
void
eventfd_destroy(
grpc_wakeup_fd
* fd_info) {
68
if
(fd_info->
read_fd
!= 0)
close
(fd_info->
read_fd
);
69
}
70
71
static
int
eventfd_check_availability(
void
) {
72
const
int
efd = eventfd(0, 0);
73
const
int
is_available = efd >= 0;
74
if
(is_available)
close
(efd);
75
return
is_available;
76
}
77
78
const
grpc_wakeup_fd_vtable
grpc_specialized_wakeup_fd_vtable
= {
79
eventfd_create, eventfd_consume, eventfd_wakeup, eventfd_destroy,
80
eventfd_check_availability};
81
82
#endif
/* GRPC_LINUX_EVENTFD */
grpc_wakeup_fd::read_fd
int read_fd
Definition:
wakeup_fd_posix.h:75
GRPC_ERROR_NONE
#define GRPC_ERROR_NONE
Definition:
error.h:234
log.h
grpc_specialized_wakeup_fd_vtable
const grpc_wakeup_fd_vtable grpc_specialized_wakeup_fd_vtable
wakeup_fd_posix.h
timers.h
grpc_wakeup_fd
Definition:
wakeup_fd_posix.h:74
GPR_TIMER_SCOPE
#define GPR_TIMER_SCOPE(tag, important)
Definition:
src/core/lib/profiling/timers.h:43
error_ref_leak.err
err
Definition:
error_ref_leak.py:35
GRPC_OS_ERROR
#define GRPC_OS_ERROR(err, call_name)
create an error associated with errno!=0 (an 'operating system' error)
Definition:
error.h:352
close
#define close
Definition:
test-fs.c:48
grpc_wakeup_fd::write_fd
int write_fd
Definition:
wakeup_fd_posix.h:76
value
const char * value
Definition:
hpack_parser_table.cc:165
port.h
grpc_error
Definition:
error_internal.h:42
grpc_wakeup_fd_vtable
Definition:
wakeup_fd_posix.h:65
errno.h
port_platform.h
grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:52