// ------------------------------------------------------------------------------------------- // Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. // This file is part of the AWS CDI-SDK, licensed under the BSD 2-Clause "Simplified" License. // License details at: https://github.com/aws/aws-cdi-sdk/blob/mainline/LICENSE // ------------------------------------------------------------------------------------------- /** * @file * @brief * The declarations in this header file correspond to the definitions in timeout.c */ #ifndef CDI_TIMEOUT_H__ #define CDI_TIMEOUT_H__ #include #include "cdi_core_api.h" #include "cdi_logger_api.h" #include "cdi_os_api.h" #include "cdi_pool_api.h" #include "fifo_api.h" #include "list_api.h" //********************************************************************************************************************* //***************************************** START OF DEFINITIONS AND TYPES ******************************************** //********************************************************************************************************************* /// Maximum number of timers per timeout instance #define MAX_TIMERS 25 /// Number of timers that may be added when increasing memory pool if needed. #define MAX_TIMERS_GROW 5 /** * @brief TimeoutDataState is the basic object used to build the list of timers * This object contains a timeout, a next and previous handle, and user data * pointer, and a user data callback function pointer */ typedef struct TimeoutDataState { /// store an instance of this object in a list ordered by deadline_us values CdiListEntry list_entry; /// when will this object expire in microseconds uint64_t deadline_us; /// pointer to callback function to execute if this item expires void* cb_ptr; /// pointer to user data that can be used in callback function void* user_data_ptr; //struct TimeoutDataState* next_handle; //struct TimeoutDataState* prev_handle; } TimeoutDataState; /** * @brief This is the handle for TimeoutDataState */ typedef struct TimeoutDataState* TimeoutHandle; /** @brief This structure contains all of the state information for the timer * instance. This includes signals, thread ID's, and pointers to the memory * pool and timer list */ typedef struct TimeoutInstanceState { /// Thread ID for the main timeout management thread CdiThreadID main_thread_id; /// Thread ID for the thread that executes the callback functions CdiThreadID cb_thread_id; /// handle for the FIFO that main thread puts callbacks into for callback thread to execute CdiFifoHandle cb_fifo_handle; /// go_signal indicates that there is at least one active timer entry CdiSignalType go_signal; /// shutdown timer instance signaled from CdiTimeoutDestroy CdiSignalType shutdown_signal; /// stop_signal indicates someone has removed active timeout or added a timeout with a closer deadline CdiSignalType stop_signal; /// list of active timeout objects CdiList timeout_list; /// Pool of available TimeoutDataState objects CdiPoolHandle mem_pool_handle; /// Critical section to indicate that timeout_list is being modified CdiCsID critical_section; /// Handle of log to use for this timeout's main thread. CdiLogHandle log_handle; } TimeoutInstanceState; //********************************************************************************************************************* //******************************************* START OF PUBLIC FUNCTIONS *********************************************** //********************************************************************************************************************* /// @brief a handle for use with TimeoutInstanceState structure typedef struct TimeoutInstanceState* CdiTimeoutInstanceHandle; /// @brief Structure for Callback functions to use to return data from callback typedef struct { TimeoutHandle handle; ///