timeout
, untimeout
,
callout_handle_init
,
callout_init
, callout_stop
,
callout_drain
, callout_reset
,
callout_pending
,
callout_active
,
callout_deactivate
—
???????줿????Ĺ?θ??δؿ??μ¹?
<sys/types.h>
<sys/systm.h>
typedef void timeout_t (void *);
struct callout_handle
timeout
(timeout_t *func,
void *arg, int ticks)
void
callout_handle_init
(struct
callout_handle *handle)
struct callout_handle handle = CALLOUT_HANDLE_INITIALIZER(&handle)
void
untimeout
(timeout_t *func,
void *arg, struct callout_handle
handle) void
callout_init
(struct callout *c,
int mpsafe) int
callout_stop
(struct callout *c)
int
callout_drain
(struct callout *c)
void
callout_reset
(struct callout *c,
int ticks, timeout_t *func,
void *arg) int
callout_pending
(struct callout
*c) int
callout_active
(struct callout
*c) callout_deactivate
(struct
callout *c)
?ؿ? timeout
() ??
ticks/hz
?ø??˼¹Ԥ????뤿???ΰ???
func
?ˤ??ä?Ϳ?????????ؿ????ƤӽФ??????Υ??????塼?????Ԥ??ޤ???
???ǤϤʤ??ͤ? ticks
?ϰ??ۤΤ??????? ‘1’
???Ѵ??????ޤ??? func ??
void *
?ΰ??????????ؿ??ؤΥݥ??Ǥ????٤??Ǥ???
?¹Ի??ˤϡ? func ??
arg
??ͣ???ΰ????Ȥ??Ƽ????????ޤ???
timeout
()
???????????ͤϡ????????塼?뤵?줿 timeout
???????ä????Τ????? untimeout
()
?ؿ??Ȥ???³?˻??Ѥ????뤳?Ȥ???ǽ??
struct callout_handle ?Ǥ???
timeout
()
?θƤӽФ??ϸŤ??????????ǡ????????????ɤ?
callout_*
()
?ؿ??????Ѥ????٤??Ǥ???
?ؿ? callout_handle_init
()
?ϥϥ??ɥ????????????뤿???˻??Ѥ???untimeout
?ȶ???
???Ѥ????Ƥ???????̵?????????褦?ˤ??ޤ???
?????륢???ȥϥ??ɥ???
CALLOUT_HANDLE_INITIALIZER
()
???ͤ??????Ƥ뤳?Ȥϡ?
callout_handle_init
()
??Ʊ?ͤε?ǽ???¹Ԥ?????Ū???????ޤ??ϥ??????Х??ʥ????륢???ȥϥ??ɥ???
???Ѥ??뤿?????????Ƥ??ޤ???
?ؿ? untimeout
()
?ϡ????Υϥ??ɥ?????????????ǧ???뤿????
func ?????? arg
?????????Ѥ??ơ? handle
?˴?Ϣ?դ????줿 timeout ???????ä??ޤ???
???Υϥ??ɥ뤬???? arg
???????ؿ? func ?????? timeout
?Ȱ??פ??ʤ??????ˤϡ??????Ԥ??ޤ?????
handle ?? untimeout
()
???Ϥ????????˰????? timeout
(),
callout_handle_init
()
?θƤӽФ????ޤ???
CALLOUT_HANDLE_INITIALIZER
(&handle)
???ͤγ????Ƥˤ??äƽ??????????ʤ????Фʤ??ޤ?????
?????˽????????줿?ϥ??ɥ???ȼ?ʤ??ʤ?
untimeout ?θƤӽФ??ο?????
̤?????Ǥ??? untimeout
()
?θƤӽФ??ϸŤ??????????ǡ????????????ɤ?
callout_*
()
?ؿ??????Ѥ????٤??Ǥ???
?ϥ??ɥ뤬?????ƥ??ˤ??äƺ????Ѥ??????Τǡ?
ξ???θƤӽФ???Ʊ???ؿ??Υݥ??????Ӱ????????Ѥ???2
???ܤθƤӽФ??????? ?ǽ??? timeout
????λ???뤫?????ä??줿?????ˤϡ?1
?Ĥ? timeout
()
?μ¹Ԥ????Υϥ??ɥ뤬?̤?
timeout
()
?μ¹ԤΥϥ??ɥ뤬???פ??뤳?Ȥ??Ǥ??뤳?Ȥ?
(?ճ??ǤϤ??뤬) ??ǽ?Ǥ??? timeout
???????? timeout
() ??????
untimeout
() ?Τ????? O(1)
?¹Ի??֤????ޤ??? timeout (????: ??????
untimeout) ?? Giant
???å????ݻ??????Ƥ??????֤ǡ?
softclock
() ?????¹Ԥ????ޤ???
???äơ??????????ݸ???ޤ???
?ؿ? callout_init
(),
callout_stop
(),
callout_drain
() ??????
callout_reset
()
?ϸ?ͭ?Υ????륢???ȹ?¤???????Ƥ뤳?Ȥ???˾???륯?饤?????ȤΤ????Ρ?
?????٥??Υ롼?????Ǥ???
?ؿ? callout_init
()
?ϥ????륢???Ȥ??????????????Τ???Υ????륢???Ȥϲ????????Ѥ??ʤ???
callout_stop
(),
callout_drain
() ?ޤ???
callout_reset
()
???Ϥ????뤳?Ȥ??Ǥ??ޤ???
mpsafe ?????? 0 ?ξ????ˤϡ?callout
??¤?Τ?
“?ޥ????ץ????å???????”
?Ǥ????ȤϤߤʤ????ޤ?????
???ʤ????????㥤?????ȥ??å????????륢???ȴؿ??θƽФ?????
???????졢?????륢???ȴؿ????????Ȥ??˲??????????褦?ˤ??ޤ???
?ؿ? callout_stop
()
?ϡ????Υ????륢???Ȥ???????α???ξ????ˤϡ??????륢???Ȥ??????ä??ޤ???
?????륢???Ȥ???α???ξ????ˤϡ?
callout_stop
() ?? 0
?Ǥʤ??ͤ??֤??ޤ???
?????륢???Ȥ????ꤵ???Ƥ??ʤ??????˼¹Ԥ????Ƥ??뤫???¹????ξ????ˤϡ?
0 ???֤????ޤ???
???δؿ????ƤӽФ??????Ȥ????????륢???Ȥ?
Giant ?ߥ塼?ƥå??? (mutex)
?ˤ??ä??ݸ???Ƥ????????ˤϡ?
Giant
???ݻ????Ƥ??ʤ????Фʤ??ޤ?????
?ؿ? callout_drain
()
?ϡ??????륢???Ȥ????˿ʹ????ξ????ˤϤ??δ?λ?????Ȥ??뤳?Ȥ??????ơ?
callout_stop
() ??Ʊ???Ǥ???
???δؿ??ϡ????Υ????륢???Ȥ??֥??å????뤫?⤷???ʤ????????????å???
?ݻ????Ƥ????֤ϡ??褷?ƸƤӽФ????ƤϤʤ??ޤ?????
?????ʤ??ȷ??̤Ȥ??ƥǥåɥ??å????ޤ???
?????륢???ȥ??֥????ƥब???ˤ??Υ????륢???Ȥ????????Ϥ?ʤ?
?????륢???ȴؿ??? callout_drain
()
?μ¹Ԥδ֤˸ƤӽФ????뤫?⤷???ʤ????Ȥ????դ??Ƥ?????????
???????ʤ??顢?????륢???ȥ??֥????ƥ??ϡ?
callout_drain
()
???֤????˥????륢???Ȥ??????????ߤ????뤳?Ȥ??ݾڤ??ޤ???
?ؿ? callout_reset
()
?Ϻǽ??ˤ??Υ????륢???Ȥ??ѻߤ??뤿????
callout_stop
()
??Ʊ?ͤΤ??Ȥ??¹Ԥ??????줫?鿷?????????륢???Ȥ?
timeout
()
??Ʊ??ή???dz?Ω???ޤ???
???δؿ????ƤӽФ??????Ȥ????????륢???Ȥ?
Giant
?ߥ塼?ƥå????ˤ??ä??ݸ?????????ˤϡ?
Giant
???ݻ??????ʤ????Фʤ??ޤ?????
?ޥ??? callout_pending
(),
callout_active
() ??????
callout_deactivate
()
?ϥ????륢???Ȥθ??ߤξ??֤ؤΥ????????????ޤ???
???????Υޥ????Ť˻??Ѥ????С???Ʊ????????????
??ͭ??¿???ζ??????????뤳?Ȥ??Ǥ??ޤ???
?????ʤ??ܺ٤ˤĤ??Ƥϲ?????
??????????????
?Ȥ??Ƥ???????
callout_pending
()
?ޥ????ϡ??????륢???Ȥ?
??α??
?Ǥ??뤫?ɤ????????å????ޤ???
?????륢???Ȥϥ????ॢ???Ȥ????ꤵ???Ƥ??뤬???֤??ޤ????夷?Ƥ??ʤ?????
??α??
?Ǥ????ȸ??ʤ????ޤ???
???ä????ॢ???Ȼ??֤????ơ??????륢???ȥ??֥????ƥब???Υ????륢????
?????????Ϥ????С? callout_pending
()
?Ϥ??Ȥ??????륢???ȴؿ????¹Ԥ???λ????
(?ޤ??ϡ??Ϥ???) ???ʤ??Ƥ?
FALSE
???֤????Ȥ????դ??Ƥ?????????
callout_active
()
?ޥ????ϥ????륢???Ȥ?
?????ƥ???
?Ȥ??ƥޡ????????Ƥ??뤫?ɤ????????å?????
callout_deactivate
()
?ޥ????ϥ????륢???Ȥ?
?????ƥ???
?ե饰?ꥢ???ޤ???
?????륢???ȥ??֥????ƥ??ϡ??????ॢ???Ȥ????ꤵ???Ƥ??륳???륢???Ȥ?
?????ƥ??? ?????ꤷ??
callout_stop
() ??
callout_drain
() ?Ǥ?
?????ƥ??? ?ꥢ???ޤ?????
?????륢???ȴؿ??μ¹Ԥ??̤???
?̾??ɤ??ꥳ???륢???Ȥδ??¤??ڤ줿?????ˤϡ????ꥢ
???ޤ??? ??
?????륢???ȥ??֥????ƥ??Ϥ??켫?ΤΥ????ޥ????ƥ????Ȥ???
?????륢???ȴؿ????ƤӽФ??ޤ???
????????Ʊ???ʤ??Ǥϡ??????륢???ȴؿ???¾?Υ????åɤ??饳???륢???Ȥ?
???ߤ??ꥻ?åȤ????ߤʤ????¹Ԥ??Ƶ?ư????????ǽ?????????ޤ???
?äˡ??????륢???ȴؿ???ŵ??Ū?ˤϺǽ???ư???Ȥ???
?ߥ塼?ƥå??????????????Τǡ?
?????륢???ȴؿ??ϴ??˸ƤӽФ??줿?Ȥ??Ƥ⡢
?̤Υ????åɤ??????륢???Ȥ??ꥻ?åȤ??뤫?ޤ??????ߤ??褦?Ȥ????ޤ?
???Υߥ塼?ƥå??????Ԥäƥ֥??å??????Ƥ??ޤ??ޤ???
?????륢???ȥ??֥????ƥ??Ϥ???????Ʊ???ط????н褹?뤿????
¿???Υᥫ?˥????????ޤ???
- mpsafe ??
FALSE
?????ꤷ?? callout_init
()
?????Ѥ??뤳?Ȥǻ??ꤵ????)
Giant
?ߥ塼?ƥå????ˤ??äƥ????륢???Ȥ??ݸ?????????ϡ?
???Υߥ塼?ƥå????϶??????????뤿???˻??ѤǤ??ޤ???
callout_stop
() ??
callout_reset
()
???ƤӽФ????ˡ? Giant
?ߥ塼?ƥå????ϸƤӽФ?¦?ˤ??äƳ????????ʤ????Фʤ??ޤ???
?????륢???Ȥ????ꤷ???Ȥ??????????????ߤ????뤫?ޤ??ϥꥻ?åȤ?????
???Ȥ??ݾڤ????ޤ???
?????륢???Ȥ????δ?Ϣ?Υߥ塼?ƥå??????˲?????????
callout_drain
()
?????Ѥ???ɬ?פ??ޤ????뤳?Ȥ????դ??Ƥ?????????
callout_stop
()
?????Υ?????ͤϡ??????륢???Ȥ????????줿???ɤ??????ޤ???
?????륢???Ȥ????ꤵ?졢
?????륢???ȴؿ????ޤ??¹Ԥ????Ƥ??ʤ????Ȥ??狼?äƤ????????ϡ?
FALSE
???ͤϥ????륢???ȴؿ????ޤ??˸ƤӽФ????褦?Ȥ??Ƥ??뤳?Ȥ??ޤ???
?㤨??:
if (sc->sc_flags & SCFLG_CALLOUT_RUNNING) {
if (callout_stop(&sc->sc_callout)) {
sc->sc_flags &= ~SCFLG_CALLOUT_RUNNING;
/* successfully stopped */
} else {
/*
* callout has expired and callout
* function is about to be executed
*/
}
}
callout_reset
()
???????륢???Ȥ????ߤ??????ɤ??????ꤹ?뤿????
Ʊ???ʥᥫ?˥??ब?ʤˤ??ʤ????Ȥ????դ??Ƥ?????????
callout_pending
(),
callout_active
() ??????
callout_deactivate
()
?ޥ????϶????????????뤿????Ϣ?Ȥ??ƻ??ѤǤ??ޤ???
?????륢???ȤΥ????ॢ???Ȥ????ꤵ?????Ȥ????????륢???ȥ??֥????ƥ???
?Ȥ??? ?????ƥ??? ??
??α??
??ξ???ǥ????륢???Ȥ??ޡ??????ޤ???
?????ॢ???Ȼ??֤?ã?????Ȥ????????륢???ȥ??֥????ƥ???
??α??
?Υե饰???ǽ??˥??ꥢ???뤳?Ȥˤ??äƥ????륢???Ȥ????????Ϥ??ޤ???
???ˡ? ?????ƥ???
?ե饰???Ѥ??ʤ??ǥ????륢???ȴؿ????ƤӽФ??ơ?
?????륢???ȴؿ??????ä????Ǥ???
?????ƥ???
?ե饰?ꥢ???ޤ?????
?????????????줿?ᥫ?˥????Ǥϡ?
?????륢???ȴؿ????Τ?
callout_deactivate
() ?ޥ????????Ѥ???
?????ƥ???
?ե饰?ꥢ???뤳?Ȥ??ᤷ?ޤ???
callout_stop
() ??
callout_drain
() ?ؿ??????????ˡ? ????
?????ƥ??? ?? ??α??
?ե饰??ξ???ꥢ???ޤ???
callout_pending
() ??
TRUE
???֤????硢
?????륢???ȴؿ??ϡ??ǽ???
??α??
?ե饰???????å?????ư???ʤ????????٤??Ǥ???
?????ϡ??????륢???Ȥ??????륢???ȴؿ????ƤӽФ?????ľ????
callout_reset
()
?????Ѥ??ƺƥ??????塼?뤵?줿???Ȥ??ޤ???
callout_active
() ??
FALSE
???֤????硢?????륢???ȴؿ???Ʊ?ͤ?ư???ʤ????֤??٤??Ǥ???
?????ϡ??????륢???Ȥ????ߤ??줿???Ȥ??ޤ???
?Ǹ??ˡ??????륢???ȴؿ??ϡ?
?????ƥ???
?ե饰?ꥢ???뤿????
callout_deactivate
()
???ƤӽФ??٤??Ǥ??? ?㤨??:
mtx_lock(&sc->sc_mtx);
if (callout_pending(&sc->sc_callout)) {
/* callout was reset */
mtx_unlock(&sc->sc_mtx);
return;
}
if (!callout_active(&sc->sc_callout)) {
/* callout was stopped */
mtx_unlock(&sc->sc_mtx);
return;
}
callout_deactivate(&sc->sc_callout);
/* rest of callout function */
?嵭?ǻ??Ѥ????ߥ塼?ƥå????Τ褦??Ŭ?ڤ?Ʊ?????Ȥ??˻Ȥ????Ȥˤ??ꡢ
???Υ??ץ??????? callout_stop
() ??
callout_reset
()
?ؿ??????Ĥⶥ???ʤ??ǻ??ѤǤ??ޤ???
?㤨??:
mtx_lock(&sc->sc_mtx);
callout_stop(&sc->sc_callout);
/* The callout is effectively stopped now. */
?????륢???Ȥ??ޤ???α???Ǥ??????硢???????δؿ????̾??ɤ???ư??ޤ?????
?????륢???Ȥν????????˻ϤޤäƤ??????硢
?????륢???ȴؿ??ˤ??????ƥ??Ȥˤ????ơ????????δؿ??Ϥ????ʤ?
ư???ʤ??????뤳?Ȥˤʤ??ޤ???
?????륢???ȴؿ???¾?Υ????ɤδ֤?Ʊ???ϡ??????륢???ȴؿ???
callout_deactivate
()
?ƤӽФ??????ޤǥ????륢???Ȥ????ߤ??ꥻ?åȤ??Ԥ????ʤ????Ȥ?
?μ¤ˤ??ޤ???
?????ˡ??嵭?Υƥ??˥å??ϡ?
?????ƥ???
?ե饰???ºݤ˥????륢???Ȥ?ͭ????̵??????ȿ?Ǥ??뤳?Ȥ??μ¤ˤ??ޤ???
callout_active
() ?? FALSE
???֤??????硢???Ȥ??????륢???ȥ??֥????ƥब
?ºݤ˥????륢???ȴؿ??Ϥ??褦?Ȥ??Ƥ????Ȥ??Ƥ⡢
?????륢???ȴؿ???ư???ʤ??˽?λ???Ƥ??ޤ??Τǡ?
?¼?Ū??̵?????????Ƥ??ޤ???
?Ǹ??ˡ??????륢???Ȥ????ߤ??褦?Ȥ??Ƥ????Ȥ???
??θ???ʤ????Фʤ??ʤ??Ǹ??ζ??????郎
1 ?Ĥ????ޤ???
???ξ??硢?????˲??????뤫?ޤ??Ϻ????Ѥ??줿?ǡ??????֥??????Ȥ?
????????????ɬ?פ????뤫?⤷???ʤ??Τǡ?
?????륢???ȴؿ????Τ?
???ߤ??줿?????륢???ȤФ??뤵???뤿???˰????Ǥʤ????⤷???ޤ?????
?????륢???Ȥ??????˽?λ???????Ȥ??ݾڤ??뤿???ˤϡ?
callout_drain
()
?ƤӽФ??????Ѥ??ʤ????Фʤ??ޤ?????
timeout
() ?ؿ???
untimeout
() ???Ϥ????Ȥ???ǽ??
struct callout_handle ???֤??ޤ???
callout_stop
() ??????
callout_drain
()
?ؿ??ϸƤӽФ??줿???˥????륢???Ȥ?̤????α???ξ????ˤ?
0 ?ʳ????? ?????Ǥʤ??????ˤ? 0
???֤??ޤ???
???ߤ? timeout ?????? untimeout ?롼?????? Adam M.
Costello ?????? George Varghese ??
Redesigning the BSD Callout and Timer Facilities
??̾?դ????줿???ѥ??ݡ??Ȥ?ȯɽ???줿???Ȥ˴??Ť??Ƥ??ޤ???
?ޤ??? FreeBSD
?ؤ?Ƴ???Τ????? Justin T. Gibbs
?ˤ??äƾ????????????Ƥ??ޤ???
???μ????ǻ??Ѥ????Ƥ????ǡ?????¤?θ??κ??Ȥϡ?
G. Varghese ?????? A. Lauck
?ˤ??ä? Proceedings of the 11th ACM Annual
Symposium on Operating Systems Principles ?? Hashed and
Hierarchical Timing Wheels: Data Structures for the Efficient Implementation
of a Timer Facility ??ȯɽ?????ޤ?????
???ߤμ????ϡ?Ĺ?餯¸?ߤ??Ƥ??????????????Ӻ?????
O(n) ?¹Ի??֤? ???뤬 untimeout
?????Τ????Υϥ??ɥ????????ޤ????ᤷ?ʤ??ä?
BSD
???ꥹ?ȤΥ????륢???ȵ????ˡ????ä??????ޤ?????