improve the cond wait wrapper

by removing it, we don't want to restart the timer on every loop
This commit is contained in:
John Cupitt 2013-01-15 17:23:58 +00:00
parent 384842cd0a
commit caa51245c7
4 changed files with 17 additions and 36 deletions

13
TODO
View File

@ -1,16 +1,3 @@
- fix
sequential.c: In function 'vips_sequential_generate':
sequential.c:163:4: warning: 'g_cond_timed_wait' is deprecated
(declared at /usr/include/glib-2.0/glib/deprecated/gthread.h:279)
[-Wdeprecated-declarations]
add a wait until wrapper using
http://developer.gnome.org/glib/2.31/glib-Threads.html#g-cond-timed-until
as a guide
- update the INCLUDES etc. stuff, see OS X build
- quadratic doesn't work for order 3

View File

@ -149,20 +149,34 @@ vips_sequential_generate( VipsRegion *or,
* deadlock, and we don't fail on timeout, since the timeout
* may be harmless.
*/
#ifdef HAVE_COND_INIT
gint64 time;
time = g_get_monotonic_time () +
STALL_TIME * G_TIME_SPAN_SECOND;
#else
GTimeVal time;
g_get_current_time( &time );
g_time_val_add( &time, STALL_TIME * 1000000 );
#endif
VIPS_DEBUG_MSG( "thread %p stalling for up to %gs ...\n",
g_thread_self(), STALL_TIME );
g_get_current_time( &time );
g_time_val_add( &time, STALL_TIME * 1000000 );
/* Exit the loop on timeout or condition passes. We have to
* be wary of spurious wakeups.
*/
while( r->top > sequential->y_pos )
#ifdef HAVE_COND_INIT
if( !g_cond_wait_until( sequential->ready,
sequential->lock, time ) )
break;
#else
if( !g_cond_timed_wait( sequential->ready,
sequential->lock, &time ) )
break;
#endif
VIPS_DEBUG_MSG( "thread %p awake again ...\n",
g_thread_self() );

View File

@ -41,11 +41,10 @@ extern "C" {
GMutex *vips_g_mutex_new( void );
void vips_g_mutex_free( GMutex * );
/* Same for GCond. And we need a wrapper for waiting too.
/* Same for GCond.
*/
GCond *vips_g_cond_new( void );
void vips_g_cond_free( GCond * );
void vips_g_cond_timed_wait( GCond *, GMutex *, gint64 );
/* ... and for GThread.
*/

View File

@ -156,25 +156,6 @@ vips_g_cond_free( GCond *cond )
#endif
}
/* Wait until cond is signalled, or timeout us have passed.
*
* You can get spurious wakeups, use this in a loop.
*/
void
vips_g_cond_timed_wait( GCond *cond, GMutex *mutex, gint64 timeout )
{
#ifdef HAVE_COND_INIT
g_cond_wait_until( cond, mutex,
g_get_monotonic_time() + timeout );
#else
GTimeVal time;
g_get_current_time( &time );
g_time_val_add( &time, timeout );
g_cond_timed_wait( cond, mutex, &time );
#endif
}
GThread *
vips_g_thread_new( const char *domain, GThreadFunc func, gpointer data )
{