ex
Fork of mbed-os-example-mbed5-blinky by
DuerOS-Light-SDK-v1.1.0/duer-os-light/src/mutex/baidu_iot_mutex.h@47:9e361da97763, 2017-07-18 (annotated)
- Committer:
- TMBOY
- Date:
- Tue Jul 18 16:54:45 2017 +0800
- Revision:
- 47:9e361da97763
?
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| TMBOY | 47:9e361da97763 | 1 | /** |
| TMBOY | 47:9e361da97763 | 2 | * Copyright 2017 Baidu Inc. All Rights Reserved. |
| TMBOY | 47:9e361da97763 | 3 | * Author: Gang Chen (chengang12@baidu.com) |
| TMBOY | 47:9e361da97763 | 4 | * This header file is wrapper for OS mutex |
| TMBOY | 47:9e361da97763 | 5 | * |
| TMBOY | 47:9e361da97763 | 6 | */ |
| TMBOY | 47:9e361da97763 | 7 | |
| TMBOY | 47:9e361da97763 | 8 | #ifndef IOT_BAIDU_BAIDU_IOT_MUTEX_H |
| TMBOY | 47:9e361da97763 | 9 | #define IOT_BAIDU_BAIDU_IOT_MUTEX_H |
| TMBOY | 47:9e361da97763 | 10 | |
| TMBOY | 47:9e361da97763 | 11 | #include <stdbool.h> |
| TMBOY | 47:9e361da97763 | 12 | |
| TMBOY | 47:9e361da97763 | 13 | #ifdef __cplusplus |
| TMBOY | 47:9e361da97763 | 14 | extern "C" { |
| TMBOY | 47:9e361da97763 | 15 | #endif |
| TMBOY | 47:9e361da97763 | 16 | |
| TMBOY | 47:9e361da97763 | 17 | typedef void *iot_mutex_t; |
| TMBOY | 47:9e361da97763 | 18 | |
| TMBOY | 47:9e361da97763 | 19 | typedef enum { |
| TMBOY | 47:9e361da97763 | 20 | IOT_MUTEX_OK = 0, // function completed; no error or event occurred. |
| TMBOY | 47:9e361da97763 | 21 | IOT_MUTEX_TIMEOUT, // Failed to lock mutex in specified time |
| TMBOY | 47:9e361da97763 | 22 | IOT_MUTEX_ERROR, |
| TMBOY | 47:9e361da97763 | 23 | } iot_mutex_status; |
| TMBOY | 47:9e361da97763 | 24 | |
| TMBOY | 47:9e361da97763 | 25 | /* |
| TMBOY | 47:9e361da97763 | 26 | * Create mutex |
| TMBOY | 47:9e361da97763 | 27 | * |
| TMBOY | 47:9e361da97763 | 28 | * @Return: the created mutex's pointer |
| TMBOY | 47:9e361da97763 | 29 | */ |
| TMBOY | 47:9e361da97763 | 30 | iot_mutex_t iot_mutex_create(void); |
| TMBOY | 47:9e361da97763 | 31 | |
| TMBOY | 47:9e361da97763 | 32 | /* |
| TMBOY | 47:9e361da97763 | 33 | * Lock a mutex |
| TMBOY | 47:9e361da97763 | 34 | * |
| TMBOY | 47:9e361da97763 | 35 | * @param mutex[in]: a pointer point to the mutex |
| TMBOY | 47:9e361da97763 | 36 | * @param timeout_ms[in]: timeout value or 0 in case of no time-out |
| TMBOY | 47:9e361da97763 | 37 | * |
| TMBOY | 47:9e361da97763 | 38 | * @Return: iot_mutex_status |
| TMBOY | 47:9e361da97763 | 39 | */ |
| TMBOY | 47:9e361da97763 | 40 | iot_mutex_status iot_mutex_lock(iot_mutex_t mutex, uint32_t timeout_ms); |
| TMBOY | 47:9e361da97763 | 41 | |
| TMBOY | 47:9e361da97763 | 42 | /* |
| TMBOY | 47:9e361da97763 | 43 | * Try to lock a mutex, and return immediately |
| TMBOY | 47:9e361da97763 | 44 | * |
| TMBOY | 47:9e361da97763 | 45 | * @param mutex[in]: a pointer point to the mutex |
| TMBOY | 47:9e361da97763 | 46 | * |
| TMBOY | 47:9e361da97763 | 47 | * @return: true if the mutex was acquired, false otherwise. |
| TMBOY | 47:9e361da97763 | 48 | */ |
| TMBOY | 47:9e361da97763 | 49 | bool iot_mutex_try_lock(iot_mutex_t mutex); |
| TMBOY | 47:9e361da97763 | 50 | |
| TMBOY | 47:9e361da97763 | 51 | /* |
| TMBOY | 47:9e361da97763 | 52 | * Unlock a mutex |
| TMBOY | 47:9e361da97763 | 53 | * |
| TMBOY | 47:9e361da97763 | 54 | * @param mutex[in]: a pointer point to the mutex |
| TMBOY | 47:9e361da97763 | 55 | * |
| TMBOY | 47:9e361da97763 | 56 | * @Return: iot_mutex_status |
| TMBOY | 47:9e361da97763 | 57 | */ |
| TMBOY | 47:9e361da97763 | 58 | iot_mutex_status iot_mutex_unlock(iot_mutex_t mutex); |
| TMBOY | 47:9e361da97763 | 59 | |
| TMBOY | 47:9e361da97763 | 60 | /* |
| TMBOY | 47:9e361da97763 | 61 | * Destroy the mutex context |
| TMBOY | 47:9e361da97763 | 62 | * |
| TMBOY | 47:9e361da97763 | 63 | * @param mutex[in]: a pointer point to the mutex |
| TMBOY | 47:9e361da97763 | 64 | * |
| TMBOY | 47:9e361da97763 | 65 | * @Return: iot_mutex_status |
| TMBOY | 47:9e361da97763 | 66 | */ |
| TMBOY | 47:9e361da97763 | 67 | iot_mutex_status iot_mutex_destroy(iot_mutex_t mutex); |
| TMBOY | 47:9e361da97763 | 68 | |
| TMBOY | 47:9e361da97763 | 69 | #ifdef __cplusplus |
| TMBOY | 47:9e361da97763 | 70 | } |
| TMBOY | 47:9e361da97763 | 71 | #endif |
| TMBOY | 47:9e361da97763 | 72 | #endif // end IOT_BAIDU_BAIDU_IOT_MUTEX_H |
