请问一个infiniband驱动代码的问题
/*** srpt_set_cmd_state() - Set the state of a SCSI command.
* @new: New state to be set.
*
* Does not modify the state of aborted commands. Returns the previous command
* state.
*/
enum srpt_command_state srpt_set_cmd_state(struct srpt_ioctx * ioctx,
enum srpt_command_state new)
{
enum srpt_command_state previous;
BUG_ON(!ioctx);
WARN_ON(new == SRPT_STATE_NEW);
do
{
previous = atomic_read(&ioctx->state);
} while ((previous != SRPT_STATE_DONE)
&& atomic_cmpxchg(&ioctx->state, previous, new) != previous);
return previous;
}
按正常说,这段代码执行应该没有什么问题,atomic_read和atomic_cmpxchg都能执行成功。
但是为什么要用do while语句来实现呢?说明确实存在循环的可能吗?会不会出现死循环呢?
因为我在中断上下文执行的时候,出了一次NMI的WATCHDOG复位,也就是在中断中执行时间太长了,
会不会是这里在某种情况下死循环呢?如果不是,为什么这里要写出do while呢,完全可以用if啊!
(当然也有可能是执行中断中的其他部分代码的时间太长导致NMI复位的)
页:
[1]