⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tm_basic.cxx

📁 ecos为实时嵌入式操作系统
💻 CXX
📖 第 1 页 / 共 4 页
字号:
    cyg_mutex_lock(&test_mutexes[0]);    for (i = 0;  i < nmutexes;  i++) {        cyg_semaphore_wait(&synchro);        wait_for_tick(); // Wait until the next clock tick to minimize aberations        HAL_CLOCK_READ(&mutex_ft[i].start);        cyg_mutex_unlock(&test_mutexes[0]);        cyg_mutex_lock(&test_mutexes[0]);        cyg_semaphore_post(&synchro);    }    cyg_thread_exit();}// Full-circuit mbox put/get testvoidmbox_test(cyg_uint32 indx){    void *item;    do {        item = cyg_mbox_get(test_mbox_handles[0]);        HAL_CLOCK_READ(&mbox_ft[(int)item].end);        cyg_semaphore_post(&synchro);    } while ((int)item != (nmboxes-1));    cyg_thread_exit();}// Full-circuit semaphore post/wait testvoidsemaphore_test(cyg_uint32 indx){    int i;    for (i = 0;  i < nsemaphores;  i++) {        cyg_semaphore_wait(&test_semaphores[0]);        HAL_CLOCK_READ(&semaphore_ft[i].end);        cyg_semaphore_post(&synchro);    }    cyg_thread_exit();}//// This set of tests is used to measure kernel primitives that deal with threads//voidrun_thread_tests(void){    int i;    cyg_priority_t prio;    // Set my priority higher than any I plan to create    cyg_thread_set_priority(cyg_thread_self(), 2);    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < ntest_threads;  i++) {        HAL_CLOCK_READ(&thread_ft[i].start);        cyg_thread_create(10,              // Priority - just a number                          test0,           // entry                          i,               // index                          thread_name("thread", i),     // Name                          &stacks[i][0],   // Stack                          STACK_SIZE,      // Size                          &threads[i],     // Handle                          &test_threads[i] // Thread data structure            );        HAL_CLOCK_READ(&thread_ft[i].end);    }    show_times(thread_ft, ntest_threads, "Create thread");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < ntest_threads;  i++) {        HAL_CLOCK_READ(&thread_ft[i].start);        cyg_thread_yield();        HAL_CLOCK_READ(&thread_ft[i].end);    }    show_times(thread_ft, ntest_threads, "Yield thread [all suspended]");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < ntest_threads;  i++) {        HAL_CLOCK_READ(&thread_ft[i].start);        cyg_thread_suspend(threads[i]);        HAL_CLOCK_READ(&thread_ft[i].end);    }    show_times(thread_ft, ntest_threads, "Suspend [suspended] thread");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < ntest_threads;  i++) {        HAL_CLOCK_READ(&thread_ft[i].start);        cyg_thread_resume(threads[i]);        HAL_CLOCK_READ(&thread_ft[i].end);    }    show_times(thread_ft, ntest_threads, "Resume thread");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < ntest_threads;  i++) {        HAL_CLOCK_READ(&thread_ft[i].start);        cyg_thread_set_priority(threads[i], 11);        HAL_CLOCK_READ(&thread_ft[i].end);    }    show_times(thread_ft, ntest_threads, "Set priority");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < ntest_threads;  i++) {        HAL_CLOCK_READ(&thread_ft[i].start);        prio = cyg_thread_get_priority(threads[i]);        HAL_CLOCK_READ(&thread_ft[i].end);    }    show_times(thread_ft, ntest_threads, "Get priority");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < ntest_threads;  i++) {        HAL_CLOCK_READ(&thread_ft[i].start);        cyg_thread_kill(threads[i]);        HAL_CLOCK_READ(&thread_ft[i].end);    }    show_times(thread_ft, ntest_threads, "Kill [suspended] thread");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < ntest_threads;  i++) {        HAL_CLOCK_READ(&thread_ft[i].start);        cyg_thread_yield();        HAL_CLOCK_READ(&thread_ft[i].end);    }    show_times(thread_ft, ntest_threads, "Yield [no other] thread");    // Set my priority higher than any I plan to create    cyg_thread_set_priority(cyg_thread_self(), 2);    // Recreate the test set    for (i = 0;  i < ntest_threads;  i++) {        cyg_thread_create(10,              // Priority - just a number                          test0,           // entry                          i,               // index                          thread_name("thread", i),     // Name                          &stacks[i][0],   // Stack                          STACK_SIZE,      // Size                          &threads[i],     // Handle                          &test_threads[i] // Thread data structure            );    }    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < ntest_threads;  i++) {        HAL_CLOCK_READ(&thread_ft[i].start);        cyg_thread_resume(threads[i]);        HAL_CLOCK_READ(&thread_ft[i].end);    }    show_times(thread_ft, ntest_threads, "Resume [suspended low prio] thread");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < ntest_threads;  i++) {        HAL_CLOCK_READ(&thread_ft[i].start);        cyg_thread_resume(threads[i]);        HAL_CLOCK_READ(&thread_ft[i].end);    }    show_times(thread_ft, ntest_threads, "Resume [runnable low prio] thread");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < ntest_threads;  i++) {        HAL_CLOCK_READ(&thread_ft[i].start);        cyg_thread_suspend(threads[i]);        HAL_CLOCK_READ(&thread_ft[i].end);    }    show_times(thread_ft, ntest_threads, "Suspend [runnable] thread");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < ntest_threads;  i++) {        HAL_CLOCK_READ(&thread_ft[i].start);        cyg_thread_yield();        HAL_CLOCK_READ(&thread_ft[i].end);    }    show_times(thread_ft, ntest_threads, "Yield [only low prio] thread");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < ntest_threads;  i++) {        HAL_CLOCK_READ(&thread_ft[i].start);        cyg_thread_suspend(threads[i]);        HAL_CLOCK_READ(&thread_ft[i].end);    }    show_times(thread_ft, ntest_threads, "Suspend [runnable->not runnable]");    for (i = 0;  i < ntest_threads;  i++) {        cyg_thread_resume(threads[i]);    }    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < ntest_threads;  i++) {        HAL_CLOCK_READ(&thread_ft[i].start);        cyg_thread_kill(threads[i]);        HAL_CLOCK_READ(&thread_ft[i].end);    }    show_times(thread_ft, ntest_threads, "Kill [runnable] thread");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < ntest_threads;  i++) {        HAL_CLOCK_READ(&thread_ft[i].start);        cyg_thread_delete(threads[i]);        HAL_CLOCK_READ(&thread_ft[i].end);    }    show_times(thread_ft, ntest_threads, "Destroy [dead] thread");    // Recreate the test set    for (i = 0;  i < ntest_threads;  i++) {        cyg_thread_create(10,              // Priority - just a number                          test0,           // entry                          i,               // index                          thread_name("thread", i),     // Name                          &stacks[i][0],   // Stack                          STACK_SIZE,      // Size                          &threads[i],     // Handle                          &test_threads[i] // Thread data structure            );        cyg_thread_resume(threads[i]);    }    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < ntest_threads;  i++) {        HAL_CLOCK_READ(&thread_ft[i].start);        cyg_thread_delete(threads[i]);        HAL_CLOCK_READ(&thread_ft[i].end);    }    show_times(thread_ft, ntest_threads, "Destroy [runnable] thread");    // Set my priority lower than any I plan to create    cyg_thread_set_priority(cyg_thread_self(), 3);    // Set up the end-of-threads synchronizer    cyg_semaphore_init(&synchro, 0);    // Recreate the test set    for (i = 0;  i < ntest_threads;  i++) {        cyg_thread_create(2,               // Priority - just a number                          test1,           // entry                          i,               // index                          thread_name("thread", i),     // Name                          &stacks[i][0],   // Stack                          STACK_SIZE,      // Size                          &threads[i],     // Handle                          &test_threads[i] // Thread data structure            );    }    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < ntest_threads;  i++) {        HAL_CLOCK_READ(&thread_ft[i].start);        cyg_thread_resume(threads[i]);        HAL_CLOCK_READ(&thread_ft[i].end);    }    show_times(thread_ft, ntest_threads, "Resume [high priority] thread");    cyg_semaphore_wait(&synchro);  // Wait for all threads to finish    // Make sure they are all dead    for (i = 0;  i < ntest_threads;  i++) {        cyg_thread_delete(threads[i]);    }    run_thread_switch_test();    end_of_test_group();}voidrun_thread_switch_test(void){    int i;    // Set up for thread context switch     for (i = 0;  i < 2;  i++) {        cyg_thread_create(10,              // Priority - just a number                          test2,           // entry                          i,               // index                          thread_name("thread", i),     // Name                          &stacks[i][0],   // Stack                          STACK_SIZE,      // Size                          &threads[i],     // Handle                          &test_threads[i] // Thread data structure            );        cyg_thread_resume(threads[i]);    }    // Set up the end-of-threads synchronizer    cyg_semaphore_init(&synchro, 0);    cyg_semaphore_wait(&synchro);    wait_for_tick(); // Wait until the next clock tick to minimize aberations    show_times(test2_ft, nthread_switches, "Thread switch");    // Clean up    for (i = 0;  i < 2;  i++) {        cyg_thread_delete(threads[i]);    }}voidrun_mutex_tests(void){    int i;    // Mutex primitives    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < nmutexes;  i++) {        HAL_CLOCK_READ(&mutex_ft[i].start);        cyg_mutex_init(&test_mutexes[i]);        HAL_CLOCK_READ(&mutex_ft[i].end);    }    show_times(mutex_ft, nmutexes, "Init mutex");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < nmutexes;  i++) {        HAL_CLOCK_READ(&mutex_ft[i].start);        cyg_mutex_lock(&test_mutexes[i]);        HAL_CLOCK_READ(&mutex_ft[i].end);    }    show_times(mutex_ft, nmutexes, "Lock [unlocked] mutex");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < nmutexes;  i++) {        HAL_CLOCK_READ(&mutex_ft[i].start);        cyg_mutex_unlock(&test_mutexes[i]);        HAL_CLOCK_READ(&mutex_ft[i].end);    }    show_times(mutex_ft, nmutexes, "Unlock [locked] mutex");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < nmutexes;  i++) {        HAL_CLOCK_READ(&mutex_ft[i].start);        cyg_mutex_trylock(&test_mutexes[i]);        HAL_CLOCK_READ(&mutex_ft[i].end);    }    show_times(mutex_ft, nmutexes, "Trylock [unlocked] mutex");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < nmutexes;  i++) {        HAL_CLOCK_READ(&mutex_ft[i].start);        cyg_mutex_trylock(&test_mutexes[i]);        HAL_CLOCK_READ(&mutex_ft[i].end);    }    show_times(mutex_ft, nmutexes, "Trylock [locked] mutex");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < nmutexes;  i++) {        HAL_CLOCK_READ(&mutex_ft[i].start);        cyg_mutex_destroy(&test_mutexes[i]);        HAL_CLOCK_READ(&mutex_ft[i].end);    }    show_times(mutex_ft, nmutexes, "Destroy mutex");    run_mutex_circuit_test();    end_of_test_group();}voidrun_mutex_circuit_test(void){    int i;    // Set my priority lower than any I plan to create    cyg_thread_set_priority(cyg_thread_self(), 4);    // Set up for full mutex unlock/lock test    cyg_mutex_init(&test_mutexes[0]);    cyg_semaphore_init(&synchro, 0);    cyg_thread_create(3,              // Priority - just a number                      mutex_test,           // entry                      0,               // index                      thread_name("thread", 0),     // Name                      &stacks[0][0],   // Stack                      STACK_SIZE,      // Size                      &mutex_test_thread_handle,   // Handle                      &mutex_test_thread    // Thread data structure        );    cyg_thread_resume(mutex_test_thread_handle);    // Need to raise priority so that this thread will block on the "lock"    cyg_thread_set_priority(cyg_thread_self(), 2);    for (i = 0;  i < nmutexes;  i++) {        cyg_semaphore_post(&synchro);        cyg_mutex_lock(&test_mutexes[0]);        HAL_CLOCK_READ(&mutex_ft[i].end);        cyg_mutex_unlock(&test_mutexes[0]);        cyg_semaphore_wait(&synchro);    }    cyg_thread_delete(mutex_test_thread_handle);    show_times(mutex_ft, nmutexes, "Unlock/Lock mutex");}voidrun_mbox_tests(void){    int i, cnt;    void *item;    // Mailbox primitives    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < nmboxes;  i++) {        HAL_CLOCK_READ(&mbox_ft[i].start);        cyg_mbox_create(&test_mbox_handles[i], &test_mboxes[i]);        HAL_CLOCK_READ(&mbox_ft[i].end);    }    show_times(mbox_ft, nmboxes, "Create mbox");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < nmboxes;  i++) {        HAL_CLOCK_READ(&mbox_ft[i].start);        cnt = cyg_mbox_peek(test_mbox_handles[i]);        HAL_CLOCK_READ(&mbox_ft[i].end);    }    show_times(mbox_ft, nmboxes, "Peek [empty] mbox");#ifdef CYGMFN_KERNEL_SYNCH_MBOXT_PUT_CAN_WAIT    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < nmboxes;  i++) {        HAL_CLOCK_READ(&mbox_ft[i].start);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -