(bind-func scheduler_evt:[void,[i64,!a]*,!a,i8*]*
(let ((evtlist:SchedEvt* null)
(next:SchedEvt* null)
(new:SchedEvt* null))
(lambda (scheduler time fname)
;; (println "sched:" scheduler time fname data)
(if (= (thread_equal_self (scheduler.thread)) 0)
(mutex_lock (scheduler.mutex)))
(set! evtlist (scheduler_at (scheduler.evtlist) time))
(if (null? evtlist)
(begin
(set! next (scheduler.evtlist))
(set! new (SchedEvt_h time fname null next))
(scheduler.evtlist new)
void)
(begin
(set! next (tref evtlist 3)) ;; get next from previous
(set! new (SchedEvt_h time fname evtlist next))
(tset! evtlist 3 new) ;; make us next of previous
(if (not (null? next)) (tset! next 2 new)) ;; set us to previous of next
void))
(if (= (thread_equal_self (scheduler.thread)) 0)
(mutex_unlock (scheduler.mutex)))
void)))