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:
Sebastian Wilhelmi 2001-06-07 13:46:14 +00:00 committed by Sebastian Wilhelmi
parent 9600d5cd53
commit 632943f359
21 changed files with 262 additions and 57 deletions

View File

@ -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>
* gdate.c (g_date_update_julian): Changed to take a const

View File

@ -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>
* gdate.c (g_date_update_julian): Changed to take a const

View File

@ -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>
* gdate.c (g_date_update_julian): Changed to take a const

View File

@ -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>
* gdate.c (g_date_update_julian): Changed to take a const

View File

@ -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>
* gdate.c (g_date_update_julian): Changed to take a const

View File

@ -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>
* gdate.c (g_date_update_julian): Changed to take a const

View File

@ -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>
* gdate.c (g_date_update_julian): Changed to take a const

View File

@ -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>
* gdate.c (g_date_update_julian): Changed to take a const

View File

@ -460,7 +460,7 @@ GLIB_SIZEOF([$size_includes], ptrdiff_t, ptrdiff_t)
GLIB_SIZEOF([$size_includes], intmax_t, intmax_t)
# 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.
# The check is borrowed from the PERL Configure script.

View File

@ -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>
* glib/tmpl/arrays.sgml, glib/tmpl/arrays_pointers.sgml,

View File

@ -857,6 +857,7 @@ G_USEC_PER_SEC
GTimeVal
g_get_current_time
g_usleep
g_time_val_add
<SUBSECTION>
GDate

View File

@ -101,6 +101,15 @@ rely on the exact length of the sleep.
@microseconds: number of microseconds to pause
<!-- ##### FUNCTION g_time_val_add ##### -->
<para>
</para>
@time:
@microseconds:
<!-- ##### STRUCT GDate ##### -->
<para>
Represents a day between January 1, Year 1 and a few thousand years in

View File

@ -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.
</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
@mutex: a #GMutex, that is currently locked
@abs_time: a #GTimeVal, determining the final time

View File

@ -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,
* #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
* 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
* @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
* received before @end_time.
**/

View File

@ -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,
* #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
* 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
* @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
* received before @end_time.
**/

View File

@ -86,20 +86,12 @@ g_thread_pool_thread_proxy (gpointer data)
* pool afterwards */
GTimeVal end_time;
g_get_current_time (&end_time);
end_time.tv_usec += G_USEC_PER_SEC / 2; /* Halv a second */
if (end_time.tv_usec >= G_USEC_PER_SEC)
{
end_time.tv_usec -= G_USEC_PER_SEC;
end_time.tv_sec += 1;
}
g_time_val_add (&end_time, G_USEC_PER_SEC / 2); /* 1/2 second */
task = g_async_queue_timed_pop_unlocked (pool->queue, &end_time);
}
else
{
task = g_async_queue_pop_unlocked (pool->queue);
}
task = g_async_queue_pop_unlocked (pool->queue);
if (task)
{
watcher = FALSE;

View File

@ -38,6 +38,8 @@
#endif /* HAVE_UNISTD_H */
#ifndef G_OS_WIN32
#include <sys/time.h>
#include <time.h>
#include <errno.h>
#endif /* G_OS_WIN32 */
#ifdef G_OS_WIN32
@ -193,7 +195,14 @@ g_usleep (gulong microseconds)
{
#ifdef G_OS_WIN32
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 ())
{
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
@ -201,16 +210,13 @@ g_usleep (gulong microseconds)
GTimeVal end_time;
g_get_current_time (&end_time);
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)
if (microseconds > G_MAXLONG)
{
end_time.tv_usec -= G_USEC_PER_SEC;
end_time.tv_sec += 1;
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)
@ -229,6 +235,42 @@ g_usleep (gulong microseconds)
tv.tv_usec = microseconds % G_USEC_PER_SEC;
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--;
}
}
}

View File

@ -40,13 +40,17 @@ typedef struct _GTimer GTimer;
#define G_USEC_PER_SEC 1000000
GTimer* g_timer_new (void);
void g_timer_destroy (GTimer *timer);
void g_timer_start (GTimer *timer);
void g_timer_stop (GTimer *timer);
void g_timer_reset (GTimer *timer);
gdouble g_timer_elapsed (GTimer *timer,
gulong *microseconds);
void g_usleep (gulong microseconds);
void g_timer_destroy (GTimer *timer);
void g_timer_start (GTimer *timer);
void g_timer_stop (GTimer *timer);
void g_timer_reset (GTimer *timer);
gdouble g_timer_elapsed (GTimer *timer,
gulong *microseconds);
void g_usleep (gulong microseconds);
void g_time_val_add (GTimeVal *time,
glong microseconds);
G_END_DECLS

View File

@ -86,20 +86,12 @@ g_thread_pool_thread_proxy (gpointer data)
* pool afterwards */
GTimeVal end_time;
g_get_current_time (&end_time);
end_time.tv_usec += G_USEC_PER_SEC / 2; /* Halv a second */
if (end_time.tv_usec >= G_USEC_PER_SEC)
{
end_time.tv_usec -= G_USEC_PER_SEC;
end_time.tv_sec += 1;
}
g_time_val_add (&end_time, G_USEC_PER_SEC / 2); /* 1/2 second */
task = g_async_queue_timed_pop_unlocked (pool->queue, &end_time);
}
else
{
task = g_async_queue_pop_unlocked (pool->queue);
}
task = g_async_queue_pop_unlocked (pool->queue);
if (task)
{
watcher = FALSE;

View File

@ -38,6 +38,8 @@
#endif /* HAVE_UNISTD_H */
#ifndef G_OS_WIN32
#include <sys/time.h>
#include <time.h>
#include <errno.h>
#endif /* G_OS_WIN32 */
#ifdef G_OS_WIN32
@ -193,7 +195,14 @@ g_usleep (gulong microseconds)
{
#ifdef G_OS_WIN32
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 ())
{
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
@ -201,16 +210,13 @@ g_usleep (gulong microseconds)
GTimeVal end_time;
g_get_current_time (&end_time);
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)
if (microseconds > G_MAXLONG)
{
end_time.tv_usec -= G_USEC_PER_SEC;
end_time.tv_sec += 1;
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)
@ -229,6 +235,42 @@ g_usleep (gulong microseconds)
tv.tv_usec = microseconds % G_USEC_PER_SEC;
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--;
}
}
}

View File

@ -40,13 +40,17 @@ typedef struct _GTimer GTimer;
#define G_USEC_PER_SEC 1000000
GTimer* g_timer_new (void);
void g_timer_destroy (GTimer *timer);
void g_timer_start (GTimer *timer);
void g_timer_stop (GTimer *timer);
void g_timer_reset (GTimer *timer);
gdouble g_timer_elapsed (GTimer *timer,
gulong *microseconds);
void g_usleep (gulong microseconds);
void g_timer_destroy (GTimer *timer);
void g_timer_start (GTimer *timer);
void g_timer_stop (GTimer *timer);
void g_timer_reset (GTimer *timer);
gdouble g_timer_elapsed (GTimer *timer,
gulong *microseconds);
void g_usleep (gulong microseconds);
void g_time_val_add (GTimeVal *time,
glong microseconds);
G_END_DECLS