1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
|
.\" Copyright (C) 2008 Michael Kerrisk <mtk.manpages@gmail.com>
.\" starting from a version by Davide Libenzi <davidel@xmailserver.org>
.\"
.\" This program is free software; you can redistribute it and/or modify
.\" it under the terms of the GNU General Public License as published by
.\" the Free Software Foundation; either version 2 of the License, or
.\" (at your option) any later version.
.\"
.\" This program is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with this program; if not, write to the Free Software
.\" Foundation, Inc., 59 Temple Place, Suite 330, Boston,
.\" MA 02111-1307 USA
.\"
.\" 2008-10-10, mtk: describe eventfd2(), and EFD_NONBLOCK and EFD_CLOEXEC
.\"
.\" Japanese Version Copyright (c) 2008 Akihiro MOTOKI
.\" all rights reserved.
.\" Translated 2008-04-08, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
.\" Updated 2008-11-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.13
.\"
.TH EVENTFD 2 2009-01-26 Linux "Linux Programmer's Manual"
.SH ̾
eventfd \- ٥ѤΥեǥץ
.SH
.B #include <sys/eventfd.h>
.sp
.BI "int eventfd(unsigned int " initval ", int " flags );
.SH
.BR eventfd ()
"eventfd ֥" 롣
eventfd ֥Ȥϥ桼֥ץꥱ٥Ԥ/Ѥ
ȤߤȤƻȤȤǤ롣ޤͥ뤬桼֥ץꥱ
٥ȤΤ뤿ˤȤȤǤ롣
Υ֥Ȥˤϡunsigned 64 ӥå
.RI ( uint64_t )
ΥޤޤƤꡢΥϥͥˤ롣
Υ
.I initval
ǻꤵ줿ͤǽ롣
Linux 2.6.27 ʹߤǤϡ
ʲͤΤĤӥåñ̤ (OR) ǻꤹ뤳Ȥǡ
.BR eventfd ()
οѹ뤳ȤǤ롣
.TP 14
.B EFD_NONBLOCK
륪ץե뵭 (open file description)
.B O_NONBLOCK
ե륹ơե饰åȤ롣
Υե饰ȤȤǡ
.B O_NONBLOCK
åȤ뤿
.BR fcntl (2)
ɲäǸƤӽФɬפʤʤ롣
.TP
.B EFD_CLOEXEC
եǥץФ
close-on-exec
.RB ( FD_CLOEXEC )
ե饰åȤ롣
Υե饰ΩͳˤĤƤϡ
.BR open (2)
.B O_CLOEXEC
ե饰ȤΤȡ
.PP
С 2.6.26 Linux Ǥϡ
.I flags
̤ѤǤꡢ0 ꤷʤФʤʤ
.BR eventfd ()
eventfd ֥ȤȤΤ˻ѤǤ뿷եǥץ
֤֤줿եǥץФƤϰʲ¹ԤǤ롣
.TP
.BR read (2)
eventfd 0 ʳͤξ硢
.BR read (2)
ϥͤǼ 8 ХȤ֤ͤ
ͤ 0 ˥ꥻåȤ
(֤ͤϥۥȡХȥĤޤ
ۥȥޥɽѤХȥdzǼ)
.IP
.BR read (2)
λǥ 0 ξ硢
.BR read (2)
ϥ 0 ʳˤʤޤ (block) 롢
⤷ϥեǥץ (non-blocking)
ꤵƤϥ顼
.B EAGAIN
ǼԤ롣
.IP
Ϥ줿Хåե礭 8 Х̤ξ硢
.BR read (2)
ϥ顼
.B EINVAL
ǼԤ롣
.TP
.BR write (2)
.BR write (2)
ϡΥХåեϤ줿 8 ХȤͤ˲û롣
˳Ǽǽʺͤ unsigned 64 ӥåκͤ
1 (ʤ 0xfffffffffffffffe) Ǥ롣
ûԤȥͤͤĶ᤹ˤϡ
ΥեǥץФ
.BR read (2)
¹Ԥޤǡ
.BR write (2)
(block) 롢
⤷ϥեǥץ (non-blocking)
ꤵƤϥ顼
.B EAGAIN
ǼԤ롣
.IP
Ϥ줿Хåե礭 8 Х̤ξ硢⤷
0xffffffffffffffff ⤦Ȥ硢
.BR write (2)
ϥ顼
.B EINVAL
ǼԤ롣
.TP
.BR poll "(2), " select "(2) (Ʊͤ)"
֤줿եǥץϡ
.BR poll (2)
.RB ( epoll (7)
Ʊ)
.BR select (2)
ݡȤƤꡢʲΤ褦ư롣
.RS
.IP * 3
0 礭ͤξ硢
եǥץɤ߽ФǽȤʤ
.RB ( select (2)
.I readfds
.BR poll (2)
.B POLLIN
ե饰)
.IP *
ʤȤ "1" (block) ȼ鷺˽硢
եǥץϽ߲ǽȤʤ
.RB ( select (2)
.I writefds
.BR poll (2)
.B POLLOUT
ե饰)
.IP *
ͤΥСեФ줿硢
.BR select (2)
ϥեǥץɤ߽ФǽȽ߲ǽξΤ
.BR poll (2)
.B POLLERR
٥Ȥ֤
Ҥ̤ꡢ
.BR write (2)
ǥСե뤳ȤϷ褷Ƥʤ
ʤ顢 KAIO ֥ƥˤä 2^64 eventfd "signal posts"
¹Ԥ줿ˤϥСե
(ŪˤϤ뤬ŪˤϤʤ)
Сեȯ硢
.BR read (2)
.I uint64_t
κ (ʤ 0xffffffffffffffff) ֤
.RE
.IP
eventfd եǥץϡʳΥեǥץ
¿ API Ǥ
.BR pselect (2),
.BR ppoll (2),
.BR epoll (7)
⥵ݡȤƤ롣
.TP
.BR close (2)
եǥץʹߤɬפʤʤäݤˤϡ٤Ǥ롣
Ʊ eventfd ֥Ȥ˴Ϣդ줿եǥץ
ȡΥ֥Ѥλͥˤ롣
.PP
.BR fork (2)
줿ҥץϡ
.BR eventfd ()
줿եǥץΥԡѾ롣
ʣ줿եǥץƱ eventfd ֥Ȥ˴Ϣդ롣
.BR execve (2)
.BR eventfd ()
줿եǥץݻ롣
.SH ֤
ȡ
.BR eventfd ()
Ͽ eventfd եǥץ֤
顼ξ硢\-1 ֤
.I errno
˥顼ͤꤹ롣
.SH 顼
.TP
.B EINVAL
.I flags
̵
Linux 2.6.26 Ǥϡ
.I flags
0 ʳ͡
.TP
.B EMFILE
ץѤߤΥեǥץοץξ¤
ãƤ
.TP
.B ENFILE
ץѤߤΥեƥΤξ¤ãƤ
.TP
.B ENODEV
.\" Note from Davide:
.\" The ENODEV error is basically never going to happen if
.\" the kernel boots correctly. That error happen only if during
.\" the kernel initialization, some error occur in the anonymous
.\" inode source initialization.
(ͥ) ̵̾ inode ǥХޥȤǤʤä
.TP
.B ENOMEM
eventfd եǥץΤ˽ʬʥ꤬ʤä
.SH С
.BR eventfd ()
ϥͥ 2.6.22 ʹߤ Linux ѲǽǤ롣
ư glibc ¦ΥݡȤϥС 2.8 ʹߤƤ롣
.\" eventfd() is in glibc 2.7, but reportedly does not build
.BR eventfd2 ()
ƥॳ (ա)
ͥ 2.6.27 ʹߤ Linux ѲǽǤ롣
С 2.9 ʹߤǤϡglibc
.BR eventfd ()
Υåѡؿϡͥ뤬бƤ
.BR eventfd2 ()
ƥॳѤ롣
.SH
.BR eventfd ()
.BR eventfd2 ()
Linux ͭǤ롣
.SH
ץꥱϡѥפ٥ȤΤ뤿˻ѤƤ
Ƥξ̤ˤơѥפ eventfd եǥץ
Ѥ뤳ȤǤ롣
eventfd եǥץȤѥפȤ٤
ͥǤΥХإåɤ٤ȤäȾեǥץ
ĤɬפȤʤ (ѥפξɬפǤ)
ͥǻѤȡeventfd եǥץ
֤ͥȥ桼֤Υ֥åǽ뤳ȤǤ
㤨 KAIO (kernel AIO)
.\" eventually syslets/threadlets
Τ褦ʵǽեǥץ˲餫λȤ
Τ뤳ȤǤ롣
eventfd եǥץνפϡ
eventfd եǥץ
.BR select (2),
.BR poll (2),
.BR epoll (7)
Ȥä¾ΥեǥץƱͤ˴ƻǤǤ롣
ΤȤϡץꥱϡֽ (traditional) եξѲ
eventfd եݡȤ¾Υͥ뵡ξѲƱ˴ƻ
Ǥ뤳Ȥ̣
.RB ( eventfd ()
եʤˤϡΥͥ뵡
.BR select (2),
.BR poll (2),
.BR epoll (7)
ͳ¿Ť뤳ȤϤǤʤä)
.SS ؤˤ Linux Υƥॳ
ؤˤ Linux ƥॳढꡢ
.BR eventfd ()
ȡäȿ
.BR eventfd2 ()
Ǥ롣
.BR eventfd ()
.I flags
Ƥʤ
.BR eventfd2 ()
ǤϾ嵭ͤ
.I flags
Ƥ롣
glibc Υåѡؿϡ
.BR eventfd2 ()
ѲǽǤСѤ롣
.SS glibc ɲõǽ
GNU C 饤֥ϡeventfd եǥץɤ߽ФȽߤ
ؤܺ٤ΤĤݲ뤿ˡĤηȡĤδؿɲä
Ƥ롣
.in +4n
.nf
typedef uint64_t eventfd_t;
int eventfd_read(int fd, eventfd_t *value);
int eventfd_write(int fd, eventfd_t value);
.fi
.in
δؿϡeventfd եǥץФɤ߽Ф
ߤ¹ԤХȿž줿ˤ
0 ֤Ǥʤ \-1 ֤
.SH
.PP
ʲΥץ eventfd եǥץ
θ fork ¹Ԥƻҥץ롣
ƥץδ sleep ֤ˡҥץ
ץΥޥɥ饤ǻꤵ줿()줾
eventfd եǥץ˽ࡣ
ƥץ sleep λ eventfd եǥץ
ɤ߽ФԤ
ʲ˼륻åˤΥץλȤ
.in +4n
.nf
.RB "$" " ./a.out 1 2 4 7 14"
Child writing 1 to efd
Child writing 2 to efd
Child writing 4 to efd
Child writing 7 to efd
Child writing 14 to efd
Child completed write loop
Parent about to read
Parent read 28 (0x1c) from efd
.fi
.in
.SS ץΥ
\&
.nf
#include <sys/eventfd.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h> /* Definition of uint64_t */
#define handle_error(msg) \\
do { perror(msg); exit(EXIT_FAILURE); } while (0)
int
main(int argc, char *argv[])
{
int efd, j;
uint64_t u;
ssize_t s;
if (argc < 2) {
fprintf(stderr, "Usage: %s <num>...\\n", argv[0]);
exit(EXIT_FAILURE);
}
efd = eventfd(0, 0);
if (efd == \-1)
handle_error("eventfd");
switch (fork()) {
case 0:
for (j = 1; j < argc; j++) {
printf("Child writing %s to efd\\n", argv[j]);
u = strtoull(argv[j], NULL, 0);
/* strtoull() allows various bases */
s = write(efd, &u, sizeof(uint64_t));
if (s != sizeof(uint64_t))
handle_error("write");
}
printf("Child completed write loop\\n");
exit(EXIT_SUCCESS);
default:
sleep(2);
printf("Parent about to read\\n");
s = read(efd, &u, sizeof(uint64_t));
if (s != sizeof(uint64_t))
handle_error("read");
printf("Parent read %llu (0x%llx) from efd\\n",
(unsigned long long) u, (unsigned long long) u);
exit(EXIT_SUCCESS);
case \-1:
handle_error("fork");
}
}
.fi
.SH Ϣ
.BR futex (2),
.BR pipe (2),
.BR poll (2),
.BR read (2),
.BR select (2),
.BR signalfd (2),
.BR timerfd_create (2),
.BR write (2),
.BR epoll (7),
.BR sem_overview (7)
|