comparison packages/kernel/current/tests/tm_basic.cxx @ 60:3836136e7743 ecos-sw-1999-12-17

Merge from eCos master repository on 1999-12-17-19:44:58-GMT
author jlarmour
date Fri, 17 Dec 1999 20:15:45 +0000
parents 755351606154
children c38311975d4f
comparison
equal deleted inserted replaced
59:19ba0f558903 60:3836136e7743
1148 if (alarm_cnt == nscheds) { 1148 if (alarm_cnt == nscheds) {
1149 cyg_semaphore_post(&synchro); 1149 cyg_semaphore_post(&synchro);
1150 } 1150 }
1151 } 1151 }
1152 1152
1153 static void
1154 alarm_cb3(cyg_handle_t alarm, cyg_addrword_t indx)
1155 {
1156 if (alarm_cnt == nscheds) {
1157 cyg_semaphore_post(&synchro);
1158 } else {
1159 sched_ft[alarm_cnt].start = 0;
1160 cyg_thread_resume((cyg_handle_t)indx);
1161 }
1162 }
1163
1153 // Null thread, used to keep scheduler busy 1164 // Null thread, used to keep scheduler busy
1154 void 1165 void
1155 alarm_test(cyg_uint32 id) 1166 alarm_test(cyg_uint32 id)
1156 { 1167 {
1157 while (true) { 1168 while (true) {
1158 cyg_thread_yield(); 1169 cyg_thread_yield();
1170 }
1171 }
1172
1173 // Thread that suspends itself at the first opportunity
1174 void
1175 alarm_test2(cyg_uint32 id)
1176 {
1177 cyg_handle_t me = cyg_thread_self();
1178 while (true) {
1179 HAL_CLOCK_READ(&sched_ft[alarm_cnt++].end);
1180 cyg_thread_suspend(me);
1159 } 1181 }
1160 } 1182 }
1161 1183
1162 void 1184 void
1163 run_alarm_tests(void) 1185 run_alarm_tests(void)
1358 show_times(sched_ft, nscheds, "Alarm latency [many threads]"); 1380 show_times(sched_ft, nscheds, "Alarm latency [many threads]");
1359 for (i = 0; i < ntest_threads; i++) { 1381 for (i = 0; i < ntest_threads; i++) {
1360 cyg_thread_suspend(threads[i]); 1382 cyg_thread_suspend(threads[i]);
1361 cyg_thread_delete(threads[i]); 1383 cyg_thread_delete(threads[i]);
1362 } 1384 }
1385
1386 // Set my priority higher than any I plan to create
1387 cyg_thread_set_priority(cyg_thread_self(), 2);
1388 cyg_thread_create(10, // Priority - just a number
1389 alarm_test2, // entry
1390 i, // index
1391 thread_name("thread", 0), // Name
1392 &stacks[0][0], // Stack
1393 STACK_SIZE, // Size
1394 &threads[0], // Handle
1395 &test_threads[0] // Thread data structure
1396 );
1397 wait_for_tick(); // Wait until the next clock tick to minimize aberations
1398 cyg_clock_to_counter(cyg_real_time_clock(), &rtc_handle);
1399 cyg_alarm_create(rtc_handle, alarm_cb3, threads[0], &alarms[0],
1400 &test_alarms[0]);
1401 init_val = 5; step_val = 5; alarm_cnt = 0;
1402 cyg_alarm_initialize(alarms[0], init_val, step_val);
1403 cyg_semaphore_init(&synchro, 0);
1404 cyg_alarm_enable(alarms[0]);
1405 cyg_semaphore_wait(&synchro);
1406 cyg_alarm_disable(alarms[0]);
1407 cyg_alarm_delete(alarms[0]);
1408 show_times(sched_ft, nscheds, "Alarm -> thread resume latency");
1409 cyg_thread_suspend(threads[0]);
1410 cyg_thread_delete(threads[0]);
1411
1363 end_of_test_group(); 1412 end_of_test_group();
1364 } 1413 }
1365 1414
1366 void 1415 void
1367 run_sched_tests(void) 1416 run_sched_tests(void)