diff options
author | Thomas Haller <thaller@redhat.com> | 2020-08-21 13:33:35 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-08-21 13:59:48 +0200 |
commit | 195b406ac0df36a061682656c562bf8544993fd2 (patch) | |
tree | ae3c67ac61111013201055ba247a2c6519e5467a /src | |
parent | e59259b3d5016646a1b63da5e2371902389367b4 (diff) | |
download | NetworkManager-195b406ac0df36a061682656c562bf8544993fd2.tar.gz |
platform: extend nm_platform_kernel_support_get() and use atomic operations to access result
Add nm_platform_kernel_support_get_full() to allow fetching the support
state without setting it to the compile time default.
Also, use g_atomic_int_get() to access _nm_platform_kernel_support_state
values. We should not access static variables without synchronization.
Better get it correct in any case than fast.
Diffstat (limited to 'src')
-rw-r--r-- | src/platform/nm-platform.h | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index f089a72783..8c9abb631a 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -986,23 +986,33 @@ _nm_platform_kernel_support_detected (NMPlatformKernelSupportType type) nm_assert ( _NM_INT_NOT_NEGATIVE (type) && type < G_N_ELEMENTS (_nm_platform_kernel_support_state)); - return G_LIKELY (_nm_platform_kernel_support_state[type] != 0); + return G_LIKELY (g_atomic_int_get (&_nm_platform_kernel_support_state[type]) != 0); } -static inline gboolean -nm_platform_kernel_support_get (NMPlatformKernelSupportType type) +static inline NMTernary +nm_platform_kernel_support_get_full (NMPlatformKernelSupportType type, + gboolean init_if_not_set) { int v; - nm_assert (_NM_INT_NOT_NEGATIVE (type) + nm_assert ( _NM_INT_NOT_NEGATIVE (type) && type < G_N_ELEMENTS (_nm_platform_kernel_support_state)); - v = _nm_platform_kernel_support_state[type]; - if (G_UNLIKELY (v == 0)) + v = g_atomic_int_get (&_nm_platform_kernel_support_state[type]); + if (G_UNLIKELY (v == 0)) { + if (!init_if_not_set) + return NM_TERNARY_DEFAULT; v = _nm_platform_kernel_support_init (type, 0); + } return (v >= 0); } +static inline gboolean +nm_platform_kernel_support_get (NMPlatformKernelSupportType type) +{ + return nm_platform_kernel_support_get_full (type, TRUE) != NM_TERNARY_FALSE; +} + /*****************************************************************************/ struct _NMPlatformPrivate; |