backoffAlgorithm v1.4.2
Algorithmic library for calculating retry intervals using exponential backoff and jitter.
 
Loading...
Searching...
No Matches
backoff_algorithm.h
Go to the documentation of this file.
1/*
2 * backoffAlgorithm
3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 *
5 * SPDX-License-Identifier: MIT
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 * this software and associated documentation files (the "Software"), to deal in
9 * the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 * the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
35#ifndef BACKOFF_ALGORITHM_H_
36#define BACKOFF_ALGORITHM_H_
37
38/* Standard include. */
39#include <stdint.h>
40
41/* *INDENT-OFF* */
42#ifdef __cplusplus
43 extern "C" {
44#endif
45/* *INDENT-ON* */
46
54#define BACKOFF_ALGORITHM_LIBRARY_VERSION "v1.4.2"
61#define BACKOFF_ALGORITHM_RETRY_FOREVER ( UINT32_MAX )
62
67typedef enum BackoffAlgorithmStatus
68{
72
78typedef struct BackoffAlgorithmContext
79{
84
89 uint32_t attemptsDone;
90
94 uint32_t nextJitterMax;
95
101
116/* @[define_backoffalgorithm_initializeparams] */
118 uint32_t backOffBase,
119 uint32_t maxBackOff,
120 uint32_t maxAttempts );
121/* @[define_backoffalgorithm_initializeparams] */
122
145/* @[define_backoffalgorithm_getnextbackoff] */
147 uint32_t randomValue,
148 uint32_t * pNextBackOff );
149/* @[define_backoffalgorithm_getnextbackoff] */
150
151/* *INDENT-OFF* */
152#ifdef __cplusplus
153 }
154#endif
155/* *INDENT-ON* */
156
157#endif /* ifndef BACKOFF_ALGORITHM_H_ */
BackoffAlgorithmStatus_t BackoffAlgorithm_GetNextBackoff(BackoffAlgorithmContext_t *pRetryContext, uint32_t randomValue, uint32_t *pNextBackOff)
Simple exponential backoff and jitter function that provides the delay value for the next retry attem...
Definition: backoff_algorithm.c:40
void BackoffAlgorithm_InitializeParams(BackoffAlgorithmContext_t *pContext, uint32_t backOffBase, uint32_t maxBackOff, uint32_t maxAttempts)
Initializes the context for using backoff algorithm. The parameters are required for calculating the ...
Definition: backoff_algorithm.c:86
BackoffAlgorithmStatus_t
Status for BackoffAlgorithm_GetNextBackoff.
Definition: backoff_algorithm.h:68
@ BackoffAlgorithmRetriesExhausted
The function exhausted all retry attempts.
Definition: backoff_algorithm.h:70
@ BackoffAlgorithmSuccess
The function successfully calculated the next back-off value.
Definition: backoff_algorithm.h:69
Represents parameters required for calculating the back-off delay for the next retry attempt.
Definition: backoff_algorithm.h:79
uint32_t nextJitterMax
The maximum backoff value (in milliseconds) for the next retry attempt.
Definition: backoff_algorithm.h:94
uint32_t maxRetryAttempts
The maximum number of retry attempts.
Definition: backoff_algorithm.h:99
uint32_t maxBackoffDelay
The maximum backoff delay (in milliseconds) between consecutive retry attempts.
Definition: backoff_algorithm.h:83
uint32_t attemptsDone
The total number of retry attempts completed. This value is incremented on every call to BackoffAlgor...
Definition: backoff_algorithm.h:89