| 145 | } |
| 146 | |
| 147 | static int |
| 148 | eventfd_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 | |
| 189 | static int |
| 190 | eventfd_write(struct file *fp, struct uio *uio, struct ucred *active_cred, |
nothing calls this directly
no test coverage detected