mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-06 03:50:17 +01:00
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:
parent
e59259b3d5
commit
195b406ac0
1 changed files with 20 additions and 10 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue