Exemplo n.º 1
0
void
system_clock_4(GFC_INTEGER_4 *count, GFC_INTEGER_4 *count_rate,
	       GFC_INTEGER_4 *count_max)
{
#if defined(__MINGW32__) || defined(__CYGWIN__) 
  if (count)
    {
      /* Use GetTickCount here as the resolution and range is
	 sufficient for the INTEGER(kind=4) version, and
	 QueryPerformanceCounter has potential issues.  */
      uint32_t cnt = GetTickCount ();
      if (cnt > GFC_INTEGER_4_HUGE)
	cnt -= GFC_INTEGER_4_HUGE - 1;
      *count = cnt;
    }
  if (count_rate)
    *count_rate = 1000;
  if (count_max)
    *count_max = GFC_INTEGER_4_HUGE;
#else
  GFC_INTEGER_4 cnt;
  GFC_INTEGER_4 mx;

  time_t secs;
  long nanosecs, tck;

  if (sizeof (secs) < sizeof (GFC_INTEGER_4))
    internal_error (NULL, "secs too small");

  if (gf_gettime_mono (&secs, &nanosecs, &tck) == 0)
    {
      tck = tck>1000 ? 1000 : tck;
      GFC_UINTEGER_4 ucnt = (GFC_UINTEGER_4) secs * tck;
      ucnt += (nanosecs + 500000000 / tck) / (1000000000 / tck);
      if (ucnt > GFC_INTEGER_4_HUGE)
	cnt = ucnt - GFC_INTEGER_4_HUGE - 1;
      else
	cnt = ucnt;
      mx = GFC_INTEGER_4_HUGE;
    }
  else
    {
      if (count != NULL)
	*count = - GFC_INTEGER_4_HUGE;
      if (count_rate != NULL)
	*count_rate = 0;
      if (count_max != NULL)
	*count_max = 0;
      return;
    }

  if (count != NULL)
    *count = cnt;
  if (count_rate != NULL)
    *count_rate = tck;
  if (count_max != NULL)
    *count_max = mx;
#endif
}
Exemplo n.º 2
0
void
system_clock_8 (GFC_INTEGER_8 *count, GFC_INTEGER_8 *count_rate,
		 GFC_INTEGER_8 *count_max)
{
#if defined(__MINGW32__) || defined(__CYGWIN__) 
  LARGE_INTEGER cnt;
  LARGE_INTEGER freq;
  bool fail = false;
  if (count && !QueryPerformanceCounter (&cnt))
    fail = true;
  if (count_rate && !QueryPerformanceFrequency (&freq))
    fail = true;
  if (fail)
    {
      if (count)
	*count = - GFC_INTEGER_8_HUGE;
      if (count_rate)
	*count_rate = 0;
      if (count_max)
	*count_max = 0;
    }
  else
    {
      if (count)
	*count = cnt.QuadPart;
      if (count_rate)
	*count_rate = freq.QuadPart;
      if (count_max)
	*count_max = GFC_INTEGER_8_HUGE;
    }
#else
  time_t secs;
  long fracsecs, tck;

  if (gf_gettime_mono (&secs, &fracsecs, &tck) == 0)
    {
      GFC_UINTEGER_8 ucnt = (GFC_UINTEGER_8) secs * tck;
      ucnt += fracsecs;
      if (ucnt > GFC_INTEGER_8_HUGE)
	ucnt = ucnt - GFC_INTEGER_8_HUGE - 1;
      if (count)
	*count = ucnt;
      if (count_rate)
	*count_rate = tck;
      if (count_max)
	*count_max = GFC_INTEGER_8_HUGE;
    }
  else
    {
      if (count)
	*count = - GFC_INTEGER_8_HUGE;
      if (count_rate)
	*count_rate = 0;
      if (count_max)
	*count_max = 0;
    }
#endif
}
Exemplo n.º 3
0
void
system_clock_4 (GFC_INTEGER_4 *count, GFC_INTEGER_4 *count_rate,
	       GFC_INTEGER_4 *count_max)
{
#if defined(__MINGW32__) || defined(__CYGWIN__)
  if (count)
    {
      /* Use GetTickCount here as the resolution and range is
	 sufficient for the INTEGER(kind=4) version, and
	 QueryPerformanceCounter has potential issues.  */
      uint32_t cnt = GetTickCount ();
      if (cnt > GFC_INTEGER_4_HUGE)
	cnt = cnt - GFC_INTEGER_4_HUGE - 1;
      *count = cnt;
    }
  if (count_rate)
    *count_rate = 1000;
  if (count_max)
    *count_max = GFC_INTEGER_4_HUGE;
#else
  time_t secs;
  long fracsecs, tck;

  if (gf_gettime_mono (&secs, &fracsecs, &tck) == 0)
    {
      long tck_out = tck > 1000 ? 1000 : tck;
      long tck_r = tck / tck_out;
      GFC_UINTEGER_4 ucnt = (GFC_UINTEGER_4) secs * tck_out;
      ucnt += fracsecs / tck_r;
      if (ucnt > GFC_INTEGER_4_HUGE)
	ucnt = ucnt - GFC_INTEGER_4_HUGE - 1;
      if (count)
	*count = ucnt;
      if (count_rate)
	*count_rate = tck_out;
      if (count_max)
	*count_max = GFC_INTEGER_4_HUGE;
    }
  else
    {
      if (count)
	*count = - GFC_INTEGER_4_HUGE;
      if (count_rate)
	*count_rate = 0;
      if (count_max)
	*count_max = 0;
    }
#endif
}
Exemplo n.º 4
0
void
system_clock_8 (GFC_INTEGER_8 *count, GFC_INTEGER_8 *count_rate,
                GFC_INTEGER_8 *count_max)
{
    GFC_INTEGER_8 cnt;
    GFC_INTEGER_8 mx;

    time_t secs;
    long nanosecs, tck;

    if (sizeof (secs) < sizeof (GFC_INTEGER_4))
        internal_error (NULL, "secs too small");

    if (gf_gettime_mono (&secs, &nanosecs, &tck) == 0)
    {
        GFC_UINTEGER_8 ucnt = (GFC_UINTEGER_8) secs * tck;
        ucnt += (nanosecs + 500000000 / tck) / (1000000000 / tck);
        if (ucnt > GFC_INTEGER_8_HUGE)
            cnt = ucnt - GFC_INTEGER_8_HUGE - 1;
        else
            cnt = ucnt;
        mx = GFC_INTEGER_8_HUGE;
    }
    else
    {
        if (count != NULL)
            *count = - GFC_INTEGER_8_HUGE;
        if (count_rate != NULL)
            *count_rate = 0;
        if (count_max != NULL)
            *count_max = 0;

        return;
    }

    if (count != NULL)
        *count = cnt;
    if (count_rate != NULL)
        *count_rate = tck;
    if (count_max != NULL)
        *count_max = mx;
}
Exemplo n.º 5
0
void
system_clock_8 (GFC_INTEGER_8 *count, GFC_INTEGER_8 *count_rate,
		GFC_INTEGER_8 *count_max)
{
#if defined(__MINGW32__) || defined(__CYGWIN__) 
  LARGE_INTEGER cnt;
  LARGE_INTEGER freq;
  bool fail = false;
  if (count && !QueryPerformanceCounter (&cnt))
    fail = true;
  if (count_rate && !QueryPerformanceFrequency (&freq))
    fail = true;
  if (fail)
    {
      if (count)
	*count = - GFC_INTEGER_8_HUGE;
      if (count_rate)
	*count_rate = 0;
      if (count_max)
	*count_max = 0;
    }
  else
    {
      if (count)
	*count = cnt.QuadPart;
      if (count_rate)
	*count_rate = freq.QuadPart;
      if (count_max)
	*count_max = GFC_INTEGER_8_HUGE;
    }
#else
  GFC_INTEGER_8 cnt;
  GFC_INTEGER_8 mx;

  time_t secs;
  long nanosecs, tck;

  if (sizeof (secs) < sizeof (GFC_INTEGER_4))
    internal_error (NULL, "secs too small");

  if (gf_gettime_mono (&secs, &nanosecs, &tck) == 0)
    {
      GFC_UINTEGER_8 ucnt = (GFC_UINTEGER_8) secs * tck;
      ucnt += (nanosecs + 500000000 / tck) / (1000000000 / tck);
      if (ucnt > GFC_INTEGER_8_HUGE)
	cnt = ucnt - GFC_INTEGER_8_HUGE - 1;
      else
	cnt = ucnt;
      mx = GFC_INTEGER_8_HUGE;
    }
  else
    {
      if (count != NULL)
	*count = - GFC_INTEGER_8_HUGE;
      if (count_rate != NULL)
	*count_rate = 0;
      if (count_max != NULL)
	*count_max = 0;

      return;
    }

  if (count != NULL)
    *count = cnt;
  if (count_rate != NULL)
    *count_rate = tck;
  if (count_max != NULL)
    *count_max = mx;
#endif
}