Re: repeat a function after fixed time period

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 23 Mar 2005, sounak chakraborty wrote:

dear sir
i want to call my own function inside the kernel
after a fixed interval(i.e some kind of timer)
how to do that which function i have to use to
repeat the function

anather way is that making my own system call
which calls my function and
this sytem call is being access by a user program
which calls it after a fixed inter val of time
will this be correct
thanks
sounak


This kernel code should do just fine.



struct INFO {
    struct timer_list timer;            // For test timer
    atomic_t running;                   // Timer is running
    };

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
//   This stops the timer. This must NOT be called with a spin-lock
//   held.
//
static void stop_timer()
{
    if(atomic_read(&info->running))
    {
        atomic_dec(&info->running);
        if(info->timer.function)
            del_timer(&info->timer);
    }
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
//    This starts the timer. This must NOT be called with a spin-lock
//    held.
//
static void start_timer(void)
{
    if(!atomic_read(&info->running))
    {
        atomic_inc(&info->running);
        init_timer(&info->timer);
        info->timer.expires = jiffies + HZ;
        info->timer.data = 0;
        info->timer.function = test_timer;
        add_timer(&info->timer);
    }
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
//   This is the code that executes at a timer-interval.
//
static void test_timer(unsigned long data)
{
    info->timer.expires = jiffies + HZ;         // New expiration time
    if(atomic_read(&info->running))             // If it's still running
    {
        code_to_execute_every_timer_interval();
        add_timer(&info->timer);                // Into timer-queue again
    }
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


Cheers,
Dick Johnson
Penguin : Linux version 2.6.11 on an i686 machine (5537.79 BogoMips).
 Notice : All mail here is now cached for review by Dictator Bush.
                 98.36% of all statistics are fiction.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux