定时器相关的一些结构体

来源:互联网 发布:德拉蒙德格林数据 编辑:程序博客网 时间:2024/04/30 11:50
content:
struct timer_list   
init_timer   
timer_pending   
add_timer   
del_timer   
del_timer_sync   
-------------------------------------------------------------------------------------------------------------------------------------------------------------
struct timer_list
The timer_list structure specifies a timer object in Linux kernel.  
  struct timer_list {
        struct list_head list;
    unsigned long expires;
    unsigned long data;
    void (*function)(unsigned long param);
    };
 
Members  
list      A struct list_head object. It is used to queue timer_list together.   
expires   Specifies the timeout value in jiffies format.   
data      User-defined variable. This field enables user of a common timeout function for several timeouts. You can use this field to distinguish between the difference invocations.   
function  User defined callback function.   
 
 
Headers  
Defined timer.h.
 
Comments  
User should allocate timer_list object in resident storage because timer will be triggered in interrupt context.
-------------------------------------------------------------------------------------------------------------------------------------------------------------
init_timer Function
Initialize a timer_list object.  
 
Syntax  
 
  void
    init_timer(
      struct timer_list* timer
      );
 
Parameters  
timer  Pointer to caller-supplied, resident storage for a timer object.   
 
 
Return Value  
None
 
Remarks  
Because timer_list structure has several other fields, you can't call add_timer to add a timer directly. Once you call init_timer to initialize a timer_list object, you should fill other fields manually. For example, the callback function pointer function should be filled because Linux kernel notifies user using this field. Field expires in timer_list should be set to the time in jiffies format. See struct timer_object for more information about internal fields.  
 
Headers  
Declared in timer.h, which located in $KERNEL_ROOT/include/linux.  
-------------------------------------------------------------------------------------------------------------------------------------------------------------
timer_pending Function
Checks the timer state.  
 
Syntax  
 
  int  
    timer_pending(
      const struct timer_list * timer
      );
 
Parameters  
timer  the timer object that you want to get state from   
 
 
Return Value  
Returns 0 if the timer has expired or doesn't insert to kernel timer list. Non-0 value otherwise.
 
Remarks  
You could test the timer state using this function.  
 
Headers  
Declared in timer.h.  
-------------------------------------------------------------------------------------------------------------------------------------------------------------
add_timer Function
Add a new timer to kernel.  
 
Syntax  
 
  void  
    add_timer(
      struct timer_list *timer
      );
 
Parameters  
timer  Pointer to timer_list object that has been initialized using init_timer.   
 
 
Return Value  
None
 
Remarks  
This function can be called in interrupt and non-interrupt context safely. The kernel keeps up a sorted timer list and polled more or less 100 times per second. Before you try to add timer to kernel, you should initialize all fields in timer_list structure.  
 
Headers  
Declared in timer.h.
-------------------------------------------------------------------------------------------------------------------------------------------------------------
del_timer Function
If a timer needs to be removed from kernel before it expires, del_timer should be called. When a timer expires, it is automatically removed also.  
 
Syntax  
 
  int
    del_timer(
      struct timer_list* timer_list
      );
 
Parameters  
timer  The timer that should be removed.   
 
 
Return Value  
If the timer is removed successfully before expiration, the return value is 1. Returns 0 if the timer has already expired.  
 
Remarks  
When 1 is returned, the timer is removed successfully and it will not be run. In contrast, when 0 is returned, you should take care of race condition because it's possible that the timer callback function is running.  
 
Headers  
Declared in timer.h.  
-------------------------------------------------------------------------------------------------------------------------------------------------------------
del_timer_sync Function
If a timer needs to be removed from kernel before it expires, del_timer should be called. When a timer expires, it is automatically removed also.  
 
Syntax  
 
  int
    del_timer_sync(
      struct timer_list* timer_list
      );
 
Parameters  
timer  The timer that should be removed.   
 
 
Return Value  
If the timer is removed successfully before expiration, the return value is 1. Returns 0 if the timer has already expired.  
 
Remarks  
Like del_timer, but this function makes sure that the deleting timer doesn't run in other CPUs. So when this function returns, the timer is either removed remove kernel or finished its timeout function.  
 
Headers  
Declared in timer.h.
-------------------------------------------------------------------------------------------------------------------------------------------------------------
原创粉丝点击