Beispiel #1
0
//---------------------------------------------------------------------------
void App2Main(void *unused_)
{
    K_USHORT usFlag = 1;
    while(1)
    {
        Thread_Sleep(100);

        // Event flags essentially map events to bits in a bitmap.  Here we
        // set one bit each 100ms.  In this loop, we cycle through bits 0-15
        // repeatedly.  Note that this will wake the other thread, which is
        // blocked, waiting for *any* of the flags in the bitmap to be set.
        EventFlag_Set( &stFlags, usFlag);

        // Bitshift the flag value to the left.  This will be the flag we set
        // the next time this thread runs through its loop.
        if (usFlag != 0x8000)
        {
            usFlag <<= 1;
        }
        else
        {
            usFlag = 1;
        }
    }
}
Beispiel #2
0
//---------------------------------------------------------------------------
void App1Main(void *unused_)
{
    K_USHORT usData = 0;
    while(1)
    {
        // This thread grabs a message from the global message pool, sets a
        // code-value and the message data pointer, then sends the message to
        // a message queue object.  Another thread (Thread2) is blocked, waiting
        // for a message to arrive in the queue.

        // Get the message object
        Message_t *pstMsg = GlobalMessagePool_Pop();

        // Set the message object's data (contrived in this example)
        Message_SetCode( pstMsg, 0x1337);
        usData++;
        Message_SetData( pstMsg, &usData);

        // Send the message to the shared message queue
        MessageQueue_Send( &stMsgQ, pstMsg);

        // Wait before sending another message.
        Thread_Sleep(20);
    }
}
Beispiel #3
0
/**
 * Thread entry point for the synthesizer. Runs until the song is stopped.
 * @param parm  Not used.
 * @return Always zero.
 */
static int synthWorkThread(void* parm)
{
    DENG_UNUSED(parm);
    DENG_ASSERT(blockBuffer != 0);

    byte samples[BLOCK_SIZE];

    while(!workerShouldStop)
    {
        if(blockBuffer->availableForWriting() < BLOCK_SIZE)
        {
            // We should not or cannot produce samples right now, let's sleep for a while.
            Thread_Sleep(50);
            continue;
        }

        //DSFLUIDSYNTH_TRACE("Synthesizing next block using fsPlayer " << fsPlayer);

        // Synthesize a block of samples into our buffer.
        fluid_synth_write_s16(DMFluid_Synth(), BLOCK_SAMPLES, samples, 0, 2, samples, 1, 2);
        blockBuffer->write(samples, BLOCK_SIZE);

        //DSFLUIDSYNTH_TRACE("Block written.");
    }

    DSFLUIDSYNTH_TRACE("Synth worker dies.");
    return 0;
}
Beispiel #4
0
void Sys_Sleep(int millisecs)
{
    /*
#ifdef WIN32
    Sleep(millisecs);
#endif
*/
    Thread_Sleep(millisecs);
}
Beispiel #5
0
static void Thread_tSleepEntryPoint(void *unused_)
{
    unused_ = unused_;

    // Thread_t will sleep for various intervals, synchronized
    // to Semaphore_t-based IPC.
    Semaphore_Pend( &stSem1 );
    Thread_Sleep(5);
    Semaphore_Post( &stSem2 );

    Semaphore_Pend( &stSem1 );
    Thread_Sleep(50);
    Semaphore_Post( &stSem2 );

    Semaphore_Pend( &stSem1 );
    Thread_Sleep(500);
    Semaphore_Post( &stSem2 );

    // Exit this Thread_t.
    Thread_Exit( Scheduler_GetCurrentThread() );
}
Beispiel #6
0
//---------------------------------------------------------------------------
static void PrintWait( Driver_t *pstDriver_, K_USHORT usSize_, const K_CHAR *data )
{
    K_USHORT usWritten = 0;
    
    while (usWritten < usSize_)
    {
        usWritten += Driver_Write( pstDriver_, (usSize_ - usWritten), (K_UCHAR*)(&data[usWritten]));
        if (usWritten != usSize_)
        {
            Thread_Sleep(5);
        }
    }
}
Beispiel #7
0
TEST_END

