From ecdff659d1696fbd972ff78744453fc82f9470f7 Mon Sep 17 00:00:00 2001 From: hujun5 Date: Thu, 19 Dec 2024 19:57:12 +0800 Subject: [PATCH] modifyreg[8|32]: use small lock in modifyreg[8|32] reason: We would like to replace the big lock with a small lock. Signed-off-by: hujun5 --- arch/arm/src/common/arm_modifyreg32.c | 10 ++++++++-- arch/arm/src/common/arm_modifyreg8.c | 10 ++++++++-- arch/arm64/src/common/arm64_modifyreg32.c | 10 ++++++++-- arch/arm64/src/common/arm64_modifyreg8.c | 10 ++++++++-- arch/avr/src/common/avr_modifyreg32.c | 7 +++++-- arch/avr/src/common/avr_modifyreg8.c | 7 +++++-- arch/ceva/src/common/ceva_modifyreg32.c | 10 ++++++++-- arch/ceva/src/common/ceva_modifyreg8.c | 10 ++++++++-- arch/hc/src/common/hc_modifyreg32.c | 7 +++++-- arch/hc/src/common/hc_modifyreg8.c | 7 +++++-- arch/mips/src/common/mips_modifyreg32.c | 7 +++++-- arch/mips/src/common/mips_modifyreg8.c | 7 +++++-- arch/misoc/src/common/misoc_modifyreg32.c | 11 +++++++++-- arch/misoc/src/common/misoc_modifyreg8.c | 11 +++++++++-- arch/or1k/src/common/or1k_modifyreg32.c | 10 ++++++++-- arch/or1k/src/common/or1k_modifyreg8.c | 10 ++++++++-- arch/risc-v/src/common/riscv_modifyreg32.c | 10 ++++++++-- arch/sparc/src/common/sparc_modifyreg32.c | 6 ++++-- arch/sparc/src/common/sparc_modifyreg8.c | 6 ++++-- arch/x86/src/common/x86_modifyreg32.c | 7 +++++-- arch/x86/src/common/x86_modifyreg8.c | 7 +++++-- arch/x86_64/src/common/x86_64_modifyreg32.c | 7 +++++-- arch/x86_64/src/common/x86_64_modifyreg8.c | 7 +++++-- arch/xtensa/src/common/xtensa_modifyreg32.c | 10 ++++++++-- arch/xtensa/src/common/xtensa_modifyreg8.c | 10 ++++++++-- arch/z80/src/z180/z180_modifiyreg8.c | 7 +++++-- 26 files changed, 169 insertions(+), 52 deletions(-) diff --git a/arch/arm/src/common/arm_modifyreg32.c b/arch/arm/src/common/arm_modifyreg32.c index b98bdc3ae3..ccc7d75829 100644 --- a/arch/arm/src/common/arm_modifyreg32.c +++ b/arch/arm/src/common/arm_modifyreg32.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 modifyreg32(unsigned int addr, uint32_t clearbits, uint32_t setbits) irqstate_t flags; uint32_t regval; - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg32(addr); regval &= ~clearbits; regval |= setbits; putreg32(regval, addr); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/arm/src/common/arm_modifyreg8.c b/arch/arm/src/common/arm_modifyreg8.c index a344995117..0e40bc1b5f 100644 --- a/arch/arm/src/common/arm_modifyreg8.c +++ b/arch/arm/src/common/arm_modifyreg8.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 modifyreg8(unsigned int addr, uint8_t clearbits, uint8_t setbits) irqstate_t flags; uint8_t regval; - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg8(addr); regval &= ~clearbits; regval |= setbits; putreg8(regval, addr); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/arm64/src/common/arm64_modifyreg32.c b/arch/arm64/src/common/arm64_modifyreg32.c index 1dd9008c01..25e5405fea 100644 --- a/arch/arm64/src/common/arm64_modifyreg32.c +++ b/arch/arm64/src/common/arm64_modifyreg32.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 modifyreg32(unsigned int addr, uint32_t clearbits, uint32_t setbits) irqstate_t flags; uint32_t regval; - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg32(addr); regval &= ~clearbits; regval |= setbits; putreg32(regval, addr); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/arm64/src/common/arm64_modifyreg8.c b/arch/arm64/src/common/arm64_modifyreg8.c index 7ab314b3e3..900d6f2af9 100644 --- a/arch/arm64/src/common/arm64_modifyreg8.c +++ b/arch/arm64/src/common/arm64_modifyreg8.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 modifyreg8(unsigned int addr, uint8_t clearbits, uint8_t setbits) irqstate_t flags; uint8_t regval; - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg8(addr); regval &= ~clearbits; regval |= setbits; putreg8(regval, addr); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/avr/src/common/avr_modifyreg32.c b/arch/avr/src/common/avr_modifyreg32.c index a4733773b9..1dd4666639 100644 --- a/arch/avr/src/common/avr_modifyreg32.c +++ b/arch/avr/src/common/avr_modifyreg32.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 modifyreg32(unsigned int addr, uint32_t clearbits, uint32_t setbits) irqstate_t flags; uint32_t regval; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg32(addr); regval &= ~clearbits; regval |= setbits; putreg32(regval, addr); - leave_critical_section(flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/avr/src/common/avr_modifyreg8.c b/arch/avr/src/common/avr_modifyreg8.c index 7419750c03..59bb0fbd79 100644 --- a/arch/avr/src/common/avr_modifyreg8.c +++ b/arch/avr/src/common/avr_modifyreg8.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 modifyreg8(unsigned int addr, uint8_t clearbits, uint8_t setbits) irqstate_t flags; uint8_t regval; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg8(addr); regval &= ~clearbits; regval |= setbits; putreg8(regval, addr); - leave_critical_section(flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/ceva/src/common/ceva_modifyreg32.c b/arch/ceva/src/common/ceva_modifyreg32.c index af64f365f4..5fd84ad3e0 100644 --- a/arch/ceva/src/common/ceva_modifyreg32.c +++ b/arch/ceva/src/common/ceva_modifyreg32.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 modifyreg32(unsigned int addr, uint32_t clearbits, uint32_t setbits) irqstate_t flags; uint32_t regval; - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg32(addr); regval &= ~clearbits; regval |= setbits; putreg32(regval, addr); - spin_unlock_irqrestore(flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/ceva/src/common/ceva_modifyreg8.c b/arch/ceva/src/common/ceva_modifyreg8.c index c0c1c78beb..b91ca92fe2 100644 --- a/arch/ceva/src/common/ceva_modifyreg8.c +++ b/arch/ceva/src/common/ceva_modifyreg8.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 modifyreg8(unsigned int addr, uint8_t clearbits, uint8_t setbits) irqstate_t flags; uint8_t regval; - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg8(addr); regval &= ~clearbits; regval |= setbits; putreg8(regval, addr); - spin_unlock_irqrestore(flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/hc/src/common/hc_modifyreg32.c b/arch/hc/src/common/hc_modifyreg32.c index b10296f720..0ac164a31d 100644 --- a/arch/hc/src/common/hc_modifyreg32.c +++ b/arch/hc/src/common/hc_modifyreg32.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 modifyreg32(unsigned int addr, uint32_t clearbits, uint32_t setbits) irqstate_t flags; uint32_t regval; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg32(addr); regval &= ~clearbits; regval |= setbits; putreg32(regval, addr); - leave_critical_section(flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/hc/src/common/hc_modifyreg8.c b/arch/hc/src/common/hc_modifyreg8.c index 05e08e9f1e..e18263c8eb 100644 --- a/arch/hc/src/common/hc_modifyreg8.c +++ b/arch/hc/src/common/hc_modifyreg8.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 modifyreg8(unsigned int addr, uint8_t clearbits, uint8_t setbits) irqstate_t flags; uint8_t regval; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg8(addr); regval &= ~clearbits; regval |= setbits; putreg8(regval, addr); - leave_critical_section(flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/mips/src/common/mips_modifyreg32.c b/arch/mips/src/common/mips_modifyreg32.c index a6ea0c1c21..59364f48ff 100644 --- a/arch/mips/src/common/mips_modifyreg32.c +++ b/arch/mips/src/common/mips_modifyreg32.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 modifyreg32(unsigned int addr, uint32_t clearbits, uint32_t setbits) irqstate_t flags; uint32_t regval; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg32(addr); regval &= ~clearbits; regval |= setbits; putreg32(regval, addr); - leave_critical_section(flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/mips/src/common/mips_modifyreg8.c b/arch/mips/src/common/mips_modifyreg8.c index 43884a583c..fac89d1776 100644 --- a/arch/mips/src/common/mips_modifyreg8.c +++ b/arch/mips/src/common/mips_modifyreg8.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 modifyreg8(unsigned int addr, uint8_t clearbits, uint8_t setbits) irqstate_t flags; uint8_t regval; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg8(addr); regval &= ~clearbits; regval |= setbits; putreg8(regval, addr); - leave_critical_section(flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/misoc/src/common/misoc_modifyreg32.c b/arch/misoc/src/common/misoc_modifyreg32.c index 2a5d372efc..6d02b36367 100644 --- a/arch/misoc/src/common/misoc_modifyreg32.c +++ b/arch/misoc/src/common/misoc_modifyreg32.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 modifyreg32(unsigned int addr, uint32_t clearbits, uint32_t setbits) irqstate_t flags; uint32_t regval; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg32(addr); regval &= ~clearbits; regval |= setbits; putreg32(regval, addr); - leave_critical_section(flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/misoc/src/common/misoc_modifyreg8.c b/arch/misoc/src/common/misoc_modifyreg8.c index 7eda3878d9..207d8fe0dc 100644 --- a/arch/misoc/src/common/misoc_modifyreg8.c +++ b/arch/misoc/src/common/misoc_modifyreg8.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 modifyreg8(unsigned int addr, uint8_t clearbits, uint8_t setbits) irqstate_t flags; uint8_t regval; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg8(addr); regval &= ~clearbits; regval |= setbits; putreg8(regval, addr); - leave_critical_section(flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/or1k/src/common/or1k_modifyreg32.c b/arch/or1k/src/common/or1k_modifyreg32.c index c079d32323..7e56c0d308 100644 --- a/arch/or1k/src/common/or1k_modifyreg32.c +++ b/arch/or1k/src/common/or1k_modifyreg32.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 modifyreg32(unsigned int addr, uint32_t clearbits, uint32_t setbits) irqstate_t flags; uint32_t regval; - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg32(addr); regval &= ~clearbits; regval |= setbits; putreg32(regval, addr); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/or1k/src/common/or1k_modifyreg8.c b/arch/or1k/src/common/or1k_modifyreg8.c index c378b542a0..32783b168c 100644 --- a/arch/or1k/src/common/or1k_modifyreg8.c +++ b/arch/or1k/src/common/or1k_modifyreg8.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 modifyreg8(unsigned int addr, uint8_t clearbits, uint8_t setbits) irqstate_t flags; uint8_t regval; - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg8(addr); regval &= ~clearbits; regval |= setbits; putreg8(regval, addr); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/risc-v/src/common/riscv_modifyreg32.c b/arch/risc-v/src/common/riscv_modifyreg32.c index 478351764e..93b5d27712 100644 --- a/arch/risc-v/src/common/riscv_modifyreg32.c +++ b/arch/risc-v/src/common/riscv_modifyreg32.c @@ -33,6 +33,12 @@ #include "riscv_internal.h" +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static spinlock_t g_modifyreg_lock = SP_UNLOCKED; + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -50,10 +56,10 @@ void modifyreg32(uintreg_t addr, uint32_t clearbits, uint32_t setbits) irqstate_t flags; uint32_t regval; - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg32(addr); regval &= ~clearbits; regval |= setbits; putreg32(regval, addr); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/sparc/src/common/sparc_modifyreg32.c b/arch/sparc/src/common/sparc_modifyreg32.c index 899d06670e..9e42428cd8 100644 --- a/arch/sparc/src/common/sparc_modifyreg32.c +++ b/arch/sparc/src/common/sparc_modifyreg32.c @@ -42,6 +42,8 @@ * Private Data ****************************************************************************/ +static spinlock_t g_modifyreg_lock = SP_UNLOCKED; + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -63,11 +65,11 @@ void modifyreg32(unsigned int addr, uint32_t clearbits, uint32_t setbits) irqstate_t flags; uint32_t regval; - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg32(addr); regval &= ~clearbits; regval |= setbits; putreg32(regval, addr); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/sparc/src/common/sparc_modifyreg8.c b/arch/sparc/src/common/sparc_modifyreg8.c index 3b5d6b3695..a91cd271f8 100644 --- a/arch/sparc/src/common/sparc_modifyreg8.c +++ b/arch/sparc/src/common/sparc_modifyreg8.c @@ -42,6 +42,8 @@ * Private Data ****************************************************************************/ +static spinlock_t g_modifyreg_lock = SP_UNLOCKED; + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -63,11 +65,11 @@ void modifyreg8(unsigned int addr, uint8_t clearbits, uint8_t setbits) irqstate_t flags; uint8_t regval; - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg8(addr); regval &= ~clearbits; regval |= setbits; putreg8(regval, addr); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/x86/src/common/x86_modifyreg32.c b/arch/x86/src/common/x86_modifyreg32.c index 2f4f30935c..8b4b61d5a3 100644 --- a/arch/x86/src/common/x86_modifyreg32.c +++ b/arch/x86/src/common/x86_modifyreg32.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 modifyreg32(unsigned int addr, uint32_t clearbits, uint32_t setbits) irqstate_t flags; uint32_t regval; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg32((uint16_t)addr); regval &= ~clearbits; regval |= setbits; putreg32(regval, (uint16_t)addr); - leave_critical_section(flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/x86/src/common/x86_modifyreg8.c b/arch/x86/src/common/x86_modifyreg8.c index 03d1169fed..2145e72e29 100644 --- a/arch/x86/src/common/x86_modifyreg8.c +++ b/arch/x86/src/common/x86_modifyreg8.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 modifyreg8(unsigned int addr, uint8_t clearbits, uint8_t setbits) irqstate_t flags; uint8_t regval; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg8((uint16_t)addr); regval &= ~clearbits; regval |= setbits; putreg8(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_modifyreg32.c b/arch/x86_64/src/common/x86_64_modifyreg32.c index 44427620f1..c1e182a7e5 100644 --- a/arch/x86_64/src/common/x86_64_modifyreg32.c +++ b/arch/x86_64/src/common/x86_64_modifyreg32.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 modifyreg32(unsigned int addr, uint32_t clearbits, uint32_t setbits) irqstate_t flags; uint32_t regval; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg32((uint16_t)addr); regval &= ~clearbits; regval |= setbits; putreg32(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_modifyreg8.c b/arch/x86_64/src/common/x86_64_modifyreg8.c index 9593752ac6..0970eb3f6e 100644 --- a/arch/x86_64/src/common/x86_64_modifyreg8.c +++ b/arch/x86_64/src/common/x86_64_modifyreg8.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 modifyreg8(unsigned int addr, uint8_t clearbits, uint8_t setbits) irqstate_t flags; uint8_t regval; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg8((uint16_t)addr); regval &= ~clearbits; regval |= setbits; putreg8(regval, (uint16_t)addr); - leave_critical_section(flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/xtensa/src/common/xtensa_modifyreg32.c b/arch/xtensa/src/common/xtensa_modifyreg32.c index 11028c1c53..6ad6b235fe 100644 --- a/arch/xtensa/src/common/xtensa_modifyreg32.c +++ b/arch/xtensa/src/common/xtensa_modifyreg32.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 modifyreg32(unsigned int addr, uint32_t clearbits, uint32_t setbits) irqstate_t flags; uint32_t regval; - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg32(addr); regval &= ~clearbits; regval |= setbits; putreg32(regval, addr); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/xtensa/src/common/xtensa_modifyreg8.c b/arch/xtensa/src/common/xtensa_modifyreg8.c index 79de967099..dd9c0c1df9 100644 --- a/arch/xtensa/src/common/xtensa_modifyreg8.c +++ b/arch/xtensa/src/common/xtensa_modifyreg8.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 modifyreg8(unsigned int addr, uint8_t clearbits, uint8_t setbits) irqstate_t flags; uint8_t regval; - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = getreg8(addr); regval &= ~clearbits; regval |= setbits; putreg8(regval, addr); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); } diff --git a/arch/z80/src/z180/z180_modifiyreg8.c b/arch/z80/src/z180/z180_modifiyreg8.c index 282e659213..35a4ca63e7 100644 --- a/arch/z80/src/z180/z180_modifiyreg8.c +++ b/arch/z80/src/z180/z180_modifiyreg8.c @@ -29,6 +29,7 @@ #include #include +#include #include /**************************************************************************** @@ -39,6 +40,8 @@ * Private Data ****************************************************************************/ +static spinlock_t g_modifyreg_lock = SP_UNLOCKED; + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -60,10 +63,10 @@ void modifyreg8(uint16_t addr, uint8_t clearbits, uint8_t setbits) irqstate_t flags; uint8_t regval; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_modifyreg_lock); regval = inp(addr); regval &= ~clearbits; regval |= setbits; outp(regval, addr); - leave_critical_section(flags); + spin_unlock_irqrestore(&g_modifyreg_lock, flags); }