Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv710
Modified Files: Tag: devel_0_39 m_sched.c Log Message: reverting to oldschool list for clock callbacks ... we need a heap to gain more efficiency
Index: m_sched.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/m_sched.c,v retrieving revision 1.5.4.35.2.6 retrieving revision 1.5.4.35.2.7 diff -C2 -d -r1.5.4.35.2.6 -r1.5.4.35.2.7 *** m_sched.c 28 Oct 2005 12:18:23 -0000 1.5.4.35.2.6 --- m_sched.c 6 Nov 2005 21:11:17 -0000 1.5.4.35.2.7 *************** *** 50,68 **** typedef void (*t_clockmethod)(void *client);
struct _clock { ! double c_settime; /* -1 if unset */ void *c_owner; t_clockmethod c_fn; ! struct _clock *c_next_time; /* clocks with settimes > c_settime */ ! struct _clock *c_next; /* clocks with settimes == c_settime */ };
t_clock *clock_setlist; - - #ifdef UNISTD - #include <unistd.h> - #endif - t_clock *clock_new(void *owner, t_method fn) { --- 50,66 ---- typedef void (*t_clockmethod)(void *client);
+ #ifdef UNISTD + #include <unistd.h> + #endif + struct _clock { ! double c_settime; void *c_owner; t_clockmethod c_fn; ! struct _clock *c_next; };
t_clock *clock_setlist; t_clock *clock_new(void *owner, t_method fn) { *************** *** 71,182 **** x->c_owner = owner; x->c_fn = (t_clockmethod)fn; - x->c_next_time = 0; x->c_next = 0; return (x); }
void clock_unset(t_clock *x) { ! if (x->c_settime == -1) ! return; ! ! assert (clock_setlist); ! if (x == clock_setlist) ! { ! if (x->c_next == 0) ! clock_setlist = x->c_next_time; ! else ! { ! x->c_next->c_next_time = x->c_next_time; ! clock_setlist = x->c_next; ! } ! } ! else ! { ! t_clock *x2 = clock_setlist; ! t_clock *x_before = 0; ! ! /* find correct settime list */ ! while (x2->c_settime != x->c_settime) ! { ! assert (x2->c_next_time != 0); ! ! x_before = x2; ! x2 = x2->c_next_time; ! } ! ! if (x2 == x) /* we're the first in the settime list */ ! { ! if (x->c_next == NULL) /* we're the only one in the list */ ! x_before->c_next_time = x->c_next_time; ! else ! { ! x_before->c_next_time = x->c_next; ! x->c_next->c_next_time = x->c_next_time; ! } ! } ! else ! { ! while (x2->c_next != x) ! { ! x2 = x2->c_next; ! assert(x2->c_next); ! } ! x2->c_next = x->c_next; ! } ! } ! x->c_settime = -1; }
! /* set the clock to call back at an absolute system time */ void clock_set(t_clock *x, double setticks) { if (setticks < sys_time) setticks = sys_time; clock_unset(x); ! x->c_settime = setticks; ! if (clock_setlist && clock_setlist->c_settime <= setticks) { ! if (clock_setlist->c_settime == setticks) ! { ! /* our slot is the first in the list */ ! x->c_next_time = 0; ! x->c_next = clock_setlist->c_next; ! clock_setlist->c_next = x; ! } ! else ! { ! t_clock *cbefore = clock_setlist; ! t_clock *cafter = clock_setlist->c_next_time; ! ! while (cafter && cafter->c_settime < setticks) ! { ! cbefore = cafter; ! cafter = cafter->c_next_time; ! } ! ! if (cafter && cafter->c_settime == setticks) ! { ! /* we found our slot */ ! x->c_next_time = 0; ! x->c_next = cafter->c_next; ! cafter->c_next = x; ! } ! else ! { ! /* we have to create our slot */ ! x->c_next_time = cafter; ! x->c_next = 0; ! cbefore->c_next_time = x; ! } ! } } ! else ! { ! /* we have to create a new slot and prepend it */ ! x->c_next = 0; ! x->c_next_time = clock_setlist; ! clock_setlist = x; ! } }
--- 69,113 ---- x->c_owner = owner; x->c_fn = (t_clockmethod)fn; x->c_next = 0; return (x); }
+ void clock_unset(t_clock *x) { ! if (x->c_settime >= 0) ! { ! if (x == clock_setlist) clock_setlist = x->c_next; ! else ! { ! t_clock *x2 = clock_setlist; ! while (x2->c_next != x) x2 = x2->c_next; ! x2->c_next = x->c_next; ! } ! x->c_settime = -1; ! } }
! /* set the clock to call back at an absolute system time */ void clock_set(t_clock *x, double setticks) { if (setticks < sys_time) setticks = sys_time; clock_unset(x); ! x->c_settime = setticks; if (clock_setlist && clock_setlist->c_settime <= setticks) { ! t_clock *cbefore, *cafter; ! for (cbefore = clock_setlist, cafter = clock_setlist->c_next; ! cbefore; cbefore = cafter, cafter = cbefore->c_next) ! { ! if (!cafter || cafter->c_settime > setticks) ! { ! cbefore->c_next = x; ! x->c_next = cafter; ! return; ! } ! } } ! else x->c_next = clock_setlist, clock_setlist = x; }
*************** *** 187,190 **** --- 118,122 ---- }
+ /* get current logical time. We don't specify what units this is in; use clock_gettimesince() to measure intervals from time of this call.