Lines Matching refs:ch
38 callback_head_init(struct callback_head *ch, int ipl)
41 memset(ch, 0, sizeof(struct callback_head));
42 mutex_init(&ch->ch_lock, MUTEX_DEFAULT, ipl);
43 cv_init(&ch->ch_cv, "callback");
44 TAILQ_INIT(&ch->ch_q);
46 ch->ch_next = NULL;
47 ch->ch_nentries = 0;
48 ch->ch_running = 0;
49 ch->ch_flags = 0;
54 callback_head_destroy(struct callback_head *ch)
57 mutex_destroy(&ch->ch_lock);
58 cv_destroy(&ch->ch_cv);
62 callback_register(struct callback_head *ch, struct callback_entry *ce,
69 mutex_enter(&ch->ch_lock);
70 TAILQ_INSERT_TAIL(&ch->ch_q, ce, ce_q);
71 ch->ch_nentries++;
72 mutex_exit(&ch->ch_lock);
76 callback_unregister(struct callback_head *ch, struct callback_entry *ce)
79 mutex_enter(&ch->ch_lock);
80 while (ch->ch_running > 0)
81 cv_wait(&ch->ch_cv, &ch->ch_lock);
82 if (__predict_false(ch->ch_next == ce)) {
83 ch->ch_next = TAILQ_NEXT(ce, ce_q);
85 TAILQ_REMOVE(&ch->ch_q, ce, ce_q);
86 ch->ch_nentries--;
87 mutex_exit(&ch->ch_lock);
91 callback_runone(struct callback_head *ch, void *arg)
96 KASSERT(ch->ch_nentries > 0);
97 KASSERT(ch->ch_running > 0);
99 ce = ch->ch_next;
101 ce = TAILQ_FIRST(&ch->ch_q);
106 ch->ch_next = TAILQ_NEXT(ce, ce_q);
111 callback_run_enter(struct callback_head *ch)
114 mutex_enter(&ch->ch_lock);
115 ch->ch_running++;
116 mutex_exit(&ch->ch_lock);
120 callback_run_leave(struct callback_head *ch)
123 mutex_enter(&ch->ch_lock);
124 KASSERT(ch->ch_running > 0);
125 ch->ch_running--;
126 if (ch->ch_running == 0)
127 cv_broadcast(&ch->ch_cv);
128 mutex_exit(&ch->ch_lock);
132 callback_run_roundrobin(struct callback_head *ch, void *arg)
138 callback_run_enter(ch);
139 n = ch->ch_nentries;
141 result = callback_runone(ch, arg);
146 callback_run_leave(ch);