mqtt: use sys_mutex instead of k_mutex

Allows the mqtt_client data structure to exist in user memory.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2019-03-27 15:55:46 -07:00 committed by Anas Nashif
commit 7e3a34f84f
2 changed files with 12 additions and 4 deletions

View file

@ -27,6 +27,7 @@
#include <zephyr.h>
#include <zephyr/types.h>
#include <net/tls_credentials.h>
#include <misc/mutex.h>
#ifdef __cplusplus
extern "C" {
@ -404,7 +405,7 @@ struct mqtt_transport {
/** @brief MQTT internal state. */
struct mqtt_internal {
/** Internal. Mutex to protect access to the client instance. */
struct k_mutex mutex;
struct sys_mutex mutex;
/** Internal. Wall clock value (in milliseconds) of the last activity
* that occurred. Needed for periodic PING.

View file

@ -20,6 +20,7 @@
#include <stddef.h>
#include <kernel.h>
#include <misc/mutex.h>
#include <net/net_core.h>
@ -41,7 +42,7 @@ extern "C" {
*/
static inline void mqtt_mutex_init(struct mqtt_client *client)
{
k_mutex_init(&client->internal.mutex);
sys_mutex_init(&client->internal.mutex);
}
/**@brief Acquire lock on the module specific mutex, if any.
@ -51,14 +52,20 @@ static inline void mqtt_mutex_init(struct mqtt_client *client)
*/
static inline void mqtt_mutex_lock(struct mqtt_client *client)
{
(void)k_mutex_lock(&client->internal.mutex, K_FOREVER);
int ret = sys_mutex_lock(&client->internal.mutex, K_FOREVER);
__ASSERT(ret == 0, "sys_mutex_lock failed with %d", ret);
(void)ret;
}
/**@brief Release the lock on the module specific mutex, if any.
*/
static inline void mqtt_mutex_unlock(struct mqtt_client *client)
{
k_mutex_unlock(&client->internal.mutex);
int ret = sys_mutex_unlock(&client->internal.mutex);
__ASSERT(ret == 0, "sys_mutex_unlock failed with %d", ret);
(void)ret;
}
/**@brief Method to get the sys tick or a wall clock in millisecond resolution.