blob: e55ef706e271747e978d05bf94cc75a459747dda [file] [log] [blame]
Kevin Peng477fa942019-07-29 10:55:17 +08001/*
2 * Copyright (c) 2017-2019, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#ifndef __OS_WRAPPER_MUTEX_H__
9#define __OS_WRAPPER_MUTEX_H__
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15#include "common.h"
16
17/**
18 * \brief Creates a mutex for mutual exclusion of resources
19 *
Kevin Peng383e8402019-08-05 16:35:44 +080020 * \return The handle of the created mutex on success or NULL on error
Kevin Peng477fa942019-07-29 10:55:17 +080021 */
Kevin Peng383e8402019-08-05 16:35:44 +080022void *os_wrapper_mutex_create(void);
Kevin Peng477fa942019-07-29 10:55:17 +080023
24/**
25 * \brief Acquires a mutex that is created by \ref os_wrapper_mutex_create()
26 *
Kevin Peng383e8402019-08-05 16:35:44 +080027 * \param[in] handle The handle of the mutex to acquire. Should be one of the
28 * handles returned by \ref os_wrapper_mutex_create()
Kevin Peng477fa942019-07-29 10:55:17 +080029 * \param[in] timeout The maximum amount of time(in tick periods) for the
30 * thread to wait for the mutex to be available.
31 * If timeout is zero, the function will return immediately.
32 * Setting timeout to \ref OS_WRAPPER_WAIT_FOREVER will
33 * cause the thread to wait indefinitely
34 *
35 * \return \ref OS_WRAPPER_SUCCESS on success or \ref OS_WRAPPER_ERROR on error
36 */
Kevin Peng383e8402019-08-05 16:35:44 +080037uint32_t os_wrapper_mutex_acquire(void *handle, uint32_t timeout);
Kevin Peng477fa942019-07-29 10:55:17 +080038
39/**
40 * \brief Releases the mutex acquired previously
41 *
Kevin Peng383e8402019-08-05 16:35:44 +080042
43 * \param[in] handle The handle of the mutex that has been acquired
Kevin Peng477fa942019-07-29 10:55:17 +080044 *
45 * \return \ref OS_WRAPPER_SUCCESS on success or \ref OS_WRAPPER_ERROR on error
46 */
Kevin Peng383e8402019-08-05 16:35:44 +080047uint32_t os_wrapper_mutex_release(void *handle);
Kevin Peng477fa942019-07-29 10:55:17 +080048
49/**
50 * \brief Deletes a mutex that is created by \ref os_wrapper_mutex_create()
51 *
Kevin Peng383e8402019-08-05 16:35:44 +080052 * \param[in] handle The handle of the mutex to be deleted
Kevin Peng477fa942019-07-29 10:55:17 +080053 *
54 * \return \ref OS_WRAPPER_SUCCESS on success or \ref OS_WRAPPER_ERROR on error
55 */
Kevin Peng383e8402019-08-05 16:35:44 +080056uint32_t os_wrapper_mutex_delete(void *handle);
Kevin Peng477fa942019-07-29 10:55:17 +080057
58#ifdef __cplusplus
59}
60#endif
61
62#endif /* __OS_WRAPPER_MUTEX_H__ */