Fixed a bug

spin_lock cannot be used in code which may cause sleep.