> After succesfully hanging my machine several dozen time at this
> stage I've a
> question. I'm playing with a PCI Development board at the moment,
> and for the
> board I maintain "board" struct which I pass around a pointer to in the
> file->private_data pointer thus maintaining state information. I
> have several
> buffers and variables which I will be accessing from bottom_half
> handlers and
> these can also be accessed from the device driver_write/read
> functions... what
> is the best way to protect these buffers...
Add a spinlock field to the board structure and make sure that
every code path that accesses the structure acquires the spin
lock first.
Note that read()/write() (i.e. non-interrupt code) must lock
out interrupts while it holds the spinlock, otherwise deadlocks
can occur.
IIRC, the spin_lock_irqsave and spin_unlock_irqrestore are the
macros that you need. They will do the spinlock and interrupt
blocking stuff in the correct order.
If you want to get really fancy, you can create spinlocks that
allow for multiple simultaneous readers but only a single,
exclusive writers. Look at asm/spinlock.h
Later,
Kenn
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!