mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-13 07:56:17 +01:00
gtimer.c: Revert accidental overwrite
Revert accidental overwrite as timing API was changed from 2.27.2 to 2.27.3
This commit is contained in:
parent
db7ea5e558
commit
029f3070e7
@ -54,7 +54,7 @@
|
||||
#include "gmem.h"
|
||||
#include "gstrfuncs.h"
|
||||
#include "gtestutils.h"
|
||||
#include "gthread.h"
|
||||
#include "gmain.h"
|
||||
|
||||
/**
|
||||
* SECTION: timers
|
||||
@ -65,19 +65,8 @@
|
||||
* that time. This is done somewhat differently on different platforms,
|
||||
* and can be tricky to get exactly right, so #GTimer provides a
|
||||
* portable/convenient interface.
|
||||
*
|
||||
* <note><para>
|
||||
* #GTimer uses a higher-quality clock when thread support is available.
|
||||
* Therefore, calling g_thread_init() while timers are running may lead to
|
||||
* unreliable results. It is best to call g_thread_init() before starting any
|
||||
* timers, if you are using threads at all.
|
||||
* </para></note>
|
||||
**/
|
||||
|
||||
#define G_NSEC_PER_SEC 1000000000
|
||||
|
||||
#define GETTIME(v) (v = g_thread_gettime ())
|
||||
|
||||
/**
|
||||
* GTimer:
|
||||
*
|
||||
@ -106,7 +95,7 @@ g_timer_new (void)
|
||||
timer = g_new (GTimer, 1);
|
||||
timer->active = TRUE;
|
||||
|
||||
GETTIME (timer->start);
|
||||
timer->start = g_get_monotonic_time ();
|
||||
|
||||
return timer;
|
||||
}
|
||||
@ -141,7 +130,7 @@ g_timer_start (GTimer *timer)
|
||||
|
||||
timer->active = TRUE;
|
||||
|
||||
GETTIME (timer->start);
|
||||
timer->start = g_get_monotonic_time ();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -158,7 +147,7 @@ g_timer_stop (GTimer *timer)
|
||||
|
||||
timer->active = FALSE;
|
||||
|
||||
GETTIME (timer->end);
|
||||
timer->end = g_get_monotonic_time ();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -174,7 +163,7 @@ g_timer_reset (GTimer *timer)
|
||||
{
|
||||
g_return_if_fail (timer != NULL);
|
||||
|
||||
GETTIME (timer->start);
|
||||
timer->start = g_get_monotonic_time ();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -202,7 +191,7 @@ g_timer_continue (GTimer *timer)
|
||||
|
||||
elapsed = timer->end - timer->start;
|
||||
|
||||
GETTIME (timer->start);
|
||||
timer->start = g_get_monotonic_time ();
|
||||
|
||||
timer->start -= elapsed;
|
||||
|
||||
@ -240,7 +229,7 @@ g_timer_elapsed (GTimer *timer,
|
||||
g_return_val_if_fail (timer != NULL, 0);
|
||||
|
||||
if (timer->active)
|
||||
GETTIME (timer->end);
|
||||
timer->end = g_get_monotonic_time ();
|
||||
|
||||
elapsed = timer->end - timer->start;
|
||||
|
||||
@ -257,57 +246,13 @@ g_usleep (gulong microseconds)
|
||||
{
|
||||
#ifdef G_OS_WIN32
|
||||
Sleep (microseconds / 1000);
|
||||
#else /* !G_OS_WIN32 */
|
||||
# ifdef HAVE_NANOSLEEP
|
||||
#else
|
||||
struct timespec request, remaining;
|
||||
request.tv_sec = microseconds / G_USEC_PER_SEC;
|
||||
request.tv_nsec = 1000 * (microseconds % G_USEC_PER_SEC);
|
||||
while (nanosleep (&request, &remaining) == -1 && errno == EINTR)
|
||||
request = remaining;
|
||||
# else /* !HAVE_NANOSLEEP */
|
||||
# ifdef HAVE_NSLEEP
|
||||
/* on AIX, nsleep is analogous to nanosleep */
|
||||
struct timespec request, remaining;
|
||||
request.tv_sec = microseconds / G_USEC_PER_SEC;
|
||||
request.tv_nsec = 1000 * (microseconds % G_USEC_PER_SEC);
|
||||
while (nsleep (&request, &remaining) == -1 && errno == EINTR)
|
||||
request = remaining;
|
||||
# else /* !HAVE_NSLEEP */
|
||||
if (g_thread_supported ())
|
||||
{
|
||||
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
|
||||
static GCond* cond = NULL;
|
||||
GTimeVal end_time;
|
||||
|
||||
g_get_current_time (&end_time);
|
||||
if (microseconds > G_MAXLONG)
|
||||
{
|
||||
microseconds -= G_MAXLONG;
|
||||
g_time_val_add (&end_time, G_MAXLONG);
|
||||
}
|
||||
g_time_val_add (&end_time, microseconds);
|
||||
|
||||
g_static_mutex_lock (&mutex);
|
||||
|
||||
if (!cond)
|
||||
cond = g_cond_new ();
|
||||
|
||||
while (g_cond_timed_wait (cond, g_static_mutex_get_mutex (&mutex),
|
||||
&end_time))
|
||||
/* do nothing */;
|
||||
|
||||
g_static_mutex_unlock (&mutex);
|
||||
}
|
||||
else
|
||||
{
|
||||
struct timeval tv;
|
||||
tv.tv_sec = microseconds / G_USEC_PER_SEC;
|
||||
tv.tv_usec = microseconds % G_USEC_PER_SEC;
|
||||
select(0, NULL, NULL, NULL, &tv);
|
||||
}
|
||||
# endif /* !HAVE_NSLEEP */
|
||||
# endif /* !HAVE_NANOSLEEP */
|
||||
#endif /* !G_OS_WIN32 */
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user