public inbox for cygwin-cvs@sourceware.org help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org> To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: timerfd: implement execve semantics Date: Wed, 16 Jan 2019 17:41:00 -0000 [thread overview] Message-ID: <20190116174104.25294.qmail@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=0e8c7b8689d18b75371ee3411a3ac68ed37fa3ef commit 0e8c7b8689d18b75371ee3411a3ac68ed37fa3ef Author: Corinna Vinschen <corinna@vinschen.de> Date: Wed Jan 16 18:40:26 2019 +0100 Cygwin: timerfd: implement execve semantics Signed-off-by: Corinna Vinschen <corinna@vinschen.de> Diff: --- winsup/cygwin/fhandler_timerfd.cc | 9 +++++++-- winsup/cygwin/timer.cc | 28 +++++++++++++++++----------- winsup/cygwin/timer.h | 6 ++++-- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/winsup/cygwin/fhandler_timerfd.cc b/winsup/cygwin/fhandler_timerfd.cc index 8ce91af..cbcbefd 100644 --- a/winsup/cygwin/fhandler_timerfd.cc +++ b/winsup/cygwin/fhandler_timerfd.cc @@ -161,10 +161,15 @@ fhandler_timerfd::dup (fhandler_base *child, int flags) void fhandler_timerfd::fixup_after_exec () { - if (!close_on_exec ()) + if (close_on_exec ()) + return; + __try { - /* TODO after exec */ + timer_tracker *tt = (timer_tracker *) timerid; + tt->fixup_after_exec (); } + __except (EFAULT) {} + __endtry } int diff --git a/winsup/cygwin/timer.cc b/winsup/cygwin/timer.cc index bd412f0..be3fcf7 100644 --- a/winsup/cygwin/timer.cc +++ b/winsup/cygwin/timer.cc @@ -108,16 +108,6 @@ timer_tracker::timer_tracker (clockid_t c, const sigevent *e, bool fd) } } -void timer_tracker::increment_instances () -{ - InterlockedIncrement (&instance_count); -} - -LONG timer_tracker::decrement_instances () -{ - return InterlockedDecrement (&instance_count); -} - static inline int64_t timespec_to_us (const timespec& ts) { @@ -152,7 +142,6 @@ timer_tracker::_disarm_event () yield (); if (ret == EVENT_ARMED) { - InterlockedExchange64 (&overrun_count_curr, overrun_count); ret = overrun_count_curr; InterlockedExchange64 (&overrun_count, 0); @@ -461,6 +450,23 @@ timer_tracker::restart () } } +/* Only called from fhandler_timerfd::fixup_after_exec. Note that + we don't touch the instance count. This is handled by closing + the timer from fhandler_timerfd::close on O_CLOEXEC. Ultimately + the instance count should be correct after execve. */ +void +timer_tracker::fixup_after_exec () +{ + lock_timer_tracker here; + /* Check if timer is already in the list. If so, skip it. */ + for (timer_tracker *tt = &ttstart; tt->next != NULL; tt = tt->next) + if (tt->next == this) + return; + next = ttstart.next; + ttstart.next = this; + restart (); +} + void timer_tracker::fixup_after_fork () { diff --git a/winsup/cygwin/timer.h b/winsup/cygwin/timer.h index f4c89bc..3b426a3 100644 --- a/winsup/cygwin/timer.h +++ b/winsup/cygwin/timer.h @@ -30,7 +30,7 @@ class timer_tracker LONG64 overrun_count; bool cancel (); - LONG decrement_instances (); + LONG decrement_instances () { return InterlockedDecrement (&instance_count); } int clean_and_unhook (); LONG64 _disarm_event (); void restart (); @@ -45,7 +45,8 @@ class timer_tracker ~timer_tracker (); inline bool is_timer_tracker () const { return magic == TT_MAGIC; } - void increment_instances (); + + void increment_instances () { InterlockedIncrement (&instance_count); } LONG64 wait (bool nonblocking); HANDLE get_timerfd_handle () const { return timerfd_event; } @@ -58,6 +59,7 @@ class timer_tracker unsigned int disarm_event (); DWORD thread_func (); + void fixup_after_exec (); static void fixup_after_fork (); static int close (timer_tracker *tt); };
reply other threads:[~2019-01-16 17:41 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20190116174104.25294.qmail@sourceware.org \ --to=corinna@sourceware.org \ --cc=cygwin-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).