title: How does wakeup(void *chan) works in xv6?
body: <p>I'm learning about osdev and looking up xv6 code, currently - the console code in particular. Basically, I don't get how the console launches a process. </p>
  
  <p>in <strong>console.c</strong> there is a function:</p>
  
  <pre><code>void consoleintr(int (*getc)(void)) {
      ....
      while((c = getc()) &gt;= 0) {
         switch(c) {
             ....
             default:
                 ....
                 if(c == '\n' || c == C('D') || input.rightmost == input.r + INPUT_BUF) {
                     wakeup(&amp;input.r);
         }
      }
  }
  </code></pre>
  
  <p>So I get it, when the line ends (or the length of the buffer exceeds maximum), it launches <em>wakeup(&amp;input.r)</em></p>
  
  <p>Then there is this in <strong>proc.c</strong>:</p>
  
  <pre><code>// Wake up all processes sleeping on chan.
  // The ptable lock must be held.
  static void wakeup1(void *chan)
  {
      struct proc *p;
  
      for(p = ptable.proc; p &lt; &amp;ptable.proc[NPROC]; p++)
          if(p-&gt;state == SLEEPING &amp;&amp; p-&gt;chan == chan)
              p-&gt;state = RUNNABLE;
  }
  
  // Wake up all processes sleeping on chan.
  void wakeup(void *chan)
  {
      acquire(&amp;ptable.lock);
      wakeup1(chan);
      release(&amp;ptable.lock);
  }
  </code></pre>
  
  <p>What is happening here? Why is it comparing address of a console buffer and proc's <strong>chan</strong>? What is this <strong>chan</strong>?</p>