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.
This commit is contained in:
Thomas Haller 2020-08-21 13:33:35 +02:00
parent e59259b3d5
commit 195b406ac0
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -986,21 +986,31 @@ _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 NMTernary
nm_platform_kernel_support_get_full (NMPlatformKernelSupportType type,
gboolean init_if_not_set)
{
int v;
nm_assert ( _NM_INT_NOT_NEGATIVE (type)
&& type < G_N_ELEMENTS (_nm_platform_kernel_support_state));
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)
{
int v;
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 = _nm_platform_kernel_support_init (type, 0);
return (v >= 0);
return nm_platform_kernel_support_get_full (type, TRUE) != NM_TERNARY_FALSE;
}
/*****************************************************************************/