<div dir="ltr">Hi Silverstri,<br><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Feb 2, 2014 at 1:19 PM, m silverstri <span dir="ltr">&lt;<a href="mailto:michael.j.silverstri@gmail.com" target="_blank">michael.j.silverstri@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">On Sat, Feb 1, 2014 at 5:34 AM, Josh Cartwright &lt;<a href="mailto:joshc@eso.teric.us">joshc@eso.teric.us</a>&gt; wrote:<br>


&gt; On Sat, Feb 01, 2014 at 01:32:49AM -0800, anish singh wrote:<br>
&gt;&gt; On Sat, Feb 1, 2014 at 1:15 AM, m silverstri<br>
&gt;&gt; &lt;<a href="mailto:michael.j.silverstri@gmail.com">michael.j.silverstri@gmail.com</a>&gt; wrote:<br>
&gt;&gt; &gt; By driver code , I mean the code which set the register values and<br>
&gt;&gt; &gt; wait till the values is set (via an interrupt handler) before<br>
&gt;&gt; &gt; continues doing something else<br>
&gt;&gt; ok so you are looking for below code:<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; some_func()<br>
&gt;&gt; {<br>
&gt;&gt; set_register_value<br>
&gt;&gt; x_variable=0<br>
&gt;&gt; wait_for_event*(x_variable);<br>
&gt;&gt; }<br>
&gt;&gt;<br>
&gt;&gt; interrupt_handler(){<br>
&gt;&gt; x_variable=1<br>
&gt;&gt; wake_up();<br>
&gt;&gt; }<br>
&gt;&gt;<br>
&gt;&gt; request_irq(interrupt_handler);<br>
&gt;<br>
&gt; Please investigate the usage of completions in your driver.  See<br>
&gt; include/linux/completion.h.  It sounds like it fits your usecase nicely.<br>
&gt;<br>
&gt;   Josh<br>
<br>
</div>I have loooked at linux completion for my usecase<br>
So I think I can do<br>
<br>
DECLARE_COMPLETION(my_completion);<br>
<br>
some_func()<br>
{<br>
set_register_value<br>
wait_for_completion(my_completion);<br>
}<br>
<br>
interrupt_handler(){<br>
complete(my_completion);<br>
}<br>
<br>
request_irq(interrupt_handler);<br>
<br>
<br>
My question now is what if 1 kernel thread execute some_funct(), but<br>
before interrupt_handler() get invoked (from HW), another kernel<br>
thread executes some_func(). In essence, set_register_value is execute<br>
twice before interrupt_handler() return once.<br></blockquote><div>Use a mutex_lock().</div><div>So your code will be as follows:</div><div><br></div><div>DECLARE_COMPLETION(my_completion);</div><div>struct mutex dev_lock;<br>

<br>some_func()<br>{</div><div>mutex_lock(&amp;dev_lock);<br>set_register_value<br>wait_for_completion(my_completion);</div><div>mutex_unloc(&amp;dev_lock);<br>}<br><br>interrupt_handler(){<br>complete(my_completion);<br>

}<br><br>mutex_init(&amp;dev_lock);<br>request_irq(interrupt_handler);<br></div><div><br></div><div>Thanks,</div><div>Arun</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<br>
how can I prevent another kernel thread from executing<br>
&quot;set_register_value()&quot; when 1 is wait_for_completion?<br>
<div class=""><div class="h5"><br>
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</div></div></blockquote></div><br></div></div>