+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
+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
+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
+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
+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
+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
+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
+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
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.
+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,
GTimeVal
g_get_current_time
g_usleep
+g_time_val_add
<SUBSECTION>
GDate
@microseconds: number of microseconds to pause
+<!-- ##### FUNCTION g_time_val_add ##### -->
+<para>
+
+</para>
+
+@time:
+@microseconds:
+
+
<!-- ##### STRUCT GDate ##### -->
<para>\r
Represents a day between January 1, Year 1 and a few thousand years in\r
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
* 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.
**/
* #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.
**/
* 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.
**/
* #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.
**/
* 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;
#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
{
#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;
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)
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--;
+ }
+ }
+}
#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
* 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;
#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
{
#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;
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)
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--;
+ }
+ }
+}
#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