This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] clock_nanosleep(2)


On Tue, 2011-08-02 at 17:42 +0200, Corinna Vinschen wrote:
> Does that mean the return value from NtQueryTimer is unreliable?
> In what way is it wrong?  

I'm not sure.  When I run an STC (attached), it works as expected.  In
cancelable_wait(), however, it returns the negative system uptime.  Is
Cygwin doing something to make this occur?

> Does nanosleep wait too long or not long enough?

That doesn't seem to be an issue.

> If NtQueryTimer is unusable, maybe we should just skip the idea to return
> the remaining time from cancelabel_wait and simply use the return
> value from hires_ms::timeGetTime_ns() to return the remaining time
> from {clock_}nanosleep

I'd rather avoid this type of workaround, particularly with
clock_nanosleep having to deal with CLOCK_MONOTONIC as well.

> > and the pthread_spin chunk doesn't look right (previously
> > the timeout would repeat in the while loop, but that won't happen the
> > way the waitable timer is set up).
> 
> It doesn't look wrong to me, but then again, I didn't test it...

You're right, since we pay no attention to the return value of
cancelable_wait() here.


Yaakov

#pragma CCOD:script no
#pragma CCOD:options -lntdll

#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <ddk/ntapi.h>

int main(void) {
  HANDLE timer;
  LARGE_INTEGER li;
  PTIMER_BASIC_INFORMATION tbi;
  const size_t sizeof_tbi = sizeof (TIMER_BASIC_INFORMATION);
  int i;

  li.QuadPart = -20000000LL;

  NtCreateTimer (&timer, TIMER_ALL_ACCESS, NULL, NotificationTimer);

  for (i = 0; i < 10; i++)
    {
      NtSetTimer (timer, &li, NULL, NULL, FALSE, 0, NULL);
      WaitForSingleObject (timer, 1000);

      tbi = (PTIMER_BASIC_INFORMATION) malloc (sizeof_tbi);
      NtQueryTimer (timer, TimerBasicInformation, tbi, sizeof_tbi, NULL);
      NtCancelTimer (timer, NULL);

      printf ("%ld.%09ld\n", (long) (tbi->TimeRemaining.QuadPart / 10000000LL),
	      (long) ((tbi->TimeRemaining.QuadPart % 10000000LL) * 100LL));
    }

  NtClose (timer);

  return 0;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]