Liuw's Thinkpad

想要赢就先学会输,想要成功就先学会失败

Archive for the ‘cheet sheet’ tag

Cheet sheet for locking

without comments

Pete Zaitcev gives the following summary:

  • If you are in a process context (any syscall) and want to lock other process out, use a semaphore. You can take a semaphore and sleep ( copy_from_user* or kmalloc(x,GFP_KERNEL) ).
  • Otherwise (== data can be touched in an interrupt), use spin_lock_irqsave() and spin_unlock_irqrestore().
  • Avoid holding spinlock for more than 5 lines of code and across any function call (except accessors like readb).

Read the rest of this entry »

Written by liuw

July 14th, 2010 at 2:04 pm