From 8bb85aecdac3cdb4fa3f09c6e053d4b99c29e04a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 18 Feb 2022 13:25:13 +0100 Subject: core: add NM_SHUTDOWN_TIMEOUT_1500_MSEC macro When you have an async operation, you must make sure that it is cancellable or completes in at most NM_SHUTDOWN_TIMEOUT_MAX_MSEC. But NM_SHUTDOWN_TIMEOUT_MAX_MSEC leaves it undefined how long it is. If you really want to wait for 1500msec, but also need to ensure to stay within NM_SHUTDOWN_TIMEOUT_MAX_MSEC, then use NM_SHUTDOWN_TIMEOUT_1500_MSEC. This has the semantic of guaranteeing both. --- src/core/NetworkManagerUtils.c | 4 ++++ src/core/NetworkManagerUtils.h | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/core/NetworkManagerUtils.c b/src/core/NetworkManagerUtils.c index c4df566eab..2f30bcaa39 100644 --- a/src/core/NetworkManagerUtils.c +++ b/src/core/NetworkManagerUtils.c @@ -34,6 +34,10 @@ /*****************************************************************************/ +G_STATIC_ASSERT(NM_SHUTDOWN_TIMEOUT_1500_MSEC <= NM_SHUTDOWN_TIMEOUT_MAX_MSEC); + +/*****************************************************************************/ + /** * nm_utils_get_shared_wifi_permission: * @connection: the NMConnection to lookup the permission. diff --git a/src/core/NetworkManagerUtils.h b/src/core/NetworkManagerUtils.h index 465f19b80f..fce940073b 100644 --- a/src/core/NetworkManagerUtils.h +++ b/src/core/NetworkManagerUtils.h @@ -121,6 +121,17 @@ NMPlatformRoutingRule *nm_ip_routing_rule_to_platform(const NMIPRoutingRule *rul #define NM_SHUTDOWN_TIMEOUT_MAX_MSEC 1500 #define NM_SHUTDOWN_TIMEOUT_ADDITIONAL_MSEC 500 +/** + * NM_SHUTDOWN_TIMEOUT_1500_MSEC: this is just 1500 msec. The special + * thing about the define is that you are guaranteed that this is not + * longer than NM_SHUTDOWN_TIMEOUT_MAX_MSEC. + * When you perform an async operation, it must either be cancellable + * (and complete fast) or never take longer than NM_SHUTDOWN_TIMEOUT_MAX_MSEC. + * The usage of this macro makes that relation to NM_SHUTDOWN_TIMEOUT_MAX_MSEC + * explicit. + */ +#define NM_SHUTDOWN_TIMEOUT_1500_MSEC 1500 + typedef enum { /* There is no watched_obj argument, and the shutdown is delayed until the user * explicitly calls unregister on the returned handle. */ -- cgit v1.2.1