From 15c80e68a0d2d35eb9109de80ee78f3eb9fcd366 Mon Sep 17 00:00:00 2001 From: hujun5 Date: Wed, 18 Dec 2024 16:08:01 +0800 Subject: [PATCH] modifyreg16: use small lock in modifyreg16 reason: We would like to replace the big lock with a small lock. Signed-off-by: hujun5 --- arch/arm/src/common/arm_modifyreg16.c | 10 ++++++++-- arch/arm64/src/common/arm64_modifyreg16.c | 10 ++++++++-- arch/avr/src/common/avr_modifyreg16.c | 7 +++++-- arch/ceva/src/common/ceva_modifyreg16.c | 10 ++++++++-- arch/hc/src/common/hc_modifyreg16.c | 7 +++++-- arch/mips/src/common/mips_modifyreg16.c | 7 +++++-- arch/misoc/src/common/misoc_modifyreg16.c | 11 +++++++++-- arch/or1k/src/common/or1k_modifyreg16.c | 10 ++++++++-- arch/sparc/src/common/sparc_modifyreg16.c | 6 ++++-- arch/x86/src/common/x86_modifyreg16.c | 7 +++++-- arch/x86_64/src/common/x86_64_modifyreg16.c | 7 +++++-- arch/xtensa/src/common/xtensa_modifyreg16.c | 10 ++++++++-- 12 files changed, 78 insertions(+), 24 deletions(-) diff --git a/arch/arm/src/common/arm_modifyreg16.c b/arch/arm/src/common/arm_modifyreg16.c index 13cc740ad6..53f536f164 100644 --- a/arch/arm/src/common/arm_modifyreg16.c +++ b/arch/arm/src/common/arm_modifyreg16.c @@ -33,6 +33,12 @@ #include "arm_internal.h" +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static spinlock_t g_modifyreg_lock = SP_UNLOCKED; + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -50,10 +56,10 @@ void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits) irqstate_t flags; uint16_t regval; - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg16(addr); regval &= ~clearbits; regval |= setbits; putreg16(regval, addr); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/arm64/src/common/arm64_modifyreg16.c b/arch/arm64/src/common/arm64_modifyreg16.c index e1e6ba8da1..914f7dd714 100644 --- a/arch/arm64/src/common/arm64_modifyreg16.c +++ b/arch/arm64/src/common/arm64_modifyreg16.c @@ -33,6 +33,12 @@ #include "arm64_internal.h" +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static spinlock_t g_modifyreg_lock = SP_UNLOCKED; + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -50,10 +56,10 @@ void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits) irqstate_t flags; uint16_t regval; - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg16(addr); regval &= ~clearbits; regval |= setbits; putreg16(regval, addr); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/avr/src/common/avr_modifyreg16.c b/arch/avr/src/common/avr_modifyreg16.c index 0d90d2c676..9102570f1d 100644 --- a/arch/avr/src/common/avr_modifyreg16.c +++ b/arch/avr/src/common/avr_modifyreg16.c @@ -31,6 +31,7 @@ #include #include +#include #include "avr_internal.h" @@ -42,6 +43,8 @@ * Private Data ****************************************************************************/ +static spinlock_t g_modifyreg_lock = SP_UNLOCKED; + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -63,10 +66,10 @@ void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits) irqstate_t flags; uint16_t regval; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg16(addr); regval &= ~clearbits; regval |= setbits; putreg16(regval, addr); - leave_critical_section(flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/ceva/src/common/ceva_modifyreg16.c b/arch/ceva/src/common/ceva_modifyreg16.c index 96baed1dad..dc6a55e5bf 100644 --- a/arch/ceva/src/common/ceva_modifyreg16.c +++ b/arch/ceva/src/common/ceva_modifyreg16.c @@ -29,6 +29,12 @@ #include "ceva_internal.h" +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static spinlock_t g_modifyreg_lock = SP_UNLOCKED; + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -46,10 +52,10 @@ void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits) irqstate_t flags; uint16_t regval; - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg16(addr); regval &= ~clearbits; regval |= setbits; putreg16(regval, addr); - spin_unlock_irqrestore(flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/hc/src/common/hc_modifyreg16.c b/arch/hc/src/common/hc_modifyreg16.c index 663409165d..44e5c2f439 100644 --- a/arch/hc/src/common/hc_modifyreg16.c +++ b/arch/hc/src/common/hc_modifyreg16.c @@ -31,6 +31,7 @@ #include #include +#include #include "hc_internal.h" @@ -42,6 +43,8 @@ * Private Data ****************************************************************************/ +static spinlock_t g_modifyreg_lock = SP_UNLOCKED; + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -63,10 +66,10 @@ void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits) irqstate_t flags; uint16_t regval; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg16(addr); regval &= ~clearbits; regval |= setbits; putreg16(regval, addr); - leave_critical_section(flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/mips/src/common/mips_modifyreg16.c b/arch/mips/src/common/mips_modifyreg16.c index 0371bfb147..42e79ec611 100644 --- a/arch/mips/src/common/mips_modifyreg16.c +++ b/arch/mips/src/common/mips_modifyreg16.c @@ -31,6 +31,7 @@ #include #include +#include #include "mips_internal.h" @@ -42,6 +43,8 @@ * Private Data ****************************************************************************/ +static spinlock_t g_modifyreg_lock = SP_UNLOCKED; + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -63,10 +66,10 @@ void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits) irqstate_t flags; uint16_t regval; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg16(addr); regval &= ~clearbits; regval |= setbits; putreg16(regval, addr); - leave_critical_section(flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/misoc/src/common/misoc_modifyreg16.c b/arch/misoc/src/common/misoc_modifyreg16.c index e368f94975..6e0ee0dd1c 100644 --- a/arch/misoc/src/common/misoc_modifyreg16.c +++ b/arch/misoc/src/common/misoc_modifyreg16.c @@ -31,9 +31,16 @@ #include #include +#include #include "misoc.h" +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static spinlock_t g_modifyreg_lock = SP_UNLOCKED; + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -51,10 +58,10 @@ void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits) irqstate_t flags; uint16_t regval; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg16(addr); regval &= ~clearbits; regval |= setbits; putreg16(regval, addr); - leave_critical_section(flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/or1k/src/common/or1k_modifyreg16.c b/arch/or1k/src/common/or1k_modifyreg16.c index 83421b675d..044999fbd8 100644 --- a/arch/or1k/src/common/or1k_modifyreg16.c +++ b/arch/or1k/src/common/or1k_modifyreg16.c @@ -33,6 +33,12 @@ #include "or1k_internal.h" +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static spinlock_t g_modifyreg_lock = SP_UNLOCKED; + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -50,10 +56,10 @@ void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits) irqstate_t flags; uint16_t regval; - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg16(addr); regval &= ~clearbits; regval |= setbits; putreg16(regval, addr); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/sparc/src/common/sparc_modifyreg16.c b/arch/sparc/src/common/sparc_modifyreg16.c index 271a8db346..a1e8b77232 100644 --- a/arch/sparc/src/common/sparc_modifyreg16.c +++ b/arch/sparc/src/common/sparc_modifyreg16.c @@ -42,6 +42,8 @@ * Private Data ****************************************************************************/ +static spinlock_t g_modifyreg_lock = SP_UNLOCKED; + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -63,11 +65,11 @@ void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits) irqstate_t flags; uint16_t regval; - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg16(addr); regval &= ~clearbits; regval |= setbits; putreg16(regval, addr); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/x86/src/common/x86_modifyreg16.c b/arch/x86/src/common/x86_modifyreg16.c index 89e43b6718..94491373d2 100644 --- a/arch/x86/src/common/x86_modifyreg16.c +++ b/arch/x86/src/common/x86_modifyreg16.c @@ -31,6 +31,7 @@ #include #include +#include #include "x86_internal.h" @@ -42,6 +43,8 @@ * Private Data ****************************************************************************/ +static spinlock_t g_modifyreg_lock = SP_UNLOCKED; + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -63,10 +66,10 @@ void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits) irqstate_t flags; uint16_t regval; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg16((uint16_t)addr); regval &= ~clearbits; regval |= setbits; putreg16(regval, (uint16_t)addr); - leave_critical_section(flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/x86_64/src/common/x86_64_modifyreg16.c b/arch/x86_64/src/common/x86_64_modifyreg16.c index e30355182a..e69412f72b 100644 --- a/arch/x86_64/src/common/x86_64_modifyreg16.c +++ b/arch/x86_64/src/common/x86_64_modifyreg16.c @@ -31,6 +31,7 @@ #include #include +#include #include "x86_64_internal.h" @@ -42,6 +43,8 @@ * Private Data ****************************************************************************/ +static spinlock_t g_modifyreg_lock = SP_UNLOCKED; + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -63,10 +66,10 @@ void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits) irqstate_t flags; uint16_t regval; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg16((uint16_t)addr); regval &= ~clearbits; regval |= setbits; putreg16(regval, (uint16_t)addr); - leave_critical_section(flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/xtensa/src/common/xtensa_modifyreg16.c b/arch/xtensa/src/common/xtensa_modifyreg16.c index 27d67bf9f0..60f907f637 100644 --- a/arch/xtensa/src/common/xtensa_modifyreg16.c +++ b/arch/xtensa/src/common/xtensa_modifyreg16.c @@ -35,6 +35,12 @@ #include "xtensa.h" +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static spinlock_t g_modifyreg_lock = SP_UNLOCKED; + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -52,10 +58,10 @@ void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits) irqstate_t flags; uint16_t regval; - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg16(addr); regval &= ~clearbits; regval |= setbits; putreg16(regval, addr); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); }