示例#1
0
static void m_callbackscheduler(void)
{
    sys_initmidiqueue();
    while (!sys_quit)
    {
#ifdef MSW
    Sleep(1000);
#else
        sleep(1);
#endif
        if (sys_idlehook)
            sys_idlehook();
    }
}
示例#2
0
文件: m_sched.c 项目: logsol/Pd-Pulp
static void m_callbackscheduler(void)
{
    sys_initmidiqueue();
    while (!sys_quit)
    {
        double timewas = pd_this->pd_systime;
#ifdef _WIN32
        Sleep(1000);
#else
        sleep(1);
#endif
        if (pd_this->pd_systime == timewas)
        {
            sys_lock();
            sys_pollgui();
            sched_tick();
            sys_unlock();
        }
        if (sys_idlehook)
            sys_idlehook();
    }
}
示例#3
0
static void m_callbackscheduler(void)
{
    sys_initmidiqueue();
    while (!sys_quit)
    {
        double timewas = sys_time;
#ifdef MSW
        Sleep(1000);
#else
        sleep(1);
#endif
        if (sys_time == timewas)
        {
            sys_lock();
            sys_pollgui();
            sched_tick(sys_time + sys_time_per_dsp_tick);
            sys_unlock();
        }
        if (sys_idlehook)
            sys_idlehook();
    }
}
示例#4
0
static void m_pollingscheduler( void)
{
    int idlecount = 0;
    sys_time_per_dsp_tick = (TIMEUNITPERSEC) *
        ((double)sys_schedblocksize) / sys_dacsr;

#ifdef THREAD_LOCKING
        sys_lock();
#endif

    sys_clearhist();
    if (sys_sleepgrain < 100)
        sys_sleepgrain = sys_schedadvance/4;
    if (sys_sleepgrain < 100)
        sys_sleepgrain = 100;
    else if (sys_sleepgrain > 5000)
        sys_sleepgrain = 5000;
    sys_initmidiqueue();
    while (!sys_quit)
    {
        int didsomething = 0;
        int timeforward;

        sys_addhist(0);
    waitfortick:
        if (sched_useaudio != SCHED_AUDIO_NONE)
        {
#ifdef THREAD_LOCKING
            /* T.Grill - send_dacs may sleep -> 
                unlock thread lock make that time available 
                - could messaging do any harm while sys_send_dacs is running?
            */
            sys_unlock();
#endif
            timeforward = sys_send_dacs();
#ifdef THREAD_LOCKING
            /* T.Grill - done */
            sys_unlock();
#endif
                /* if dacs remain "idle" for 1 sec, they're hung up. */
            if (timeforward != 0)
                idlecount = 0;
            else
            {
                idlecount++;
                if (!(idlecount & 31))
                {
                    static double idletime;
                    if (sched_useaudio != SCHED_AUDIO_POLL)
                    {
                            bug("m_pollingscheduler\n");
                            return;
                    }
                        /* on 32nd idle, start a clock watch;  every
                        32 ensuing idles, check it */
                    if (idlecount == 32)
                        idletime = sys_getrealtime();
                    else if (sys_getrealtime() - idletime > 1.)
                    {
                        post("audio I/O stuck... closing audio\n");
                        sys_close_audio();
                        sched_set_using_audio(SCHED_AUDIO_NONE);
                        goto waitfortick;
                    }
                }
            }
        }
        else
        {
            if (1000. * (sys_getrealtime() - sched_referencerealtime)
                > clock_gettimesince(sched_referencelogicaltime))
                    timeforward = SENDDACS_YES;
            else timeforward = SENDDACS_NO;
        }
        sys_setmiditimediff(0, 1e-6 * sys_schedadvance);
        sys_addhist(1);
        if (timeforward != SENDDACS_NO)
            sched_tick(sys_time + sys_time_per_dsp_tick);
        if (timeforward == SENDDACS_YES)
            didsomething = 1;

        sys_addhist(2);
        sys_pollmidiqueue();
        if (sys_pollgui())
        {
            if (!didsomething)
                sched_didpoll++;
            didsomething = 1;
        }
        sys_addhist(3);
            /* test for idle; if so, do graphics updates. */
        if (!didsomething)
        {
            sched_pollformeters();
            sys_reportidle();
#ifdef THREAD_LOCKING
            sys_unlock();   /* unlock while we idle */
#endif
                /* call externally installed idle function if any. */
            if (!sys_idlehook || !sys_idlehook())
            {
                    /* if even that had nothing to do, sleep. */
                if (timeforward != SENDDACS_SLEPT)
                    sys_microsleep(sys_sleepgrain);
            }
#ifdef THREAD_LOCKING
            sys_lock();
#endif
            sys_addhist(5);
            sched_didnothing++;
        }
    }

#ifdef THREAD_LOCKING
    sys_unlock();
#endif
}