Skip to content

Commit

Permalink
Add gcc function attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSomeMan committed Dec 14, 2020
1 parent b3011f9 commit 1784a70
Show file tree
Hide file tree
Showing 18 changed files with 163 additions and 3 deletions.
6 changes: 6 additions & 0 deletions include/os_mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "os_wrapper_types.h"
#include "attribs.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -20,14 +21,19 @@ extern "C" {
typedef SemaphoreHandle_t os_mutex_t;
typedef StaticSemaphore_t os_mutex_static_t;

ATTR_WARN_UNUSED_RESULT
os_mutex_t
os_mutex_create(void);

#if configSUPPORT_STATIC_ALLOCATION
ATTR_WARN_UNUSED_RESULT
ATTR_NONNULL(1)
ATTR_RETURNS_NONNULL
os_mutex_t
os_mutex_create_static(os_mutex_static_t *const p_mutex_static);
#endif

ATTR_NONNULL(1)
void
os_mutex_delete(os_mutex_t *const ph_mutex);

Expand Down
6 changes: 6 additions & 0 deletions include/os_sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "os_wrapper_types.h"
#include "attribs.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -20,14 +21,19 @@ extern "C" {
typedef SemaphoreHandle_t os_sema_t;
typedef StaticSemaphore_t os_sema_static_t;

ATTR_WARN_UNUSED_RESULT
os_sema_t
os_sema_create(void);

#if configSUPPORT_STATIC_ALLOCATION
ATTR_WARN_UNUSED_RESULT
ATTR_NONNULL(1)
ATTR_RETURNS_NONNULL
os_sema_t
os_sema_create_static(os_sema_static_t *const p_sema_static);
#endif

ATTR_NONNULL(1)
void
os_sema_delete(os_sema_t *const ph_sema);

Expand Down
8 changes: 8 additions & 0 deletions include/os_signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <stdint.h>
#include <stdbool.h>
#include "os_wrapper_types.h"
#include "attribs.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -81,6 +82,8 @@ os_signal_create(void);
* @brief Create new os_signal_t object using pre-allocated memory.
* @return ptr to the instance of os_signal_t object.
*/
ATTR_RETURNS_NONNULL
ATTR_NONNULL(1)
os_signal_t *
os_signal_create_static(os_signal_static_t *const p_signal_mem);

Expand All @@ -90,6 +93,7 @@ os_signal_create_static(os_signal_static_t *const p_signal_mem);
* @note the passed ptr to the object will be set to NULL.
* @return None.
*/
ATTR_NONNULL(1)
void
os_signal_delete(os_signal_t **pp_signal);

