CDI SDK
SDK for transporting chunks of data reliably and with low latency using a polled mode network driver.
Loading...
Searching...
No Matches
timeout.h
Go to the documentation of this file.
1// -------------------------------------------------------------------------------------------
2// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
3// This file is part of the AWS CDI-SDK, licensed under the BSD 2-Clause "Simplified" License.
4// License details at: https://github.com/aws/aws-cdi-sdk/blob/mainline/LICENSE
5// -------------------------------------------------------------------------------------------
6
13#ifndef CDI_TIMEOUT_H__
14#define CDI_TIMEOUT_H__
15
16#include <stdbool.h>
17
18#include "cdi_core_api.h"
19#include "cdi_logger_api.h"
20#include "cdi_os_api.h"
21#include "cdi_pool_api.h"
22#include "fifo_api.h"
23#include "list_api.h"
24
25//*********************************************************************************************************************
26//***************************************** START OF DEFINITIONS AND TYPES ********************************************
27//*********************************************************************************************************************
29#define MAX_TIMERS 25
31#define MAX_TIMERS_GROW 5
32
38typedef struct TimeoutDataState {
42 uint64_t deadline_us;
44 void* cb_ptr;
47 //struct TimeoutDataState* next_handle;
48 //struct TimeoutDataState* prev_handle;
50
55
82
83//*********************************************************************************************************************
84//******************************************* START OF PUBLIC FUNCTIONS ***********************************************
85//*********************************************************************************************************************
86
89
95
97typedef void (*CdiTimeoutCallback)(const CdiTimeoutCbData* data_ptr);
98
109
119
131bool CdiTimeoutAdd(CdiTimeoutInstanceHandle instance_handle, CdiTimeoutCallback cb_ptr, int timeout_us,
132 void* user_data_ptr, TimeoutHandle* ret_handle);
133
142bool CdiTimeoutRemove(TimeoutHandle handle, CdiTimeoutInstanceHandle instance_handle);
143
144#endif // CDI_TIMEOUT_H__
This file declares the public API data types, structures and functions that comprise the CDI low-leve...
CdiReturnStatus
Values used for API function return codes.
Definition cdi_core_api.h:189
The declarations in this header file correspond to the definitions in logger.c.
This file contains the declarations for OS functions for creating/managing/freeing threads,...
struct CdiSignalType_t * CdiSignalType
Define portable signal type. Don't use void* here, which prevents the compiler from type checking.
Definition cdi_os_api.h:189
pthread_mutex_t * CdiCsID
Define portable critical section.
Definition cdi_os_api.h:192
struct CdiThreadID_t * CdiThreadID
Define portable thread type. Separate name from type, otherwise the typedef that follows it will gene...
Definition cdi_os_api.h:312
This file declares the public API data types, structures and functions that comprise the CDI Pool Uti...
The declarations in this header file correspond to the definitions in fifo.c.
The declarations in this header file correspond to the definitions in list.c. Many of the functions h...
Structure used to hold state data for a single FIFO.
Definition fifo.c:32
This structure represents a single list entry.
Definition list_api.h:34
This structure represents a list.
Definition list_api.h:42
Structure used to hold state data for a single log of any type (stdout, callback or file).
Definition logger.c:79
This structure represents the current state of a memory pool.
Definition pool.c:46
Structure for Callback functions to use to return data from callback.
Definition timeout.h:91
void * user_data_ptr
Pointer to data space for this handle.
Definition timeout.h:93
TimeoutHandle handle
Handle for timeout data state.
Definition timeout.h:92
TimeoutDataState is the basic object used to build the list of timers This object contains a timeout,...
Definition timeout.h:38
void * user_data_ptr
pointer to user data that can be used in callback function
Definition timeout.h:46
CdiListEntry list_entry
store an instance of this object in a list ordered by deadline_us values
Definition timeout.h:40
uint64_t deadline_us
when will this object expire in microseconds
Definition timeout.h:42
void * cb_ptr
pointer to callback function to execute if this item expires
Definition timeout.h:44
This structure contains all of the state information for the timer instance. This includes signals,...
Definition timeout.h:60
CdiSignalType stop_signal
stop_signal indicates someone has removed active timeout or added a timeout with a closer deadline
Definition timeout.h:72
CdiSignalType go_signal
go_signal indicates that there is at least one active timer entry
Definition timeout.h:68
CdiPoolHandle mem_pool_handle
Pool of available TimeoutDataState objects.
Definition timeout.h:76
CdiThreadID cb_thread_id
Thread ID for the thread that executes the callback functions.
Definition timeout.h:64
CdiCsID critical_section
Critical section to indicate that timeout_list is being modified.
Definition timeout.h:78
CdiLogHandle log_handle
Handle of log to use for this timeout's main thread.
Definition timeout.h:80
CdiSignalType shutdown_signal
shutdown timer instance signaled from CdiTimeoutDestroy
Definition timeout.h:70
CdiThreadID main_thread_id
Thread ID for the main timeout management thread.
Definition timeout.h:62
CdiList timeout_list
list of active timeout objects
Definition timeout.h:74
CdiFifoHandle cb_fifo_handle
handle for the FIFO that main thread puts callbacks into for callback thread to execute
Definition timeout.h:66
struct TimeoutDataState * TimeoutHandle
This is the handle for TimeoutDataState.
Definition timeout.h:54
bool CdiTimeoutAdd(CdiTimeoutInstanceHandle instance_handle, CdiTimeoutCallback cb_ptr, int timeout_us, void *user_data_ptr, TimeoutHandle *ret_handle)
Adds a timeout to the active timeout list and puts the timeout in order based on when the timeout occ...
Definition timeout.c:305
struct TimeoutInstanceState TimeoutInstanceState
This structure contains all of the state information for the timer instance. This includes signals,...
void(* CdiTimeoutCallback)(const CdiTimeoutCbData *data_ptr)
Callback function definition used by CdiTimeoutAdd.
Definition timeout.h:97
CdiReturnStatus CdiTimeoutCreate(CdiLogHandle log_handle, CdiTimeoutInstanceHandle *ret_handle)
Creates a TimeoutInstanceState structure memory allocated for a pool of TimeoutDataState structures a...
Definition timeout.c:196
void CdiTimeoutDestroy(CdiTimeoutInstanceHandle handle)
Destroys a TimeoutInstanceState structure freeing associated mememory and other resources such as wak...
Definition timeout.c:283
struct TimeoutInstanceState * CdiTimeoutInstanceHandle
a handle for use with TimeoutInstanceState structure
Definition timeout.h:88
bool CdiTimeoutRemove(TimeoutHandle handle, CdiTimeoutInstanceHandle instance_handle)
Removes a timeout from the timeout list thread, generally upon completion of operation.
Definition timeout.c:364
struct TimeoutDataState TimeoutDataState
TimeoutDataState is the basic object used to build the list of timers This object contains a timeout,...