瀏覽代碼

TC: do not use rt_sem_trytake to clean the sem

There can be a race condition that the sem has alread been detached
after we did the cleanup. Besides, there is a RT_IPC_CMD_RESET command
in rt_sem_control which is more clear in setting the sem values.
Grissiom 11 年之前
父節點
當前提交
e9e8e3f3ca
共有 1 個文件被更改,包括 2 次插入2 次删除
  1. 2 2
      examples/kernel/tc_comm.c

+ 2 - 2
examples/kernel/tc_comm.c

@@ -40,6 +40,8 @@ void tc_thread_entry(void* parameter)
 				tick = index->func();
 				if (tick > 0)
 				{
+					/* Make sure we are going to be blocked. */
+					rt_sem_control(&_tc_sem, RT_IPC_CMD_RESET, 0);
 					rt_sem_take(&_tc_sem, tick * _tc_scale);
 
 					if (_tc_cleanup != RT_NULL)
@@ -49,8 +51,6 @@ void tc_thread_entry(void* parameter)
 						_tc_cleanup = RT_NULL;
 					}
 
-					rt_sem_trytake(&_tc_sem);/* by nl1031 */
-
 					if (_tc_stat & TC_STAT_FAILED)
 						rt_kprintf("TestCase[%s] failed\n", _tc_current);
 					else