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

📄 tm_basic.cxx

📁 eCos1.31版
💻 CXX
📖 第 1 页 / 共 5 页
字号:
    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");    // Must unlock mutices before destroying them.    for (i = 0;  i < nmutexes;  i++) {        cyg_mutex_unlock(&test_mutexes[i]);    }    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);        cyg_mbox_put(test_mbox_handles[i], (void *)i);        HAL_CLOCK_READ(&mbox_ft[i].end);    }    show_times(mbox_ft, nmboxes, "Put [first] 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 [1 msg] 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);        cyg_mbox_put(test_mbox_handles[i], (void *)i);        HAL_CLOCK_READ(&mbox_ft[i].end);    }    show_times(mbox_ft, nmboxes, "Put [second] 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 [2 msgs] 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);        item = cyg_mbox_get(test_mbox_handles[i]);        HAL_CLOCK_READ(&mbox_ft[i].end);    }    show_times(mbox_ft, nmboxes, "Get [first] 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);        item = cyg_mbox_get(test_mbox_handles[i]);        HAL_CLOCK_READ(&mbox_ft[i].end);    }    show_times(mbox_ft, nmboxes, "Get [second] mbox");#endif // 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);        cyg_mbox_tryput(test_mbox_handles[i], (void *)i);        HAL_CLOCK_READ(&mbox_ft[i].end);    }    show_times(mbox_ft, nmboxes, "Tryput [first] 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);        item = cyg_mbox_peek_item(test_mbox_handles[i]);        HAL_CLOCK_READ(&mbox_ft[i].end);    }    show_times(mbox_ft, nmboxes, "Peek item [non-empty] 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);        item = cyg_mbox_tryget(test_mbox_handles[i]);        HAL_CLOCK_READ(&mbox_ft[i].end);    }    show_times(mbox_ft, nmboxes, "Tryget [non-empty] 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);        item = cyg_mbox_peek_item(test_mbox_handles[i]);        HAL_CLOCK_READ(&mbox_ft[i].end);    }    show_times(mbox_ft, nmboxes, "Peek item [empty] 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);        item = cyg_mbox_tryget(test_mbox_handles[i]);        HAL_CLOCK_READ(&mbox_ft[i].end);    }    show_times(mbox_ft, nmboxes, "Tryget [empty] 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);        cyg_mbox_waiting_to_get(test_mbox_handles[i]);        HAL_CLOCK_READ(&mbox_ft[i].end);    }    show_times(mbox_ft, nmboxes, "Waiting to get 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);        cyg_mbox_waiting_to_put(test_mbox_handles[i]);        HAL_CLOCK_READ(&mbox_ft[i].end);    }    show_times(mbox_ft, nmboxes, "Waiting to put 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);        cyg_mbox_delete(test_mbox_handles[i]);        HAL_CLOCK_READ(&mbox_ft[i].end);    }    show_times(mbox_ft, nmboxes, "Delete mbox");    run_mbox_circuit_test();    end_of_test_group();}voidrun_mbox_circuit_test(void){#ifdef CYGMFN_KERNEL_SYNCH_MBOXT_PUT_CAN_WAIT    int i;    // Set my priority lower than any I plan to create    cyg_thread_set_priority(cyg_thread_self(), 3);    // Set up for full mbox put/get test    cyg_mbox_create(&test_mbox_handles[0], &test_mboxes[0]);    cyg_semaphore_init(&synchro, 0);    cyg_thread_create(2,              // Priority - just a number                      mbox_test,           // entry                      0,               // index                      thread_name("thread", 0),     // Name                      &stacks[0][0],   // Stack                      STACK_SIZE,      // Size                      &mbox_test_thread_handle,   // Handle                      &mbox_test_thread    // Thread data structure        );    cyg_thread_resume(mbox_test_thread_handle);    for (i = 0;  i < nmboxes;  i++) {        wait_for_tick(); // Wait until the next clock tick to minimize aberations        HAL_CLOCK_READ(&mbox_ft[i].start);        cyg_mbox_put(test_mbox_handles[0], (void *)i);        cyg_semaphore_wait(&synchro);    }    cyg_thread_delete(mbox_test_thread_handle);    show_times(mbox_ft, nmboxes, "Put/Get mbox");#endif}voidrun_semaphore_tests(void){    int i;    cyg_count32 sem_val;    // Semaphore primitives    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < nsemaphores;  i++) {        HAL_CLOCK_READ(&semaphore_ft[i].start);        cyg_semaphore_init(&test_semaphores[i], 0);        HAL_CLOCK_READ(&semaphore_ft[i].end);    }    show_times(semaphore_ft, nsemaphores, "Init semaphore");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < nsemaphores;  i++) {        HAL_CLOCK_READ(&semaphore_ft[i].start);        cyg_semaphore_post(&test_semaphores[i]);        HAL_CLOCK_READ(&semaphore_ft[i].end);    }    show_times(semaphore_ft, nsemaphores, "Post [0] semaphore");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < nsemaphores;  i++) {        HAL_CLOCK_READ(&semaphore_ft[i].start);        cyg_semaphore_wait(&test_semaphores[i]);        HAL_CLOCK_READ(&semaphore_ft[i].end);    }    show_times(semaphore_ft, nsemaphores, "Wait [1] semaphore");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < nsemaphores;  i++) {        HAL_CLOCK_READ(&semaphore_ft[i].start);        cyg_semaphore_trywait(&test_semaphores[i]);        HAL_CLOCK_READ(&semaphore_ft[i].end);    }    show_times(semaphore_ft, nsemaphores, "Trywait [0] semaphore");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < nsemaphores;  i++) {        cyg_semaphore_post(&test_semaphores[i]);        HAL_CLOCK_READ(&semaphore_ft[i].start);        cyg_semaphore_trywait(&test_semaphores[i]);        HAL_CLOCK_READ(&semaphore_ft[i].end);    }    show_times(semaphore_ft, nsemaphores, "Trywait [1] semaphore");    wait_for_tick(); // Wait until the next clock tick to minimize aberations    for (i = 0;  i < nsemaphores;  i++) {        HAL_CLOCK_READ(&semaphore_ft[i].start);

⌨️ 快捷键说明

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