MCPcopy Create free account
hub / github.com/F-Stack/f-stack / eventfd_read

Function eventfd_read

freebsd/kern/sys_eventfd.c:147–187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

145}
146
147static int
148eventfd_read(struct file *fp, struct uio *uio, struct ucred *active_cred,
149 int flags, struct thread *td)
150{
151 struct eventfd *efd;
152 eventfd_t count;
153 int error;
154
155 if (uio->uio_resid < sizeof(eventfd_t))
156 return (EINVAL);
157
158 error = 0;
159 efd = fp->f_data;
160 mtx_lock(&efd->efd_lock);
161 while (error == 0 && efd->efd_count == 0) {
162 if ((fp->f_flag & FNONBLOCK) != 0) {
163 mtx_unlock(&efd->efd_lock);
164 return (EAGAIN);
165 }
166 error = mtx_sleep(&efd->efd_count, &efd->efd_lock, PCATCH,
167 "efdrd", 0);
168 }
169 if (error == 0) {
170 MPASS(efd->efd_count > 0);
171 if ((efd->efd_flags & EFD_SEMAPHORE) != 0) {
172 count = 1;
173 --efd->efd_count;
174 } else {
175 count = efd->efd_count;
176 efd->efd_count = 0;
177 }
178 KNOTE_LOCKED(&efd->efd_sel.si_note, 0);
179 selwakeup(&efd->efd_sel);
180 wakeup(&efd->efd_count);
181 mtx_unlock(&efd->efd_lock);
182 error = uiomove(&count, sizeof(eventfd_t), uio);
183 } else
184 mtx_unlock(&efd->efd_lock);
185
186 return (error);
187}
188
189static int
190eventfd_write(struct file *fp, struct uio *uio, struct ucred *active_cred,

Callers

nothing calls this directly

Calls 5

selwakeupFunction · 0.85
mtx_lockFunction · 0.70
mtx_unlockFunction · 0.70
wakeupFunction · 0.70
uiomoveFunction · 0.70

Tested by

no test coverage detected