ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.c
(Generate patch)

Comparing libev/ev.c (file contents):
Revision 1.525 by root, Wed Jan 22 14:09:07 2020 UTC vs.
Revision 1.537 by sf-exg, Sun May 14 19:02:31 2023 UTC

1/* 1/*
2 * libev event processing core, watcher management 2 * libev event processing core, watcher management
3 * 3 *
4 * Copyright (c) 2007-2019 Marc Alexander Lehmann <libev@schmorp.de> 4 * Copyright (c) 2007-2020 Marc Alexander Lehmann <libev@schmorp.de>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without modifica- 7 * Redistribution and use in source and binary forms, with or without modifica-
8 * tion, are permitted provided that the following conditions are met: 8 * tion, are permitted provided that the following conditions are met:
9 * 9 *
34 * by deleting the provisions above and replace them with the notice 34 * by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL. If you do not delete the 35 * and other provisions required by the GPL. If you do not delete the
36 * provisions above, a recipient may use your version of this file under 36 * provisions above, a recipient may use your version of this file under
37 * either the BSD or the GPL. 37 * either the BSD or the GPL.
38 */ 38 */
39
40#pragma clang diagnostic ignored "-Wunused-value"
41#pragma clang diagnostic ignored "-Wcomment"
42#pragma clang diagnostic ignored "-Wextern-initializer"
39 43
40/* this big block deduces configuration from config.h */ 44/* this big block deduces configuration from config.h */
41#ifndef EV_STANDALONE 45#ifndef EV_STANDALONE
42# ifdef EV_CONFIG_H 46# ifdef EV_CONFIG_H
43# include EV_CONFIG_H 47# include EV_CONFIG_H
491# endif 495# endif
492#endif 496#endif
493 497
494#if EV_USE_IOURING 498#if EV_USE_IOURING
495# include <sys/syscall.h> 499# include <sys/syscall.h>
496# if !SYS_io_uring_setup && __linux && !__alpha 500# if !SYS_io_uring_register && __linux && !__alpha
497# define SYS_io_uring_setup 425 501# define SYS_io_uring_setup 425
498# define SYS_io_uring_enter 426 502# define SYS_io_uring_enter 426
499# define SYS_io_uring_wregister 427 503# define SYS_io_uring_register 427
500# endif 504# endif
501# if SYS_io_uring_setup && EV_USE_EPOLL /* iouring backend requires epoll backend */ 505# if SYS_io_uring_setup && EV_USE_EPOLL /* iouring backend requires epoll backend */
502# define EV_NEED_SYSCALL 1 506# define EV_NEED_SYSCALL 1
503# else 507# else
504# undef EV_USE_IOURING 508# undef EV_USE_IOURING
604/* the following is ecb.h embedded into libev - use update_ev_c to update from an external copy */ 608/* the following is ecb.h embedded into libev - use update_ev_c to update from an external copy */
605/* ECB.H BEGIN */ 609/* ECB.H BEGIN */
606/* 610/*
607 * libecb - http://software.schmorp.de/pkg/libecb 611 * libecb - http://software.schmorp.de/pkg/libecb
608 * 612 *
609 * Copyright (©) 2009-2015 Marc Alexander Lehmann <libecb@schmorp.de> 613 * Copyright (©) 2009-2015,2018-2020 Marc Alexander Lehmann <libecb@schmorp.de>
610 * Copyright (©) 2011 Emanuele Giaquinta 614 * Copyright (©) 2011 Emanuele Giaquinta
611 * All rights reserved. 615 * All rights reserved.
612 * 616 *
613 * Redistribution and use in source and binary forms, with or without modifica- 617 * Redistribution and use in source and binary forms, with or without modifica-
614 * tion, are permitted provided that the following conditions are met: 618 * tion, are permitted provided that the following conditions are met:
649/* 16 bits major, 16 bits minor */ 653/* 16 bits major, 16 bits minor */
650#define ECB_VERSION 0x00010008 654#define ECB_VERSION 0x00010008
651 655
652#include <string.h> /* for memcpy */ 656#include <string.h> /* for memcpy */
653 657
654#ifdef _WIN32 658#if defined (_WIN32) && !defined (__MINGW32__)
655 typedef signed char int8_t; 659 typedef signed char int8_t;
656 typedef unsigned char uint8_t; 660 typedef unsigned char uint8_t;
657 typedef signed char int_fast8_t; 661 typedef signed char int_fast8_t;
658 typedef unsigned char uint_fast8_t; 662 typedef unsigned char uint_fast8_t;
659 typedef signed short int16_t; 663 typedef signed short int16_t;
2392inline_size void 2396inline_size void
2393fd_reify (EV_P) 2397fd_reify (EV_P)
2394{ 2398{
2395 int i; 2399 int i;
2396 2400
2397 /* most backends do not modify the fdchanges list in backend_modfiy. 2401 /* most backends do not modify the fdchanges list in backend_modify.
2398 * except io_uring, which has fixed-size buffers which might force us 2402 * except io_uring, which has fixed-size buffers which might force us
2399 * to handle events in backend_modify, causing fdchanges to be amended, 2403 * to handle events in backend_modify, causing fdchanges to be amended,
2400 * which could result in an endless loop. 2404 * which could result in an endless loop.
2401 * to avoid this, we do not dynamically handle fds that were added 2405 * to avoid this, we do not dynamically handle fds that were added
2402 * during fd_reify. that means that for those backends, fdchangecnt 2406 * during fd_reify. that means that for those backends, fdchangecnt
2471inline_size 2475inline_size
2472void 2476void
2473fd_change (EV_P_ int fd, int flags) 2477fd_change (EV_P_ int fd, int flags)
2474{ 2478{
2475 unsigned char reify = anfds [fd].reify; 2479 unsigned char reify = anfds [fd].reify;
2476 anfds [fd].reify |= flags; 2480 anfds [fd].reify = reify | flags;
2477 2481
2478 if (ecb_expect_true (!reify)) 2482 if (ecb_expect_true (!reify))
2479 { 2483 {
2480 ++fdchangecnt; 2484 ++fdchangecnt;
2481 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit); 2485 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit);
3165 3169
3166 /* TODO: linuxaio is very experimental */ 3170 /* TODO: linuxaio is very experimental */
3167#if !EV_RECOMMEND_LINUXAIO 3171#if !EV_RECOMMEND_LINUXAIO
3168 flags &= ~EVBACKEND_LINUXAIO; 3172 flags &= ~EVBACKEND_LINUXAIO;
3169#endif 3173#endif
3170 /* TODO: linuxaio is super experimental */ 3174 /* TODO: iouring is super experimental */
3171#if !EV_RECOMMEND_IOURING 3175#if !EV_RECOMMEND_IOURING
3172 flags &= ~EVBACKEND_IOURING; 3176 flags &= ~EVBACKEND_IOURING;
3173#endif 3177#endif
3174 3178
3175 return flags; 3179 return flags;
3504#endif 3508#endif
3505 3509
3506 if (postfork != 2) 3510 if (postfork != 2)
3507 { 3511 {
3508 #if EV_USE_SIGNALFD 3512 #if EV_USE_SIGNALFD
3509 /* surprisingly, nothing needs to be done for signalfd, accoridng to docs, it does the right thing on fork */ 3513 /* surprisingly, nothing needs to be done for signalfd, according to docs, it does the right thing on fork */
3510 #endif 3514 #endif
3511 3515
3512 #if EV_USE_TIMERFD 3516 #if EV_USE_TIMERFD
3513 if (ev_is_active (&timerfd_w)) 3517 if (ev_is_active (&timerfd_w))
3514 { 3518 {
4092 4096
4093 if (ecb_expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped))) 4097 if (ecb_expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped)))
4094 { 4098 {
4095 waittime = EV_TS_CONST (MAX_BLOCKTIME); 4099 waittime = EV_TS_CONST (MAX_BLOCKTIME);
4096 4100
4101#if EV_USE_MONOTONIC
4102 if (ecb_expect_true (have_monotonic))
4103 {
4097#if EV_USE_TIMERFD 4104#if EV_USE_TIMERFD
4098 /* sleep a lot longer when we can reliably detect timejumps */ 4105 /* sleep a lot longer when we can reliably detect timejumps */
4099 if (ecb_expect_true (timerfd >= 0)) 4106 if (ecb_expect_true (timerfd != -1))
4100 waittime = EV_TS_CONST (MAX_BLOCKTIME2); 4107 waittime = EV_TS_CONST (MAX_BLOCKTIME2);
4101#endif 4108#endif
4102#if !EV_PERIODIC_ENABLE 4109#if !EV_PERIODIC_ENABLE
4103 /* without periodics but with monotonic clock there is no need */ 4110 /* without periodics but with monotonic clock there is no need */
4104 /* for any time jump detection, so sleep longer */ 4111 /* for any time jump detection, so sleep longer */
4105 if (ecb_expect_true (have_monotonic))
4106 waittime = EV_TS_CONST (MAX_BLOCKTIME2); 4112 waittime = EV_TS_CONST (MAX_BLOCKTIME2);
4113#endif
4114 }
4107#endif 4115#endif
4108 4116
4109 if (timercnt) 4117 if (timercnt)
4110 { 4118 {
4111 ev_tstamp to = ANHE_at (timers [HEAP0]) - mn_now; 4119 ev_tstamp to = ANHE_at (timers [HEAP0]) - mn_now;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines