UINT _tx_semaphore_get(
TX_SEMAPHORE *semaphore_ptr,
ULONG wait_option);
局部变量:
1.如果信号量计数器tx_semaphore_count不为0,就减一,返回申请成功。
2.如果信号量计数器tx_semaphore_count为0,说明资源都被占用,挂起当前线程到suspension list的尾部,后续恢复时按FIFO
流程:
1.禁止中断
2.若count不为0 //还有信号量资源
(1) count--
(2) 设置status为success
3.若count为0 //没有信号量资源
(1) wait_option不为0
1) 由于获取不到信号量而挂起,所以设置清除函数为信号量相关的函数tx_semaphore_cleanup,当定时器超时或线程中止时,回调这个函数,释放清除和信号量相关数据,比如从tx_semaphore_suspension_list队列移除线程
2) 挂起线程
3) suspended count++
4) 设置state为semaphore susp
5) 设置suspending flag
6) 禁止抢占
7) 设置timer
8) 恢复中断
9) 若wait_option不为forever,开启timer
10) _tx_thread_suspend( )
11) 返回status
(2) wait_option为0
status为no_instance
4.恢复中断
5.返回status