improve the cond wait wrapper
by removing it, we don't want to restart the timer on every loop
This commit is contained in:
parent
384842cd0a
commit
caa51245c7
13
TODO
13
TODO
@ -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
|
- update the INCLUDES etc. stuff, see OS X build
|
||||||
|
|
||||||
- quadratic doesn't work for order 3
|
- quadratic doesn't work for order 3
|
||||||
|
@ -149,20 +149,34 @@ vips_sequential_generate( VipsRegion *or,
|
|||||||
* deadlock, and we don't fail on timeout, since the timeout
|
* deadlock, and we don't fail on timeout, since the timeout
|
||||||
* may be harmless.
|
* may be harmless.
|
||||||
*/
|
*/
|
||||||
|
#ifdef HAVE_COND_INIT
|
||||||
|
gint64 time;
|
||||||
|
|
||||||
|
time = g_get_monotonic_time () +
|
||||||
|
STALL_TIME * G_TIME_SPAN_SECOND;
|
||||||
|
#else
|
||||||
GTimeVal time;
|
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",
|
VIPS_DEBUG_MSG( "thread %p stalling for up to %gs ...\n",
|
||||||
g_thread_self(), STALL_TIME );
|
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
|
/* Exit the loop on timeout or condition passes. We have to
|
||||||
* be wary of spurious wakeups.
|
* be wary of spurious wakeups.
|
||||||
*/
|
*/
|
||||||
while( r->top > sequential->y_pos )
|
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,
|
if( !g_cond_timed_wait( sequential->ready,
|
||||||
sequential->lock, &time ) )
|
sequential->lock, &time ) )
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
VIPS_DEBUG_MSG( "thread %p awake again ...\n",
|
VIPS_DEBUG_MSG( "thread %p awake again ...\n",
|
||||||
g_thread_self() );
|
g_thread_self() );
|
||||||
|
@ -41,11 +41,10 @@ extern "C" {
|
|||||||
GMutex *vips_g_mutex_new( void );
|
GMutex *vips_g_mutex_new( void );
|
||||||
void vips_g_mutex_free( GMutex * );
|
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 );
|
GCond *vips_g_cond_new( void );
|
||||||
void vips_g_cond_free( GCond * );
|
void vips_g_cond_free( GCond * );
|
||||||
void vips_g_cond_timed_wait( GCond *, GMutex *, gint64 );
|
|
||||||
|
|
||||||
/* ... and for GThread.
|
/* ... and for GThread.
|
||||||
*/
|
*/
|
||||||
|
@ -156,25 +156,6 @@ vips_g_cond_free( GCond *cond )
|
|||||||
#endif
|
#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 *
|
GThread *
|
||||||
vips_g_thread_new( const char *domain, GThreadFunc func, gpointer data )
|
vips_g_thread_new( const char *domain, GThreadFunc func, gpointer data )
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user