Linux核心定時器

來源:互聯網
上載者:User

標籤:style   blog   color   使用   io   ar   art   div   cti   

一、核心定時器定義:

struct timer_list {    struct list_head entry;    unsigned long expires;    void (*function)(unsigned long);    unsigned long data;    struct tvec_base *base;#ifdef CONFIG_TIMER_STATS    void *start_site;    char start_comm[16];    int start_pid;#endif#ifdef CONFIG_LOCKDEP    struct lockdep_map lockdep_map;#endif};

二、使用方法:

  ①struct timer_list timer;

   void fun (unsigned long arg);

   unsigned long = 0;

  ②init_timer (&timer);

  ③setup_timer (&timer, fun, (unsigned long )arg);  

  ④timer.expires = jiffires + 60 * HZ; //自訂一個逾時時間,jiffires是計時器的當前值(單位是中斷),HZ是每秒對應的中斷次數。

  ⑤add_timer (&timer);

  ⑥如果是希望周期運行,則每次在註冊的函數執行完畢後需要重新設定、啟用定時器,可以使用mod_timer()。核心注釋:

    * mod_timer(timer, expires) is equivalent to:
    *
    * del_timer(timer); timer->expires = expires; add_timer(timer);

 

   mod_timer (&timer, jiffires + 60 * HZ); //寫在fun函數的最後

  ⑦del_timer (&timer);

 

ps:個人快速筆記,如有錯誤期待指出。

Linux核心定時器

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.