ex

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers baidu_iot_mutex.h Source File

baidu_iot_mutex.h

00001 /**
00002  * Copyright 2017 Baidu Inc. All Rights Reserved.
00003  * Author: Gang Chen (chengang12@baidu.com)
00004  * This header file is wrapper for OS mutex
00005  *
00006  */
00007 
00008 #ifndef IOT_BAIDU_BAIDU_IOT_MUTEX_H
00009 #define IOT_BAIDU_BAIDU_IOT_MUTEX_H
00010 
00011 #include <stdbool.h>
00012 
00013 #ifdef __cplusplus
00014 extern "C" {
00015 #endif
00016 
00017 typedef void *iot_mutex_t;
00018 
00019 typedef enum {
00020     IOT_MUTEX_OK = 0,       // function completed; no error or event occurred.
00021     IOT_MUTEX_TIMEOUT,      // Failed to lock mutex in specified time
00022     IOT_MUTEX_ERROR,
00023 } iot_mutex_status;
00024 
00025 /*
00026  * Create mutex
00027  *
00028  * @Return: the created mutex's pointer
00029  */
00030 iot_mutex_t iot_mutex_create(void);
00031 
00032 /*
00033  * Lock a mutex
00034  *
00035  * @param mutex[in]: a pointer point to the mutex
00036  * @param timeout_ms[in]: timeout value or 0 in case of no time-out
00037  *
00038  * @Return: iot_mutex_status
00039  */
00040 iot_mutex_status iot_mutex_lock(iot_mutex_t mutex, uint32_t timeout_ms);
00041 
00042 /*
00043  * Try to lock a mutex, and return immediately
00044  *
00045  * @param mutex[in]: a pointer point to the mutex
00046  *
00047  * @return: true if the mutex was acquired, false otherwise.
00048  */
00049 bool iot_mutex_try_lock(iot_mutex_t mutex);
00050 
00051 /*
00052  * Unlock a mutex
00053  *
00054  * @param mutex[in]: a pointer point to the mutex
00055  *
00056  * @Return: iot_mutex_status
00057  */
00058 iot_mutex_status iot_mutex_unlock(iot_mutex_t mutex);
00059 
00060 /*
00061  * Destroy the mutex context
00062  *
00063  * @param mutex[in]: a pointer point to the mutex
00064  *
00065  * @Return: iot_mutex_status
00066  */
00067 iot_mutex_status iot_mutex_destroy(iot_mutex_t mutex);
00068 
00069 #ifdef __cplusplus
00070 }
00071 #endif
00072 #endif // end IOT_BAIDU_BAIDU_IOT_MUTEX_H