From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin-patches@cygwin.com
Subject: Re: Fix nanosleep returning negative rem
Date: Wed, 21 Jul 2021 11:33:05 +0200 [thread overview]
Message-ID: <YPfp0WgZUVo0nap7@calimero.vinschen.de> (raw)
In-Reply-To: <YPfpSgbZbr+bnOWE@calimero.vinschen.de>
[-- Attachment #1: Type: text/plain, Size: 457 bytes --]
On Jul 21 11:30, Corinna Vinschen wrote:
> I wrote a quick STC using the NT API calls and I can't reproduce the
> problem with this code either. The output is either
>
> SignalState: 1 TimeRemaining: -5354077459183
>
> or
>
> SignalState: 0 TimeRemaining: 653
>
> I never get a small negative value in the latter case. Can you
> reproduce your problem with this testcase or tweak it to reproduce it?
Now I actually attached the code :}
Corinna
[-- Attachment #2: timer.c --]
[-- Type: text/plain, Size: 1580 bytes --]
#include <stdio.h>
#include <w32api/windows.h>
#include <w32api/winternl.h>
#include <w32api/ntdef.h>
typedef enum _TIMER_INFORMATION_CLASS {
TimerBasicInformation = 0
} TIMER_INFORMATION_CLASS, *PTIMER_INFORMATION_CLASS;
typedef struct _TIMER_BASIC_INFORMATION {
LARGE_INTEGER TimeRemaining;
BOOLEAN SignalState;
} TIMER_BASIC_INFORMATION, *PTIMER_BASIC_INFORMATION;
NTSTATUS NTAPI NtCreateTimer(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES,
TIMER_TYPE);
NTSTATUS NTAPI NtCancelTimer(HANDLE, PBOOLEAN);
NTSTATUS NTAPI NtSetTimer(HANDLE, PLARGE_INTEGER, PVOID, PVOID,
BOOLEAN, LONG, PBOOLEAN);
NTSTATUS NTAPI NtQueryTimer (HANDLE, TIMER_INFORMATION_CLASS, PVOID,
ULONG, PULONG);
int
main ()
{
HANDLE event;
HANDLE timer;
NTSTATUS status;
LARGE_INTEGER timeout;
TIMER_BASIC_INFORMATION tbi;
event = CreateEvent (NULL, TRUE, FALSE, NULL);
status = NtCreateTimer (&timer, TIMER_ALL_ACCESS, NULL, NotificationTimer);
if (!NT_SUCCESS (status))
{
fprintf (stderr, "NtCreateTimer: 0x%08lx\n", status);
return 1;
}
timeout.QuadPart = -10000000LL; /* 1 sec */
status = NtSetTimer (timer, &timeout, NULL, NULL, FALSE, 0, NULL);
if (!NT_SUCCESS (status))
{
fprintf (stderr, "NtSetTimer: 0x%08lx\n", status);
return 1;
}
WaitForSingleObject (event, 985L);
NtQueryTimer (timer, TimerBasicInformation, &tbi, sizeof tbi, NULL);
printf ("SignalState: %d TimeRemaining: %lld\n", tbi.SignalState,
tbi.TimeRemaining.QuadPart);
NtCancelTimer (timer, NULL);
NtClose (timer);
return 0;
}
next prev parent reply other threads:[~2021-07-21 9:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-20 15:16 David Allsopp
2021-07-21 8:39 ` Corinna Vinschen
2021-07-21 9:07 ` David Allsopp
2021-07-21 9:30 ` Corinna Vinschen
2021-07-21 9:33 ` Corinna Vinschen [this message]
2021-07-21 16:02 ` David Allsopp
2021-07-21 17:57 ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2021-07-22 8:01 ` Corinna Vinschen
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=YPfp0WgZUVo0nap7@calimero.vinschen.de \
--to=corinna-cygwin@cygwin.com \
--cc=cygwin-patches@cygwin.com \
/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: link
Be 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).