0

I am working on implementing blocking calls in char device drivers. I use wait_queue_head_t element with wait_queue_interruptible and wake_up_interruptible calls. What I understand and read about blocking behaviour is that when a call is blocked it sleeps( not busy wait) and doesn't consume resources. But when I checked struct wait_queue_head in wait.h , it uses a spin-lock. spin-locks have behaviour of not sleeping (busy waiting)..! So this confused me. Any clarifications to help on this please? Am I missing something?

Chinna
  • 3,930
  • 4
  • 25
  • 55
Diwakar Sharma
  • 415
  • 1
  • 9
  • 26
  • Please have a look [Here](http://stackoverflow.com/questions/5869825/when-should-one-use-a-spinlock-instead-of-mutex). – Dayal rai Dec 11 '13 at 05:17

2 Answers2

2

The purpose of spinlock you find in

struct __wait_queue_head {
spinlock_t lock;
struct list_head task_list;

};

is to protect the member task_list from concurrent access. If you step in wait_queue_interruptible() you could find a call to schedule().

toyoubala
  • 71
  • 3
1

To expand on the other answer: the spinlock inside the struct wait_queue_head is used to protect the internal list member in case multiple threads are accessing it simultaneously. However, the spinlock is never held when going to sleep -- it is only held during the small, non-preemptable, non-sleeping critical sections that manipulate the wait queue internals.

Roland
  • 6,227
  • 23
  • 29