Mbed OS 文档翻译 之 参考(API(平台(PlatformMutex)))

PlatformMutex

                                                                         

                                                                              PlatformMutex 类层次结构

PlarformMutex 类在没有 RTOS 的情况下提供互斥存根函数。此类使您可以在 RTOS 不存在时使用驱动程序/应用程序代码。

PlatformMutex 类参考

PlatformMutex 类参考

公共成员函数
void lock ()
void unlock ()

PlatformMutex 示例

下面的代码演示了 PlatformMutex 的用法。

main.cpp                                                                                                                                           导入到 Mbed IDE

#include "mbed.h"

PlatformMutex stdio_mutex;
Thread t2;
Thread t3;
    
void notify(const char* name, int state) {
    stdio_mutex.lock();
    printf("%s: %d\n\r", name, state);
    stdio_mutex.unlock();
}

void test_thread(void const *args) {
    while (true) {
        notify((const char*)args, 0); wait(1);
        notify((const char*)args, 1); wait(1);
    }
}

int main() {
    t2.start(callback(test_thread, (void *)"Th 2"));
    t3.start(callback(test_thread, (void *)"Th 3"));

    test_thread((void *)"Th 1");
}

对于所有驱动程序,Mbed OS 使用 PlatformMutex 类而不是 RTOS 互斥锁。例如,请参见 AnalogInBusOutSPISerialI2C

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值