- 論壇徽章:
- 0
|
/**
* 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;
}
按正常說,這段代碼執(zhí)行應該沒有什么問題,atomic_read和atomic_cmpxchg都能執(zhí)行成功。
但是為什么要用do while語句來實現(xiàn)呢?說明確實存在循環(huán)的可能嗎?會不會出現(xiàn)死循環(huán)呢?
因為我在中斷上下文執(zhí)行的時候,出了一次NMI的WATCHDOG復位,也就是在中斷中執(zhí)行時間太長了,
會不會是這里在某種情況下死循環(huán)呢?如果不是,為什么這里要寫出do while呢,完全可以用if!
(當然也有可能是執(zhí)行中斷中的其他部分代碼的時間太長導致NMI復位的) |
|