欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 培训 > RTOS接口-Semaphores

RTOS接口-Semaphores

2025/10/20 1:59:26 来源:https://blog.csdn.net/fantasyYXQ/article/details/147655270  浏览:    关键词:RTOS接口-Semaphores

跟Linux下面的信号量的PV操作是一个思想

接口

/*Create and Initialize a Semaphore object.*/
osSemaphoreId_t  osSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr)/*Get name of a Semaphore object.*/
const char *  osSemaphoreGetName (osSemaphoreId_t semaphore_id)/*Acquire a Semaphore token or timeout if no tokens are available.*/
osStatus_t 	osSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout)/*Release a Semaphore token up to the initial maximum count.*/
osStatus_t 	osSemaphoreRelease (osSemaphoreId_t semaphore_id)/*Get current Semaphore token count.*/
uint32_t  osSemaphoreGetCount (osSemaphoreId_t semaphore_id)/*Delete a Semaphore object.*/ 
osStatus_t 	osSemaphoreDelete (osSemaphoreId_t semaphore_id)

代码举例

osSemaphoreId_t multiplex_id;void thread_n (void) {multiplex_id = osSemaphoreNew(3U, 3U, NULL);while(1) {osSemaphoreAcquire(multiplex_id, osWaitForever);// do somethingosSemaphoreRelease(multiplex_id);}
}

当信号量的数量为1时,实现的功能就跟互斥锁没有区别了

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词