简体   繁体   English

在linux中,如何确保执行一系列代码而不会中断

[英]In linux, how to make sure a sequence of code is executed without any interruption

I have a routine that toggles the GPIO pin high/low, and have delay between the highs and lows (using udelay ), and then samples the GPIO state for some period. 我有一个程序可以将GPIO引脚切换为高电平/低电平,并在高电平和低电平之间有延迟(使用udelay ),然后对GPIO状态进行一段时间的采样。 I need to make sure this part of the code is executed without being pre-empted by the scheduler or by any possible interrupts. 我需要确保执行代码的这一部分而不会被调度程序或任何可能的中断抢占。 I am running the code on a dual core ARM system so it should be SMP. 我在双核ARM系统上运行代码,所以它应该是SMP。 Is Spin_Lock_IrqSave() safe enough for such purpose? Spin_Lock_IrqSave()是否足够安全用于此目的? I got a feeling my code is still somehow being interrupted occasionally but no proof yet. 我感觉我的代码仍然偶尔会被打断,但还没有证据。

Thanks a lot. 非常感谢。

If you want to disable preemption, use preempt_disable() and preempt_enable() . 如果要禁用抢占,请使用preempt_disable()preempt_enable() If you want to disable interrupts, use local_irq_disable() and local_irq_enable() 如果要禁用中断,请使用local_irq_disable()local_irq_enable()

spin_lock_irqsave will normally do both of these, though some "real-time" enhancements sometimes allow spinlocks to schedule, so it is always best to say what you mean. spin_lock_irqsave通常会同时执行这两个操作,虽然一些“实时”增强功能有时会让自旋锁安排,所以最好说出你的意思。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Linux上不间断地运行命令 - run commands on linux without interruption 如何确保应用程序在 Linux 上保持运行 - How to make sure an application keeps running on Linux 如何确保正确安装了Linux驱动程序? - How do I make sure that Linux drivers are installed correctly? 如何确保在Linux中使用-g编译程序或共享库 - how to make sure a program or shared library is compiled with -g, in linux 有没有办法确保浮点运算结果在linux和windows中都相同 - Is there any way to make sure the floating point arithmetic result the same in both linux and windows 如何避免因Linux中的信号导致睡眠呼叫中断? - How to avoid the interruption of sleep calls due to a signal in Linux? 如何在没有任何DesktopEnvironment的情况下运行linux? - How to run linux without any DesktopEnvironment? 如何使用 C 以编程方式更改设置以使 Linux 终端中字符的宽度和高度相同而没有任何间距? - How do I change the settings programmatically with C to make the width and height of characters in a Linux terminal the same without any spacing? 在 Linux 中启动“init”进程之前,如何确保已连接的 USB 设备被枚举? - How do I make sure that a connected USB device gets enumerated before starting "init" process in Linux? 使用Java 6,在linux上如何确保使用ipv4套接字? - Using Java 6, on linux how can I make sure to use an ipv4 socket?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM