Lines Matching +full:poll +full:- +full:retry +full:- +full:count

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
44 #include <sys/poll.h>
117 efd->efd_flags = flags;
118 efd->efd_count = initval;
119 mtx_init(&efd->efd_lock, "eventfd", NULL, MTX_DEF);
120 knlist_init_mtx(&efd->efd_sel.si_note, &efd->efd_lock);
135 efd = fp->f_data;
136 seldrain(&efd->efd_sel);
137 knlist_destroy(&efd->efd_sel.si_note);
138 mtx_destroy(&efd->efd_lock);
148 eventfd_t count;
151 if (uio->uio_resid < sizeof(eventfd_t))
155 efd = fp->f_data;
156 mtx_lock(&efd->efd_lock);
157 while (error == 0 && efd->efd_count == 0) {
158 if ((fp->f_flag & FNONBLOCK) != 0) {
159 mtx_unlock(&efd->efd_lock);
162 error = mtx_sleep(&efd->efd_count, &efd->efd_lock, PCATCH,
166 MPASS(efd->efd_count > 0);
167 if ((efd->efd_flags & EFD_SEMAPHORE) != 0) {
168 count = 1;
169 --efd->efd_count;
171 count = efd->efd_count;
172 efd->efd_count = 0;
174 KNOTE_LOCKED(&efd->efd_sel.si_note, 0);
175 selwakeup(&efd->efd_sel);
176 wakeup(&efd->efd_count);
177 mtx_unlock(&efd->efd_lock);
178 error = uiomove(&count, sizeof(eventfd_t), uio);
180 mtx_unlock(&efd->efd_lock);
190 eventfd_t count;
193 if (uio->uio_resid < sizeof(eventfd_t))
196 error = uiomove(&count, sizeof(eventfd_t), uio);
199 if (count == UINT64_MAX)
202 efd = fp->f_data;
203 mtx_lock(&efd->efd_lock);
204 retry:
205 if (UINT64_MAX - efd->efd_count <= count) {
206 if ((fp->f_flag & FNONBLOCK) != 0) {
207 mtx_unlock(&efd->efd_lock);
209 uio->uio_resid += sizeof(eventfd_t);
212 error = mtx_sleep(&efd->efd_count, &efd->efd_lock,
215 goto retry;
218 MPASS(UINT64_MAX - efd->efd_count > count);
219 efd->efd_count += count;
220 KNOTE_LOCKED(&efd->efd_sel.si_note, 0);
221 selwakeup(&efd->efd_sel);
222 wakeup(&efd->efd_count);
224 mtx_unlock(&efd->efd_lock);
236 efd = fp->f_data;
238 mtx_lock(&efd->efd_lock);
239 if ((events & (POLLIN | POLLRDNORM)) != 0 && efd->efd_count > 0)
241 if ((events & (POLLOUT | POLLWRNORM)) != 0 && UINT64_MAX - 1 >
242 efd->efd_count)
245 selrecord(td, &efd->efd_sel);
246 mtx_unlock(&efd->efd_lock);
254 struct eventfd *efd = fp->f_data;
256 mtx_lock(&efd->efd_lock);
257 switch (kn->kn_filter) {
259 kn->kn_fop = &eventfd_rfiltops;
262 kn->kn_fop = &eventfd_wfiltops;
265 mtx_unlock(&efd->efd_lock);
269 kn->kn_hook = efd;
270 knlist_add(&efd->efd_sel.si_note, kn, 1);
271 mtx_unlock(&efd->efd_lock);
279 struct eventfd *efd = kn->kn_hook;
281 mtx_lock(&efd->efd_lock);
282 knlist_remove(&efd->efd_sel.si_note, kn, 1);
283 mtx_unlock(&efd->efd_lock);
289 struct eventfd *efd = kn->kn_hook;
292 mtx_assert(&efd->efd_lock, MA_OWNED);
293 kn->kn_data = (int64_t)efd->efd_count;
294 ret = efd->efd_count > 0;
302 struct eventfd *efd = kn->kn_hook;
305 mtx_assert(&efd->efd_lock, MA_OWNED);
306 kn->kn_data = (int64_t)(UINT64_MAX - 1 - efd->efd_count);
307 ret = UINT64_MAX - 1 > efd->efd_count;
329 st->st_mode = S_IFIFO;
336 struct eventfd *efd = fp->f_data;
338 kif->kf_type = KF_TYPE_EVENTFD;
339 mtx_lock(&efd->efd_lock);
340 kif->kf_un.kf_eventfd.kf_eventfd_value = efd->efd_count;
341 kif->kf_un.kf_eventfd.kf_eventfd_flags = efd->efd_flags;
342 kif->kf_un.kf_eventfd.kf_eventfd_addr = (uintptr_t)efd;
343 mtx_unlock(&efd->efd_lock);