//===========================================================================
TEST(ut_thread_stop)
{
    // Test point - stop and restart a Thread_t
    Thread_Stop( &stThread1 );
    Thread_Sleep(10);
    Thread_Start( &stThread1 );

    // Poke the Thread_t using a Semaphore_t, verify it's still responding
    Semaphore_Post( &stSem2 );
    Semaphore_TimedPend( &stSem1, 10 );

    EXPECT_FALSE( Thread_GetExpired( Scheduler_GetCurrentThread() ) );
}
Beispiel #8
0
//---------------------------------------------------------------------------
static void AppMain( void *unused )
{
    Driver_t *pstUART = DriverList_FindByPath("/dev/tty");
    
#if UNIT_TEST    
    UT_Init();
#endif
    
#if PROFILE_TEST
    ProfileInit();
#endif    

    Driver_Control( pstUART, CMD_SET_BUFFERS, 0, NULL, 32, aucTxBuf );
    {
        K_ULONG ulBaudRate = 57600;
        Driver_Control( pstUART, CMD_SET_BAUDRATE, 0, &ulBaudRate, 0, 0 );
        Driver_Control( pstUART, CMD_SET_RX_DISABLE, 0, 0, 0, 0);
    }
    
    Driver_Open( pstUART );
    Driver_Write( pstUART, 6,(K_UCHAR*)"START\n");

    while(1)
    {

#if PROFILE_TEST
        //---[ API Profiling ]-----------------------------
        Profiler_Start();
        ProfileOverhead();        
        Semaphore_Profiling();
        Mutex_Profiling();
        Thread_Profiling();
        Scheduler_Profiling();
        Profiler_Stop();
                
        ProfilePrintResults();
        Thread_Sleep(500);
#endif        
    }
}
Beispiel #9
0
TEST_END

//===========================================================================
TEST(ut_quanta)
{
    K_ULONG ulAvg;
    K_ULONG ulMax;
    K_ULONG ulMin;
    K_ULONG ulRange;

    // Create three Thread_ts that only increment counters - similar to the
    // previous test.  However, modify the Thread_t quanta such that each Thread_t
    // will get a different proportion of the CPU cycles.
    Thread_Init( &stThread1, aucStack1, TEST_STACK_SIZE, 1, RR_EntryPoint, (void*)&ulRR1);
    Thread_Init( &stThread2, aucStack2, TEST_STACK_SIZE, 1, RR_EntryPoint, (void*)&ulRR2);
    Thread_Init( &stThread3, aucStack3, TEST_STACK_SIZE, 1, RR_EntryPoint, (void*)&ulRR3);

    ulRR1 = 0;
    ulRR2 = 0;
    ulRR3 = 0;

    // Adjust Thread_t priority before starting test Thread_ts to ensure
    // they all start at the same time (when we hit the 1 second sleep)
    Thread_SetPriority( Scheduler_GetCurrentThread(), 2);

    // Set a different execution quanta for each Thread_t
    Thread_SetQuantum( &stThread1, 3);
    Thread_SetQuantum( &stThread2, 6);
    Thread_SetQuantum( &stThread3, 9);

    Thread_Start( &stThread1 );
    Thread_Start( &stThread2 );
    Thread_Start( &stThread3 );

    Thread_Sleep(1800);

    // When the sleep ends, this will preempt the Thread_t in progress,
    // allowing us to stop them, and drop priority.
    Thread_Stop( &stThread1 );
    Thread_Stop( &stThread2 );
    Thread_Stop( &stThread3 );
    Thread_SetPriority( Scheduler_GetCurrentThread(), 1);

    // Test point - make sure that Q3 > Q2 > Q1
    EXPECT_GT( ulRR2, ulRR1 );
    EXPECT_GT( ulRR3, ulRR2 );

    // scale the counters relative to the largest value, and compare.
    ulRR1 *= 3;
    ulRR2 *= 3;
    ulRR2 = (ulRR2 + 1) / 2;

    // After scaling, they should be nearly identical (well, stose at least)
    if (ulRR1 > ulRR2)
    {
        ulMax = ulRR1;
    }
    else
    {
        ulMax = ulRR2;
    }
    if (ulMax < ulRR3)
    {
        ulMax = ulRR3;
    }

    if (ulRR1 < ulRR2)
    {
        ulMin = ulRR1;
    }
    else
    {
        ulMin = ulRR2;
    }
    if (ulMin > ulRR3)
    {
        ulMin = ulRR3;
    }
    ulRange = ulMax - ulMin;
    ulAvg = (ulRR1 + ulRR2 + ulRR3) / 3;

#if KERNEL_TIMERS_TICKLESS
    // Max-Min delta should not exceed 5% of average for this test
    EXPECT_LT( ulRange, ulAvg / 20);
#else
    // Max-Min delta should not exceed 20% of average for this test -- tick-based timers
    // are coarse, and prone to Thread_t preference due to phase.
    EXPECT_LT( ulRange, ulAvg / 5);
#endif


    // Make sure none of the component values are 0
    EXPECT_FAIL_EQUALS( ulRR1, 0 );
    EXPECT_FAIL_EQUALS( ulRR2, 0 );
    EXPECT_FAIL_EQUALS( ulRR3, 0 );
}