* clutter/clutter-frame-source.h:
* clutter/clutter-frame-source.c:
New files that contain a replacement for g_timeout that try to
cope with system delays.
* clutter/Makefile.am: Added clutter-frame-source.{c,h}
* clutter/clutter-timeline.c (timeout_add): Use a frame source
instead of a g_timeout.
* clutter/clutter-main.c (clutter_threads_add_frame_source_full)
(clutter_threads_add_frame_source): New public functions to wrap a
frame source and grab the Clutter mutex.
* clutter/clutter-timeout-pool.c: Now calculates the timeout
expiration times in the same way as a frame source does so that it
counts time in frame intervals instead of setting the next
expiration time as an offset from the current time.
The clutter_timeout_pool_insert_sorted() function caused an inversion of
the timeout sources in the pool; this led to a wrong behaviour in the
execution of the timeout functions. See bug 471.
This patch drops clutter_timeout_pool_insert_sorted() in favour of the
standard g_list_insert_sorted(), which produces identical behaviours with
and without the pool.
A new test, written by Rob Bradford, has been added to the regression test
suite in order to identify sorting issues with the timeout pools.
* clutter/clutter-timeout-pool.c: Fix removing and adding timeouts
to the timeout pool during a dispatch of a timeout source already
inside the pool. (#456, based on a patch by Neil Roberts)
(clutter_timeout_dispatch), (clutter_timeout_pool_dispatch): Hold
the main Clutter lock in the pool dispatch function, instead of
the per-timeout dispatch; this guarantees that the ref+unref of
the single timeouts are done under the main lock.
All the ClutterTimeline share a ClutterTimeoutPool by default. This might
cause problems if an application is using a heavily threaded library that
does not play nicely with the main loop (like libneon). If this is the
case, using the CLUTTER_TIMELINE environment variable set to "no-pool"
makes the ClutterTimeline objects discard the pool and allocate a slice
of the main loop.
The mutex protection for the timeout pool was causing deadlocks, so it has been
removed for the time being, until I figure out a way to make it work properly.
A timeout pool should not be considered thread-safe (or thread-aware) until further
notice.
* clutter/clutter-timeout-pool.c: Make ClutterTimeoutPool
more thread-safe, using a static lock.
(clutter_timeout_pool_dispatch), (clutter_timeout_pool_remove): Fix
a race condition-turned-in-memory corruption bug, triggered by
removing a timeout from the pool while still spinning the pool
source.
A ClutterTimeoutPool is a source for the GLib main loop which pools
multiple timeout functions. The pool is always sorted so that the first
timeout to expire is also the first element of the pool; hence, extraction
is a constant time operation. This also makes the usage of multiple
timeouts at the same priority not compete for a timeslice of the main
loop, leading to starvation.