pm_mutex.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. */
  12. #ifndef MUTEX_H__
  13. #define MUTEX_H__
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. /**
  17. * @cond NO_DOXYGEN
  18. * @defgroup pm_mutex Mutex
  19. * @ingroup peer_manager
  20. * @{
  21. * @brief An internal module of @ref peer_manager. This module provides thread-safe mutexes.
  22. */
  23. /**@brief Defines the storage size of a specified mutex group.
  24. *
  25. * @param number_of_mutexes the number of mutexes in the group.
  26. */
  27. #define MUTEX_STORAGE_SIZE(number_of_mutexes) ((7 + (number_of_mutexes)) >> 3)
  28. /**@brief Initializes a mutex group.
  29. *
  30. * @param[in] p_mutex Pointer to the mutex group. See @ref MUTEX_STORAGE_SIZE().
  31. * @param[in] mutex_size The size of the mutex group in number of mutexes.
  32. */
  33. void pm_mutex_init(uint8_t * p_mutex, uint16_t mutex_size);
  34. /**@brief Locks the mutex specified by the bit id.
  35. *
  36. * @param[inout] p_mutex Pointer to the mutex group.
  37. * @param[in] mutex_bit_id The bit id of the mutex.
  38. *
  39. * @retval true if it was possible to lock the mutex.
  40. * @retval false otherwise.
  41. */
  42. bool pm_mutex_lock(uint8_t * p_mutex, uint16_t mutex_bit_id);
  43. /**@brief Locks the first unlocked mutex within the mutex group.
  44. *
  45. * @param[in, out] p_mutex Pointer to the mutex group.
  46. * @param[in] mutex_size The size of the mutex group.
  47. *
  48. * @return The first unlocked mutex id in the group.
  49. * @retval group-size if there was no unlocked mutex available.
  50. */
  51. uint16_t pm_mutex_lock_first_available(uint8_t * p_mutex, uint16_t mutex_size);
  52. /**@brief Unlocks the mutex specified by the bit id.
  53. *
  54. * @param[in, out] p_mutex Pointer to the mutex group.
  55. * @param[in] mutex_bit_id The bit id of the mutex.
  56. */
  57. void pm_mutex_unlock(uint8_t * p_mutex, uint16_t mutex_bit_id);
  58. /**@brief Gets the locking status of the specified mutex.
  59. *
  60. * @param[in, out] p_mutex Pointer to the mutex group.
  61. * @param[in] mutex_bit_id The bit id of the mutex.
  62. *
  63. * @retval true if the mutex was locked.
  64. * @retval false otherwise.
  65. */
  66. bool pm_mutex_lock_status_get(uint8_t * p_mutex, uint16_t mutex_bit_id);
  67. #endif // MUTEX_H__
  68. /** @}
  69. * @endcond
  70. */