|
发表于 2018-9-19 21:33:48
|
显示全部楼层
用stdio的话是会有互斥的问题,比较io这种流设备肯定是独占访问的,具体的话就是读操作会有读互斥,写会有写互斥
rtx4中标准库用到的互斥量,rtx的实现代码在此,但是有问题,我记得keil官方论坛有人讨论过这个问题
- /*--------------------------- _mutex_initialize -----------------------------*/
- int _mutex_initialize (OS_ID *mutex) {
- /* Allocate and initialize a system mutex. */
- if (nr_mutex >= OS_MUTEXCNT) {
- /* If you are here, you need to increase the number OS_MUTEXCNT. */
- for (;;);
- }
- *mutex = &std_libmutex[nr_mutex++];
- mutex_init (*mutex);
- return (1);
- }
- /*--------------------------- _mutex_acquire --------------------------------*/
- __used void _mutex_acquire (OS_ID *mutex) {
- /* Acquire a system mutex, lock stdlib resources. */
- if (runtask_id ()) {
- /* RTX running, acquire a mutex. */
- mutex_wait (*mutex);
- }
- }
- /*--------------------------- _mutex_release --------------------------------*/
- __used void _mutex_release (OS_ID *mutex) {
- /* Release a system mutex, unlock stdlib resources. */
- if (runtask_id ()) {
- /* RTX runnning, release a mutex. */
- mutex_rel (*mutex);
- }
- }
复制代码
|
|