Expand Down Expand Up @@ -140,6 +144,7 @@ os_signal_send(os_signal_t *const p_signal, const os_signal_num_e sig_num);
* @param[OUT] p_sig_events - ptr to @ref os_signal_events_t.
* @return true if success.
*/
ATTR_NONNULL(4)
bool
os_signal_wait_with_sig_mask(
os_signal_t *const p_signal,
Expand All @@ -154,6 +159,7 @@ os_signal_wait_with_sig_mask(
* @param[OUT] p_sig_events - ptr to @ref os_signal_events_t
* @return true if success
*/
ATTR_NONNULL(3)
bool
os_signal_wait_with_timeout(
os_signal_t *const p_signal,
Expand All @@ -166,9 +172,11 @@ os_signal_wait_with_timeout(
* @param[OUT] p_sig_events - ptr to @ref os_signal_events_t
* @return true if success
*/
ATTR_NONNULL(2)
void
os_signal_wait(os_signal_t *const p_signal, os_signal_events_t *const p_sig_events);

ATTR_NONNULL(1)
os_signal_num_e
os_signal_num_get_next(os_signal_events_t *const p_sig_events);

Expand Down
27 changes: 27 additions & 0 deletions include/os_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ typedef StaticTask_t os_task_static_t;
* @param[out] ph_task - pointer to the variable to return task handle
* @return true if successful
*/
ATTR_NONNULL(1, 6)
ATTR_WARN_UNUSED_RESULT
bool
os_task_create(
const os_task_func_t p_func,
Expand All @@ -58,6 +60,8 @@ os_task_create(
* @param[out] ph_task - pointer to the variable to return task handle
* @return true if successful
*/
ATTR_NONNULL(1, 4, 6)
ATTR_WARN_UNUSED_RESULT
bool
os_task_create_with_const_param(
const os_task_func_const_param_t p_func,
Expand All @@ -76,6 +80,8 @@ os_task_create_with_const_param(
* @param[out] ph_task - pointer to the variable to return task handle
* @return true if successful
*/
ATTR_NONNULL(1, 5)
ATTR_WARN_UNUSED_RESULT
bool
os_task_create_without_param(
const os_task_func_without_param_t p_func,
Expand All @@ -93,6 +99,8 @@ os_task_create_without_param(
* @param priority - task priority
* @return true if successful
*/
ATTR_NONNULL(1)
ATTR_WARN_UNUSED_RESULT
bool
os_task_create_finite(
const os_task_finite_func_with_param_t p_func,
Expand All @@ -110,6 +118,8 @@ os_task_create_finite(
* @param priority - task priority
* @return true if successful
*/
ATTR_NONNULL(1)
ATTR_WARN_UNUSED_RESULT
bool
os_task_create_finite_with_const_param(
const os_task_finite_func_with_const_param_t p_func,
Expand All @@ -126,6 +136,8 @@ os_task_create_finite_with_const_param(
* @param priority - task priority
* @return true if successful
*/
ATTR_NONNULL(1)
ATTR_WARN_UNUSED_RESULT
bool
os_task_create_finite_without_param(
const os_task_finite_func_without_param_t p_func,
Expand All @@ -145,6 +157,8 @@ os_task_create_finite_without_param(
* @param[out] ph_task - pointer to the variable to return task handle
* @return true if successful
*/
ATTR_NONNULL(1, 3, 7, 8)
ATTR_WARN_UNUSED_RESULT
bool
os_task_create_static(
const os_task_func_t p_func,
Expand All @@ -168,6 +182,8 @@ os_task_create_static(
* @param[out] ph_task - pointer to the variable to return task handle
* @return true if successful
*/
ATTR_NONNULL(1, 3, 7, 8)
ATTR_WARN_UNUSED_RESULT
bool
os_task_create_static_with_const_param(
const os_task_func_const_param_t p_func,
Expand All @@ -190,6 +206,8 @@ os_task_create_static_with_const_param(
* @param[out] ph_task - pointer to the variable to return task handle
* @return true if successful
*/
ATTR_NONNULL(1, 3, 6, 7)
ATTR_WARN_UNUSED_RESULT
bool
os_task_create_static_without_param(
const os_task_func_without_param_t p_func,
Expand All @@ -211,6 +229,8 @@ os_task_create_static_without_param(
* @param p_task_mem - pointer to the statically allocated buffer for @ref os_task_static_t
* @return true if successful
*/
ATTR_NONNULL(1, 3, 7)
ATTR_WARN_UNUSED_RESULT
bool
os_task_create_static_finite(
const os_task_finite_func_with_param_t p_func,
Expand All @@ -232,6 +252,8 @@ os_task_create_static_finite(
* @param p_task_mem - pointer to the statically allocated buffer for @ref os_task_static_t
* @return true if successful
*/
ATTR_NONNULL(1, 3, 7)
ATTR_WARN_UNUSED_RESULT
bool
os_task_create_static_finite_with_const_param(
const os_task_finite_func_with_const_param_t p_func,
Expand All @@ -252,6 +274,8 @@ os_task_create_static_finite_with_const_param(
* @param p_task_mem - pointer to the statically allocated buffer for @ref os_task_static_t
* @return true if successful
*/
ATTR_NONNULL(1, 3, 6)
ATTR_WARN_UNUSED_RESULT
bool
os_task_create_static_finite_without_param(
const os_task_finite_func_without_param_t p_func,
Expand All @@ -266,13 +290,15 @@ os_task_create_static_finite_without_param(
* @note All resources (dynamic memory, sockets, file descriptors, ...) allocated by the task will remain allocated.
* @param ph_task - ptr to variable which contains the task handle, this variable will be automatically cleared.
*/
ATTR_NONNULL(1)
void
os_task_delete(os_task_handle_t *const ph_task);

/**
* Get task name for the current thread.
* @return pointer to the string with the current task name.
*/
ATTR_WARN_UNUSED_RESULT
const char *
os_task_get_name(void);

Expand All @@ -287,6 +313,7 @@ os_task_delay(const os_delta_ticks_t delay_ticks);
* Get the handle of the current task.
* @return handle of the current task - @ref os_task_handle_t
*/
ATTR_WARN_UNUSED_RESULT
os_task_handle_t
os_task_get_cur_task_handle(void);

Expand Down
11 changes: 11 additions & 0 deletions include/os_timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/timers.h"
#include "os_wrapper_types.h"
#include "attribs.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -51,13 +52,17 @@ typedef struct os_timer_one_shot_static_t
typedef void (*os_timer_callback_periodic_t)(os_timer_periodic_t *p_timer, void *p_arg);
typedef void (*os_timer_callback_one_shot_t)(os_timer_one_shot_t *p_timer, void *p_arg);

ATTR_WARN_UNUSED_RESULT
os_timer_periodic_t *
os_timer_periodic_create(
const char *const p_timer_name,
const os_delta_ticks_t period_ticks,
const os_timer_callback_periodic_t cb_func,
void *const p_arg);

ATTR_WARN_UNUSED_RESULT
ATTR_NONNULL(1)
ATTR_RETURNS_NONNULL
os_timer_periodic_t *
os_timer_periodic_create_static(
os_timer_periodic_static_t *const p_mem,
Expand All @@ -66,13 +71,17 @@ os_timer_periodic_create_static(
const os_timer_callback_periodic_t cb_func,
void *const p_arg);

ATTR_WARN_UNUSED_RESULT
os_timer_one_shot_t *
os_timer_one_shot_create(
const char *const p_timer_name,
const os_delta_ticks_t period_ticks,
const os_timer_callback_one_shot_t cb_func,
void *const p_arg);

ATTR_WARN_UNUSED_RESULT
ATTR_NONNULL(1)
ATTR_RETURNS_NONNULL
os_timer_one_shot_t *
os_timer_one_shot_create_static(
os_timer_one_shot_static_t *const p_mem,
Expand All @@ -81,9 +90,11 @@ os_timer_one_shot_create_static(
const os_timer_callback_one_shot_t cb_func,
void *const p_arg);

ATTR_NONNULL(1)
void
os_timer_periodic_delete(os_timer_periodic_t **const pp_timer);

ATTR_NONNULL(1)
void
os_timer_one_shot_delete(os_timer_one_shot_t **const pp_timer);

Expand Down
11 changes: 11 additions & 0 deletions include/os_timer_sig.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "os_signal.h"
#include "os_timer.h"
#include "os_wrapper_types.h"
#include "attribs.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -49,13 +50,17 @@ typedef struct os_timer_sig_one_shot_static_t
os_timer_one_shot_static_t os_timer_mem;
} os_timer_sig_one_shot_static_t;

ATTR_WARN_UNUSED_RESULT
os_timer_sig_periodic_t *
os_timer_sig_periodic_create(
const char *const p_timer_name,
os_signal_t *const p_signal,
const os_signal_num_e sig_num,
const os_delta_ticks_t period_ticks);

ATTR_WARN_UNUSED_RESULT
ATTR_NONNULL(1)
ATTR_RETURNS_NONNULL
os_timer_sig_periodic_t *
os_timer_sig_periodic_create_static(
os_timer_sig_periodic_static_t *const p_timer_sig_mem,
Expand All @@ -64,13 +69,17 @@ os_timer_sig_periodic_create_static(
const os_signal_num_e sig_num,
const os_delta_ticks_t period_ticks);

ATTR_WARN_UNUSED_RESULT
os_timer_sig_one_shot_t *
os_timer_sig_one_shot_create(
const char *const p_timer_name,
os_signal_t *const p_signal,
const os_signal_num_e sig_num,
const os_delta_ticks_t period_ticks);

ATTR_WARN_UNUSED_RESULT
ATTR_NONNULL(1)
ATTR_RETURNS_NONNULL
os_timer_sig_one_shot_t *
os_timer_sig_one_shot_create_static(
os_timer_sig_one_shot_static_t *const p_timer_sig_mem,
Expand All @@ -79,9 +88,11 @@ os_timer_sig_one_shot_create_static(
const os_signal_num_e sig_num,
const os_delta_ticks_t period_ticks);

ATTR_NONNULL(1)
void
os_timer_sig_periodic_delete(os_timer_sig_periodic_t **const pp_obj);

ATTR_NONNULL(1)
void
os_timer_sig_one_shot_delete(os_timer_sig_one_shot_t **const pp_obj);

Expand Down
2 changes: 2 additions & 0 deletions include/str_buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ str_buf_init_with_alloc(str_buf_t *const p_str_buf);
* @return length of string.
*/
ATTR_NONNULL(1)
ATTR_PURE
str_buf_size_t
str_buf_get_len(const str_buf_t *const p_str_buf);

Expand All @@ -75,6 +76,7 @@ str_buf_get_len(const str_buf_t *const p_str_buf);
* @return true if buffer overflow occurred.
*/
ATTR_NONNULL(1)
ATTR_PURE
bool
str_buf_is_overflow(const str_buf_t *const p_str_buf);

Expand Down
3 changes: 3 additions & 0 deletions include/time_units.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define RUUVI_TIME_UNITS_H

#include <stdint.h>
#include "attribs.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -25,12 +26,14 @@ typedef uint32_t TimeUnitsSeconds_t;
typedef uint32_t TimeUnitsMilliSeconds_t;
typedef uint64_t TimeUnitsMicroSeconds_t;

ATTR_CONST
static inline TimeUnitsMilliSeconds_t
time_units_conv_seconds_to_ms(const TimeUnitsSeconds_t num_seconds)
{
return num_seconds * TIME_UNITS_MS_PER_SECOND;
}

ATTR_CONST
static inline TimeUnitsMicroSeconds_t
time_units_conv_ms_to_us(const TimeUnitsMilliSeconds_t num_ms)
{
Expand Down
Loading

0 comments on commit 1784a70

Please sign in to comment.