Thanks Arun, But why not just use mutex and remove the completion? i.e. do this: struct mutex dev_lock; some_func() { mutex_lock(&dev_lock); set_register_value } interrupt_handler(){ mutex_unloc(&dev_lock); } mutex_init(&dev_lock); request_irq(interrupt_handler); On Mon, Feb 3, 2014 at 1:54 AM, Arun KS <getarunks@xxxxxxxxx> wrote: > Hi Silverstri, > > > On Sun, Feb 2, 2014 at 1:19 PM, m silverstri > <michael.j.silverstri@xxxxxxxxx> wrote: >> >> On Sat, Feb 1, 2014 at 5:34 AM, Josh Cartwright <joshc@xxxxxxxxxxxx> >> wrote: >> > On Sat, Feb 01, 2014 at 01:32:49AM -0800, anish singh wrote: >> >> On Sat, Feb 1, 2014 at 1:15 AM, m silverstri >> >> <michael.j.silverstri@xxxxxxxxx> wrote: >> >> > By driver code , I mean the code which set the register values and >> >> > wait till the values is set (via an interrupt handler) before >> >> > continues doing something else >> >> ok so you are looking for below code: >> >> >> >> >> >> some_func() >> >> { >> >> set_register_value >> >> x_variable=0 >> >> wait_for_event*(x_variable); >> >> } >> >> >> >> interrupt_handler(){ >> >> x_variable=1 >> >> wake_up(); >> >> } >> >> >> >> request_irq(interrupt_handler); >> > >> > Please investigate the usage of completions in your driver. See >> > include/linux/completion.h. It sounds like it fits your usecase nicely. >> > >> > Josh >> >> I have loooked at linux completion for my usecase >> So I think I can do >> >> DECLARE_COMPLETION(my_completion); >> >> some_func() >> { >> set_register_value >> wait_for_completion(my_completion); >> } >> >> interrupt_handler(){ >> complete(my_completion); >> } >> >> request_irq(interrupt_handler); >> >> >> My question now is what if 1 kernel thread execute some_funct(), but >> before interrupt_handler() get invoked (from HW), another kernel >> thread executes some_func(). In essence, set_register_value is execute >> twice before interrupt_handler() return once. > > Use a mutex_lock(). > So your code will be as follows: > > DECLARE_COMPLETION(my_completion); > struct mutex dev_lock; > > some_func() > { > mutex_lock(&dev_lock); > set_register_value > wait_for_completion(my_completion); > mutex_unloc(&dev_lock); > } > > interrupt_handler(){ > complete(my_completion); > } > > mutex_init(&dev_lock); > request_irq(interrupt_handler); > > Thanks, > Arun > >> >> >> how can I prevent another kernel thread from executing >> "set_register_value()" when 1 is wait_for_completion? >> >> _______________________________________________ >> Kernelnewbies mailing list >> Kernelnewbies@xxxxxxxxxxxxxxxxx >> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies > > _______________________________________________ Kernelnewbies mailing list Kernelnewbies@xxxxxxxxxxxxxxxxx http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies