<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"><<a href="mailto:michael.j.silverstri@gmail.com" target="_blank">michael.j.silverstri@gmail.com</a>></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 <<a href="mailto:joshc@eso.teric.us">joshc@eso.teric.us</a>> wrote:<br>
> On Sat, Feb 01, 2014 at 01:32:49AM -0800, anish singh wrote:<br>
>> On Sat, Feb 1, 2014 at 1:15 AM, m silverstri<br>
>> <<a href="mailto:michael.j.silverstri@gmail.com">michael.j.silverstri@gmail.com</a>> wrote:<br>
>> > By driver code , I mean the code which set the register values and<br>
>> > wait till the values is set (via an interrupt handler) before<br>
>> > continues doing something else<br>
>> ok so you are looking for below code:<br>
>><br>
>><br>
>> some_func()<br>
>> {<br>
>> set_register_value<br>
>> x_variable=0<br>
>> wait_for_event*(x_variable);<br>
>> }<br>
>><br>
>> interrupt_handler(){<br>
>> x_variable=1<br>
>> wake_up();<br>
>> }<br>
>><br>
>> request_irq(interrupt_handler);<br>
><br>
> Please investigate the usage of completions in your driver. See<br>
> include/linux/completion.h. It sounds like it fits your usecase nicely.<br>
><br>
> 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(&dev_lock);<br>set_register_value<br>wait_for_completion(my_completion);</div><div>mutex_unloc(&dev_lock);<br>}<br><br>interrupt_handler(){<br>complete(my_completion);<br>
}<br><br>mutex_init(&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>
"set_register_value()" 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>