mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-27 14:36:16 +01:00
Look for nanosleep function.
2001-06-07 Sebastian Wilhelmi <wilhelmi@ira.uka.de> * configure.in: Look for nanosleep function. * gtimer.c: Use nanosleep for g_usleep, when found. * gtimer.c, gtimer.h: Add g_time_val_add function. Closes #54271. * gasyncqueue.c: Documentation updates. * gthreadpool.c: Use g_time_val_add now that we have it. * glib/glib-sections.txt, glib/tmpl/date.sgml: Add g_time_val_add. * glib/tmpl/threads.sgml: Updated.
This commit is contained in:
parent
9600d5cd53
commit
632943f359
12
ChangeLog
12
ChangeLog
@ -1,3 +1,15 @@
|
|||||||
|
2001-06-07 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* configure.in: Look for nanosleep function.
|
||||||
|
|
||||||
|
* gtimer.c: Use nanosleep for g_usleep, when found.
|
||||||
|
|
||||||
|
* gtimer.c, gtimer.h: Add g_time_val_add function. Closes #54271.
|
||||||
|
|
||||||
|
* gasyncqueue.c: Documentation updates.
|
||||||
|
|
||||||
|
* gthreadpool.c: Use g_time_val_add now that we have it.
|
||||||
|
|
||||||
2001-06-01 Jon Trowbridge <trow@gnu.org>
|
2001-06-01 Jon Trowbridge <trow@gnu.org>
|
||||||
|
|
||||||
* gdate.c (g_date_update_julian): Changed to take a const
|
* gdate.c (g_date_update_julian): Changed to take a const
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
2001-06-07 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* configure.in: Look for nanosleep function.
|
||||||
|
|
||||||
|
* gtimer.c: Use nanosleep for g_usleep, when found.
|
||||||
|
|
||||||
|
* gtimer.c, gtimer.h: Add g_time_val_add function. Closes #54271.
|
||||||
|
|
||||||
|
* gasyncqueue.c: Documentation updates.
|
||||||
|
|
||||||
|
* gthreadpool.c: Use g_time_val_add now that we have it.
|
||||||
|
|
||||||
2001-06-01 Jon Trowbridge <trow@gnu.org>
|
2001-06-01 Jon Trowbridge <trow@gnu.org>
|
||||||
|
|
||||||
* gdate.c (g_date_update_julian): Changed to take a const
|
* gdate.c (g_date_update_julian): Changed to take a const
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
2001-06-07 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* configure.in: Look for nanosleep function.
|
||||||
|
|
||||||
|
* gtimer.c: Use nanosleep for g_usleep, when found.
|
||||||
|
|
||||||
|
* gtimer.c, gtimer.h: Add g_time_val_add function. Closes #54271.
|
||||||
|
|
||||||
|
* gasyncqueue.c: Documentation updates.
|
||||||
|
|
||||||
|
* gthreadpool.c: Use g_time_val_add now that we have it.
|
||||||
|
|
||||||
2001-06-01 Jon Trowbridge <trow@gnu.org>
|
2001-06-01 Jon Trowbridge <trow@gnu.org>
|
||||||
|
|
||||||
* gdate.c (g_date_update_julian): Changed to take a const
|
* gdate.c (g_date_update_julian): Changed to take a const
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
2001-06-07 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* configure.in: Look for nanosleep function.
|
||||||
|
|
||||||
|
* gtimer.c: Use nanosleep for g_usleep, when found.
|
||||||
|
|
||||||
|
* gtimer.c, gtimer.h: Add g_time_val_add function. Closes #54271.
|
||||||
|
|
||||||
|
* gasyncqueue.c: Documentation updates.
|
||||||
|
|
||||||
|
* gthreadpool.c: Use g_time_val_add now that we have it.
|
||||||
|
|
||||||
2001-06-01 Jon Trowbridge <trow@gnu.org>
|
2001-06-01 Jon Trowbridge <trow@gnu.org>
|
||||||
|
|
||||||
* gdate.c (g_date_update_julian): Changed to take a const
|
* gdate.c (g_date_update_julian): Changed to take a const
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
2001-06-07 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* configure.in: Look for nanosleep function.
|
||||||
|
|
||||||
|
* gtimer.c: Use nanosleep for g_usleep, when found.
|
||||||
|
|
||||||
|
* gtimer.c, gtimer.h: Add g_time_val_add function. Closes #54271.
|
||||||
|
|
||||||
|
* gasyncqueue.c: Documentation updates.
|
||||||
|
|
||||||
|
* gthreadpool.c: Use g_time_val_add now that we have it.
|
||||||
|
|
||||||
2001-06-01 Jon Trowbridge <trow@gnu.org>
|
2001-06-01 Jon Trowbridge <trow@gnu.org>
|
||||||
|
|
||||||
* gdate.c (g_date_update_julian): Changed to take a const
|
* gdate.c (g_date_update_julian): Changed to take a const
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
2001-06-07 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* configure.in: Look for nanosleep function.
|
||||||
|
|
||||||
|
* gtimer.c: Use nanosleep for g_usleep, when found.
|
||||||
|
|
||||||
|
* gtimer.c, gtimer.h: Add g_time_val_add function. Closes #54271.
|
||||||
|
|
||||||
|
* gasyncqueue.c: Documentation updates.
|
||||||
|
|
||||||
|
* gthreadpool.c: Use g_time_val_add now that we have it.
|
||||||
|
|
||||||
2001-06-01 Jon Trowbridge <trow@gnu.org>
|
2001-06-01 Jon Trowbridge <trow@gnu.org>
|
||||||
|
|
||||||
* gdate.c (g_date_update_julian): Changed to take a const
|
* gdate.c (g_date_update_julian): Changed to take a const
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
2001-06-07 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* configure.in: Look for nanosleep function.
|
||||||
|
|
||||||
|
* gtimer.c: Use nanosleep for g_usleep, when found.
|
||||||
|
|
||||||
|
* gtimer.c, gtimer.h: Add g_time_val_add function. Closes #54271.
|
||||||
|
|
||||||
|
* gasyncqueue.c: Documentation updates.
|
||||||
|
|
||||||
|
* gthreadpool.c: Use g_time_val_add now that we have it.
|
||||||
|
|
||||||
2001-06-01 Jon Trowbridge <trow@gnu.org>
|
2001-06-01 Jon Trowbridge <trow@gnu.org>
|
||||||
|
|
||||||
* gdate.c (g_date_update_julian): Changed to take a const
|
* gdate.c (g_date_update_julian): Changed to take a const
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
2001-06-07 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* configure.in: Look for nanosleep function.
|
||||||
|
|
||||||
|
* gtimer.c: Use nanosleep for g_usleep, when found.
|
||||||
|
|
||||||
|
* gtimer.c, gtimer.h: Add g_time_val_add function. Closes #54271.
|
||||||
|
|
||||||
|
* gasyncqueue.c: Documentation updates.
|
||||||
|
|
||||||
|
* gthreadpool.c: Use g_time_val_add now that we have it.
|
||||||
|
|
||||||
2001-06-01 Jon Trowbridge <trow@gnu.org>
|
2001-06-01 Jon Trowbridge <trow@gnu.org>
|
||||||
|
|
||||||
* gdate.c (g_date_update_julian): Changed to take a const
|
* gdate.c (g_date_update_julian): Changed to take a const
|
||||||
|
@ -460,7 +460,7 @@ GLIB_SIZEOF([$size_includes], ptrdiff_t, ptrdiff_t)
|
|||||||
GLIB_SIZEOF([$size_includes], intmax_t, intmax_t)
|
GLIB_SIZEOF([$size_includes], intmax_t, intmax_t)
|
||||||
|
|
||||||
# Check for some functions
|
# Check for some functions
|
||||||
AC_CHECK_FUNCS(lstat strerror strsignal memmove mkstemp vsnprintf stpcpy strcasecmp strncasecmp poll getcwd)
|
AC_CHECK_FUNCS(lstat strerror strsignal memmove mkstemp vsnprintf stpcpy strcasecmp strncasecmp poll getcwd nanosleep)
|
||||||
|
|
||||||
# Check if bcopy can be used for overlapping copies, if memmove isn't found.
|
# Check if bcopy can be used for overlapping copies, if memmove isn't found.
|
||||||
# The check is borrowed from the PERL Configure script.
|
# The check is borrowed from the PERL Configure script.
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
2001-06-07 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* glib/glib-sections.txt, glib/tmpl/date.sgml: Add g_time_val_add.
|
||||||
|
|
||||||
|
* glib/tmpl/threads.sgml: Updated.
|
||||||
|
|
||||||
2001-05-23 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
2001-05-23 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
* glib/tmpl/arrays.sgml, glib/tmpl/arrays_pointers.sgml,
|
* glib/tmpl/arrays.sgml, glib/tmpl/arrays_pointers.sgml,
|
||||||
|
@ -857,6 +857,7 @@ G_USEC_PER_SEC
|
|||||||
GTimeVal
|
GTimeVal
|
||||||
g_get_current_time
|
g_get_current_time
|
||||||
g_usleep
|
g_usleep
|
||||||
|
g_time_val_add
|
||||||
|
|
||||||
<SUBSECTION>
|
<SUBSECTION>
|
||||||
GDate
|
GDate
|
||||||
|
@ -101,6 +101,15 @@ rely on the exact length of the sleep.
|
|||||||
@microseconds: number of microseconds to pause
|
@microseconds: number of microseconds to pause
|
||||||
|
|
||||||
|
|
||||||
|
<!-- ##### FUNCTION g_time_val_add ##### -->
|
||||||
|
<para>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
|
||||||
|
@time:
|
||||||
|
@microseconds:
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### STRUCT GDate ##### -->
|
<!-- ##### STRUCT GDate ##### -->
|
||||||
<para>
|
<para>
|
||||||
Represents a day between January 1, Year 1 and a few thousand years in
|
Represents a day between January 1, Year 1 and a few thousand years in
|
||||||
|
@ -1366,6 +1366,11 @@ This function can also be used, if g_thread_init() has not yet been
|
|||||||
called and will immediately return TRUE then.
|
called and will immediately return TRUE then.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
To easily calculate @abs_time a combination of g_get_current_time()
|
||||||
|
and g_time_val_add() can be used.
|
||||||
|
</para>
|
||||||
|
|
||||||
@cond: a #GCond
|
@cond: a #GCond
|
||||||
@mutex: a #GMutex, that is currently locked
|
@mutex: a #GMutex, that is currently locked
|
||||||
@abs_time: a #GTimeVal, determining the final time
|
@abs_time: a #GTimeVal, determining the final time
|
||||||
|
@ -343,6 +343,9 @@ g_async_queue_try_pop_unlocked (GAsyncQueue* queue)
|
|||||||
* Pop data from the @queue. If no data is received before @end_time,
|
* Pop data from the @queue. If no data is received before @end_time,
|
||||||
* #NULL is returned.
|
* #NULL is returned.
|
||||||
*
|
*
|
||||||
|
* To easily calculate @end_time a combination of g_get_current_time()
|
||||||
|
* and g_time_val_add() can be used.
|
||||||
|
*
|
||||||
* Return value: data from the queue or #NULL, when no data is
|
* Return value: data from the queue or #NULL, when no data is
|
||||||
* received before @end_time.
|
* received before @end_time.
|
||||||
**/
|
**/
|
||||||
@ -370,6 +373,9 @@ g_async_queue_timed_pop (GAsyncQueue* queue, GTimeVal *end_time)
|
|||||||
* #NULL is returned. This function must be called while holding the
|
* #NULL is returned. This function must be called while holding the
|
||||||
* @queue's lock.
|
* @queue's lock.
|
||||||
*
|
*
|
||||||
|
* To easily calculate @end_time a combination of g_get_current_time()
|
||||||
|
* and g_time_val_add() can be used.
|
||||||
|
*
|
||||||
* Return value: data from the queue or #NULL, when no data is
|
* Return value: data from the queue or #NULL, when no data is
|
||||||
* received before @end_time.
|
* received before @end_time.
|
||||||
**/
|
**/
|
||||||
|
@ -343,6 +343,9 @@ g_async_queue_try_pop_unlocked (GAsyncQueue* queue)
|
|||||||
* Pop data from the @queue. If no data is received before @end_time,
|
* Pop data from the @queue. If no data is received before @end_time,
|
||||||
* #NULL is returned.
|
* #NULL is returned.
|
||||||
*
|
*
|
||||||
|
* To easily calculate @end_time a combination of g_get_current_time()
|
||||||
|
* and g_time_val_add() can be used.
|
||||||
|
*
|
||||||
* Return value: data from the queue or #NULL, when no data is
|
* Return value: data from the queue or #NULL, when no data is
|
||||||
* received before @end_time.
|
* received before @end_time.
|
||||||
**/
|
**/
|
||||||
@ -370,6 +373,9 @@ g_async_queue_timed_pop (GAsyncQueue* queue, GTimeVal *end_time)
|
|||||||
* #NULL is returned. This function must be called while holding the
|
* #NULL is returned. This function must be called while holding the
|
||||||
* @queue's lock.
|
* @queue's lock.
|
||||||
*
|
*
|
||||||
|
* To easily calculate @end_time a combination of g_get_current_time()
|
||||||
|
* and g_time_val_add() can be used.
|
||||||
|
*
|
||||||
* Return value: data from the queue or #NULL, when no data is
|
* Return value: data from the queue or #NULL, when no data is
|
||||||
* received before @end_time.
|
* received before @end_time.
|
||||||
**/
|
**/
|
||||||
|
@ -86,20 +86,12 @@ g_thread_pool_thread_proxy (gpointer data)
|
|||||||
* pool afterwards */
|
* pool afterwards */
|
||||||
GTimeVal end_time;
|
GTimeVal end_time;
|
||||||
g_get_current_time (&end_time);
|
g_get_current_time (&end_time);
|
||||||
end_time.tv_usec += G_USEC_PER_SEC / 2; /* Halv a second */
|
g_time_val_add (&end_time, G_USEC_PER_SEC / 2); /* 1/2 second */
|
||||||
if (end_time.tv_usec >= G_USEC_PER_SEC)
|
|
||||||
{
|
|
||||||
end_time.tv_usec -= G_USEC_PER_SEC;
|
|
||||||
end_time.tv_sec += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
task = g_async_queue_timed_pop_unlocked (pool->queue, &end_time);
|
task = g_async_queue_timed_pop_unlocked (pool->queue, &end_time);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
task = g_async_queue_pop_unlocked (pool->queue);
|
||||||
task = g_async_queue_pop_unlocked (pool->queue);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (task)
|
if (task)
|
||||||
{
|
{
|
||||||
watcher = FALSE;
|
watcher = FALSE;
|
||||||
|
@ -38,6 +38,8 @@
|
|||||||
#endif /* HAVE_UNISTD_H */
|
#endif /* HAVE_UNISTD_H */
|
||||||
#ifndef G_OS_WIN32
|
#ifndef G_OS_WIN32
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <errno.h>
|
||||||
#endif /* G_OS_WIN32 */
|
#endif /* G_OS_WIN32 */
|
||||||
|
|
||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
@ -193,7 +195,14 @@ g_usleep (gulong microseconds)
|
|||||||
{
|
{
|
||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
Sleep (microseconds / 1000);
|
Sleep (microseconds / 1000);
|
||||||
#else
|
#else /* !G_OS_WIN32 */
|
||||||
|
# ifdef HAVE_NANOSLEEP
|
||||||
|
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) == EINTR)
|
||||||
|
request = remaining;
|
||||||
|
# else /* !HAVE_NANOSLEEP */
|
||||||
if (g_thread_supported ())
|
if (g_thread_supported ())
|
||||||
{
|
{
|
||||||
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
|
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
|
||||||
@ -201,16 +210,13 @@ g_usleep (gulong microseconds)
|
|||||||
GTimeVal end_time;
|
GTimeVal end_time;
|
||||||
|
|
||||||
g_get_current_time (&end_time);
|
g_get_current_time (&end_time);
|
||||||
|
if (microseconds > G_MAXLONG)
|
||||||
end_time.tv_sec += microseconds / G_USEC_PER_SEC;
|
|
||||||
end_time.tv_usec += microseconds % G_USEC_PER_SEC;
|
|
||||||
|
|
||||||
if (end_time.tv_usec >= G_USEC_PER_SEC)
|
|
||||||
{
|
{
|
||||||
end_time.tv_usec -= G_USEC_PER_SEC;
|
microseconds -= G_MAXLONG;
|
||||||
end_time.tv_sec += 1;
|
g_time_val_add (&end_time, G_MAXLONG);
|
||||||
}
|
}
|
||||||
|
g_time_val_add (&end_time, microseconds);
|
||||||
|
|
||||||
g_static_mutex_lock (&mutex);
|
g_static_mutex_lock (&mutex);
|
||||||
|
|
||||||
if (!cond)
|
if (!cond)
|
||||||
@ -229,6 +235,42 @@ g_usleep (gulong microseconds)
|
|||||||
tv.tv_usec = microseconds % G_USEC_PER_SEC;
|
tv.tv_usec = microseconds % G_USEC_PER_SEC;
|
||||||
select(0, NULL, NULL, NULL, &tv);
|
select(0, NULL, NULL, NULL, &tv);
|
||||||
}
|
}
|
||||||
#endif
|
# endif /* !HAVE_NANOSLEEP */
|
||||||
|
#endif /* !G_OS_WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_time_val_add:
|
||||||
|
* @time: a #GTimeVal
|
||||||
|
* @microseconds: number of microseconds to add to @time
|
||||||
|
*
|
||||||
|
* Adds the given number of microseconds to @time. @microseconds can
|
||||||
|
* also be negative to decrease the value of @time.
|
||||||
|
**/
|
||||||
|
void
|
||||||
|
g_time_val_add (GTimeVal *time, glong microseconds)
|
||||||
|
{
|
||||||
|
g_return_if_fail (time->tv_usec >= 0 && time->tv_usec < G_USEC_PER_SEC);
|
||||||
|
|
||||||
|
if (microseconds >= 0)
|
||||||
|
{
|
||||||
|
time->tv_usec += microseconds % G_USEC_PER_SEC;
|
||||||
|
time->tv_sec += microseconds / G_USEC_PER_SEC;
|
||||||
|
if (time->tv_usec >= G_USEC_PER_SEC)
|
||||||
|
{
|
||||||
|
time->tv_usec -= G_USEC_PER_SEC;
|
||||||
|
time->tv_sec++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
microseconds *= -1;
|
||||||
|
time->tv_usec -= microseconds % G_USEC_PER_SEC;
|
||||||
|
time->tv_sec -= microseconds / G_USEC_PER_SEC;
|
||||||
|
if (time->tv_usec < 0)
|
||||||
|
{
|
||||||
|
time->tv_usec += G_USEC_PER_SEC;
|
||||||
|
time->tv_sec--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -40,13 +40,17 @@ typedef struct _GTimer GTimer;
|
|||||||
#define G_USEC_PER_SEC 1000000
|
#define G_USEC_PER_SEC 1000000
|
||||||
|
|
||||||
GTimer* g_timer_new (void);
|
GTimer* g_timer_new (void);
|
||||||
void g_timer_destroy (GTimer *timer);
|
void g_timer_destroy (GTimer *timer);
|
||||||
void g_timer_start (GTimer *timer);
|
void g_timer_start (GTimer *timer);
|
||||||
void g_timer_stop (GTimer *timer);
|
void g_timer_stop (GTimer *timer);
|
||||||
void g_timer_reset (GTimer *timer);
|
void g_timer_reset (GTimer *timer);
|
||||||
gdouble g_timer_elapsed (GTimer *timer,
|
gdouble g_timer_elapsed (GTimer *timer,
|
||||||
gulong *microseconds);
|
gulong *microseconds);
|
||||||
void g_usleep (gulong microseconds);
|
|
||||||
|
void g_usleep (gulong microseconds);
|
||||||
|
|
||||||
|
void g_time_val_add (GTimeVal *time,
|
||||||
|
glong microseconds);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
@ -86,20 +86,12 @@ g_thread_pool_thread_proxy (gpointer data)
|
|||||||
* pool afterwards */
|
* pool afterwards */
|
||||||
GTimeVal end_time;
|
GTimeVal end_time;
|
||||||
g_get_current_time (&end_time);
|
g_get_current_time (&end_time);
|
||||||
end_time.tv_usec += G_USEC_PER_SEC / 2; /* Halv a second */
|
g_time_val_add (&end_time, G_USEC_PER_SEC / 2); /* 1/2 second */
|
||||||
if (end_time.tv_usec >= G_USEC_PER_SEC)
|
|
||||||
{
|
|
||||||
end_time.tv_usec -= G_USEC_PER_SEC;
|
|
||||||
end_time.tv_sec += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
task = g_async_queue_timed_pop_unlocked (pool->queue, &end_time);
|
task = g_async_queue_timed_pop_unlocked (pool->queue, &end_time);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
task = g_async_queue_pop_unlocked (pool->queue);
|
||||||
task = g_async_queue_pop_unlocked (pool->queue);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (task)
|
if (task)
|
||||||
{
|
{
|
||||||
watcher = FALSE;
|
watcher = FALSE;
|
||||||
|
62
gtimer.c
62
gtimer.c
@ -38,6 +38,8 @@
|
|||||||
#endif /* HAVE_UNISTD_H */
|
#endif /* HAVE_UNISTD_H */
|
||||||
#ifndef G_OS_WIN32
|
#ifndef G_OS_WIN32
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <errno.h>
|
||||||
#endif /* G_OS_WIN32 */
|
#endif /* G_OS_WIN32 */
|
||||||
|
|
||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
@ -193,7 +195,14 @@ g_usleep (gulong microseconds)
|
|||||||
{
|
{
|
||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
Sleep (microseconds / 1000);
|
Sleep (microseconds / 1000);
|
||||||
#else
|
#else /* !G_OS_WIN32 */
|
||||||
|
# ifdef HAVE_NANOSLEEP
|
||||||
|
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) == EINTR)
|
||||||
|
request = remaining;
|
||||||
|
# else /* !HAVE_NANOSLEEP */
|
||||||
if (g_thread_supported ())
|
if (g_thread_supported ())
|
||||||
{
|
{
|
||||||
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
|
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
|
||||||
@ -201,16 +210,13 @@ g_usleep (gulong microseconds)
|
|||||||
GTimeVal end_time;
|
GTimeVal end_time;
|
||||||
|
|
||||||
g_get_current_time (&end_time);
|
g_get_current_time (&end_time);
|
||||||
|
if (microseconds > G_MAXLONG)
|
||||||
end_time.tv_sec += microseconds / G_USEC_PER_SEC;
|
|
||||||
end_time.tv_usec += microseconds % G_USEC_PER_SEC;
|
|
||||||
|
|
||||||
if (end_time.tv_usec >= G_USEC_PER_SEC)
|
|
||||||
{
|
{
|
||||||
end_time.tv_usec -= G_USEC_PER_SEC;
|
microseconds -= G_MAXLONG;
|
||||||
end_time.tv_sec += 1;
|
g_time_val_add (&end_time, G_MAXLONG);
|
||||||
}
|
}
|
||||||
|
g_time_val_add (&end_time, microseconds);
|
||||||
|
|
||||||
g_static_mutex_lock (&mutex);
|
g_static_mutex_lock (&mutex);
|
||||||
|
|
||||||
if (!cond)
|
if (!cond)
|
||||||
@ -229,6 +235,42 @@ g_usleep (gulong microseconds)
|
|||||||
tv.tv_usec = microseconds % G_USEC_PER_SEC;
|
tv.tv_usec = microseconds % G_USEC_PER_SEC;
|
||||||
select(0, NULL, NULL, NULL, &tv);
|
select(0, NULL, NULL, NULL, &tv);
|
||||||
}
|
}
|
||||||
#endif
|
# endif /* !HAVE_NANOSLEEP */
|
||||||
|
#endif /* !G_OS_WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_time_val_add:
|
||||||
|
* @time: a #GTimeVal
|
||||||
|
* @microseconds: number of microseconds to add to @time
|
||||||
|
*
|
||||||
|
* Adds the given number of microseconds to @time. @microseconds can
|
||||||
|
* also be negative to decrease the value of @time.
|
||||||
|
**/
|
||||||
|
void
|
||||||
|
g_time_val_add (GTimeVal *time, glong microseconds)
|
||||||
|
{
|
||||||
|
g_return_if_fail (time->tv_usec >= 0 && time->tv_usec < G_USEC_PER_SEC);
|
||||||
|
|
||||||
|
if (microseconds >= 0)
|
||||||
|
{
|
||||||
|
time->tv_usec += microseconds % G_USEC_PER_SEC;
|
||||||
|
time->tv_sec += microseconds / G_USEC_PER_SEC;
|
||||||
|
if (time->tv_usec >= G_USEC_PER_SEC)
|
||||||
|
{
|
||||||
|
time->tv_usec -= G_USEC_PER_SEC;
|
||||||
|
time->tv_sec++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
microseconds *= -1;
|
||||||
|
time->tv_usec -= microseconds % G_USEC_PER_SEC;
|
||||||
|
time->tv_sec -= microseconds / G_USEC_PER_SEC;
|
||||||
|
if (time->tv_usec < 0)
|
||||||
|
{
|
||||||
|
time->tv_usec += G_USEC_PER_SEC;
|
||||||
|
time->tv_sec--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
18
gtimer.h
18
gtimer.h
@ -40,13 +40,17 @@ typedef struct _GTimer GTimer;
|
|||||||
#define G_USEC_PER_SEC 1000000
|
#define G_USEC_PER_SEC 1000000
|
||||||
|
|
||||||
GTimer* g_timer_new (void);
|
GTimer* g_timer_new (void);
|
||||||
void g_timer_destroy (GTimer *timer);
|
void g_timer_destroy (GTimer *timer);
|
||||||
void g_timer_start (GTimer *timer);
|
void g_timer_start (GTimer *timer);
|
||||||
void g_timer_stop (GTimer *timer);
|
void g_timer_stop (GTimer *timer);
|
||||||
void g_timer_reset (GTimer *timer);
|
void g_timer_reset (GTimer *timer);
|
||||||
gdouble g_timer_elapsed (GTimer *timer,
|
gdouble g_timer_elapsed (GTimer *timer,
|
||||||
gulong *microseconds);
|
gulong *microseconds);
|
||||||
void g_usleep (gulong microseconds);
|
|
||||||
|
void g_usleep (gulong microseconds);
|
||||||
|
|
||||||
|
void g_time_val_add (GTimeVal *time,
|
||||||
|
glong microseconds);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user