How to awake a process waiting for a semaphore?
Garcia Jérémie
GARCIAJ at 3il.fr
Mon Jun 27 23:59:01 EST 2005
Hi everybody,
as the subject of this mpail tells, I'd like to be able to interrupt a task that
is waiting for a semaphore to be free.
Indeed I use "down_interruptible()" and I'd like to be able to tell to the task
after a period of time : "give up, awake and do something else".
I tried this piece of code in a kernel module to test this, but obviously that
doesn't work (I tried 2 ways but both failed) :
struct semaphore * testSem;
void myAlert(unsigned long data)
{
char *msg = "TIMEOUT!\n";
task_t * myTask = (task_t *)data;
printk("Current task state : %d",myTask->state);
printk("%s",msg);
// First Test
wake_up_process((task_t *)data);
// Second Test
//myTask->state = TASK_RUNNING
int test(void)
{
int ret_val,state,timeout=500;
struct timer_list myTimer;
testSem = (struct semaphore *)kmalloc(sizeof(struct semaphore),GFP_ATOMIC);
sema_init(testSem,0);
state = current->state;
printk("Current task state: %d\n",state);
init_timer(&myTimer);
myTimer.expires = jiffies + timeout;
myTimer.data = (unsigned long) current;
myTimer.function = myAlert;
myTimer.data = (unsigned long) current;
add_timer(&myTimer);
// That will get the task to sleep for sure
down_interruptible(testSem);
del_timer_sync(&myTimer);
return 0;
}
More information about the Linuxppc-dev
mailing list