From 1c52f49354aa83e71fcceccae888da0c77f2391d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 1 Oct 2021 09:54:41 +0000 Subject: ds: simplify signalfd use Since signalfd is often combined with our event loop, give it a convenient API and reduce the code duplication required to use it. EventLoop is replaced with ::event_loop to allow consistent parameter passing and avoid needlessly passing the package name on stack. We also avoid exporting SFD_NONBLOCK since it's the only flag we support. There's no sense in having the memory overhead of a constant function when it's in cold code. --- lib/PublicInbox/Syscall.pm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib/PublicInbox/Syscall.pm') diff --git a/lib/PublicInbox/Syscall.pm b/lib/PublicInbox/Syscall.pm index a8a6f42a..7ab42911 100644 --- a/lib/PublicInbox/Syscall.pm +++ b/lib/PublicInbox/Syscall.pm @@ -22,7 +22,7 @@ our @EXPORT_OK = qw(epoll_ctl epoll_create epoll_wait EPOLLIN EPOLLOUT EPOLLET EPOLL_CTL_ADD EPOLL_CTL_DEL EPOLL_CTL_MOD EPOLLONESHOT EPOLLEXCLUSIVE - signalfd SFD_NONBLOCK); + signalfd); our %EXPORT_TAGS = (epoll => [qw(epoll_ctl epoll_create epoll_wait EPOLLIN EPOLLOUT EPOLL_CTL_ADD EPOLL_CTL_DEL EPOLL_CTL_MOD @@ -67,7 +67,6 @@ our ( ); my $SFD_CLOEXEC = 02000000; # Perl does not expose O_CLOEXEC -sub SFD_NONBLOCK () { O_NONBLOCK } our $no_deprecated = 0; if ($^O eq "linux") { @@ -266,14 +265,15 @@ sub epoll_wait_mod8 { } } -sub signalfd ($$$) { - my ($fd, $signos, $flags) = @_; +sub signalfd ($$) { + my ($signos, $nonblock) = @_; if ($SYS_signalfd4) { my $set = POSIX::SigSet->new(@$signos); - syscall($SYS_signalfd4, $fd, "$$set", + syscall($SYS_signalfd4, -1, "$$set", # $Config{sig_count} is NSIG, so this is NSIG/8: int($Config{sig_count}/8), - $flags|$SFD_CLOEXEC); + # SFD_NONBLOCK == O_NONBLOCK for every architecture + ($nonblock ? O_NONBLOCK : 0) |$SFD_CLOEXEC); } else { $! = ENOSYS; undef; -- cgit v1.2.3-24-ge0c7