On Mon, Sep 14, 2009 at 11:43 PM, Daniel Baluta <daniel.baluta@xxxxxxxxx> wrote: > On Mon, Sep 14, 2009 at 6:32 PM, Peter Teoh <htmldeveloper@xxxxxxxxx> wrote: >> On Mon, Sep 14, 2009 at 11:11 PM, Peter Teoh <htmldeveloper@xxxxxxxxx> wrote: >>> sounds like u need TWO variables. reason goes like this: >> > > Huh? > >> >> sorry....I also forgotten to mention that since there are two variable >> now...the interrupt sensitive one should be using spinlock and the one >> that need to be able to sleep() should be a mutex or semaphore > > Can you be more explicit :). > > Daniel. > I tried to be abstract and vague, because even the simple statement "two variable" have multiple implementation possible, so it is up to your design. For eg (a specific design)....since top half have to be quick (http://www.linuxjournal.com/article/6916), just update ONE flag (called flagA), perhaps just a 4 bytes or less variable.....NO spin lock is needed, and then in work queue (is is scheduled from inside the interrupt), and work queue can sleep, just mutex lock all the necessary structures fields (called structB), and modify it, and then unlock it, before calling copy_to_user(). since u are not using copy_from_user(), there is no way it can be modified from userspace, and so no need to keep the mutex lock opened. so long as nobody can acquire the mutex lock, all the fields will stay consistent among itself. whenever u modify one field, all the necessary field get modified within the same lock - for consistency/integrity reason. but of course interrupt can always comes in and modify the flagA, just go ahead and modify it.....it will not affect the value of structB now, but perhaps later, until when the next scheduled workqueue to update the structB gets triggered again. so on the whole everything is logically consistent....any bugs in my logic? (this is just one implementation of the two variable concept) -- Regards, Peter Teoh -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