[lkml]   [2000]   [Oct]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectIs this a valid construct?
Does the following pseudocode do what I think it does?

Assume the semaphore is properly initialized to locked.

int flagvar = 0;
struct semaphore blocking_sem;

void function_called_from_kernel_thread(void)
flagvar = 1;

if (flagvar)
printk("something went wrong")
printk("everything okay")

void function_called_from_interrupt_context()
flagvar = 0;

void function_to_call_from_timeout()

The idea is this -- I chew on the hardware, then sleep on the semaphore. I
then either get woken up by an IRQ (which may never come), or the timeout.
I then try to use the flagvar to determine which of the two happened.

This _looks_ valid to me... but I'm seeing occurances where I get the IRQ
(yes, I'm sure of it) but flagvar == 1, which confuses me.

Is this one of those places where I need the "volatile" keyword?

The code I'm working on is in the kernel... but this is the stripped-down
version. I can provide files/lines if people want to look at particulars.


Matthew Dharm Home:
Maintainer, Linux USB Mass Storage Driver

Somebody call an exorcist!
-- Dust Puppy
User Friendly, 5/16/1998
[unhandled content-type:application/pgp-signature]
 \ /
  Last update: 2005-03-22 12:41    [W:0.034 / U:1.920 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site