2014-12-10 3 views
1

여러 hrtimers를 구현하고 싶지만 모두 동일한 콜백 함수를 사용하는 방법을 잘 모르겠습니다. 예를 들어, 필드 중 하나가 struct hrtimer 인 my_struct 유형의 배열이 있습니다.커널 모듈, 복수 고해상도 타이머

콜백 함수를 입력 할 때 배열의 어느 요소를 호출하는지 결정하는 방법은 무엇입니까?

답변

2

사용 container_of 매크로 :

struct my_struct { 
    int my_something; 
    struct hrtimer my_timer; 
    ... 
}; 

enum hrtimer_restart my_callback(struct hrtimer *hrtimer) 
{ 
    struct my_struct my = container_of(hrtimer, struct my_struct, my_timer); 
    my->my_something = 42; 
    ... 
} 
+0

이 완벽합니다. 고맙습니다! :) – selfbg