title: How correctly wake up process inside interrupt handlers
body: <p>Briefly, in a <code>read</code> method i check if a variable is 0 and if it's i put the current process to sleep:</p>
  
  <pre><code>static ssize_t soc2e_read(struct file *filp, char __user *buf,
                            size_t count, loff_t * ppos)
  {
      ...
      struct soc2e_dev *soc2e = (struct soc2e_dev *)filp-&gt;private_data;
  
      if (soc2e-&gt;bytes == 0)
      {
          if (wait_event_interruptible(soc2e-&gt;wlist, (soc2e-&gt;bytes &gt; 0)))
              return -ERESTARTSYS;
      }
      ...
   }
  </code></pre>
  
  <p>I must wake up the process in an interrupt handler:</p>
  
  <pre><code>static irqreturn_t soc2e_irq_handler(int irq, void *dev)
  {
     ...
     struct soc2e_dev *soc2e = dev;
     ...
     soc2e-&gt;bytes += read_bytes;
  
     wake_up_interruptible(&amp;soc2e-&gt;wlist);
     return IRQ_HANDLED;
  }
  </code></pre>
  
  <p>I think (and also verified) that here could be a problem of atomicity. What happen if interrupt comes between <code>if (soc2e-&gt;bytes == 0)</code> in <code>read</code> method and the call to <code>wait_event_interruptible</code>. Maybe the process won't be waked up until next interrupt. What is the best way to resolve this issue?</p>