eventfd: Add eventfd_signal()
The `eventfd_signal()` function is the equivalent to a write to an eventfd file descriptor: it bumps the internal counter and wakes up processes waiting for it. `eventfd_signal()` is meant to be used by kernel drivers. DRM drivers will call it through linuxkpi. Reviewed by: markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D50850
This commit is contained in:
+22
-3
@@ -157,6 +157,27 @@ eventfd_put(struct eventfd *efd)
|
||||
free(efd, M_EVENTFD);
|
||||
}
|
||||
|
||||
static void
|
||||
eventfd_wakeup(struct eventfd *efd)
|
||||
{
|
||||
KNOTE_LOCKED(&efd->efd_sel.si_note, 0);
|
||||
selwakeup(&efd->efd_sel);
|
||||
wakeup(&efd->efd_count);
|
||||
}
|
||||
|
||||
void
|
||||
eventfd_signal(struct eventfd *efd)
|
||||
{
|
||||
mtx_lock(&efd->efd_lock);
|
||||
|
||||
if (efd->efd_count < UINT64_MAX)
|
||||
efd->efd_count++;
|
||||
|
||||
eventfd_wakeup(efd);
|
||||
|
||||
mtx_unlock(&efd->efd_lock);
|
||||
}
|
||||
|
||||
static int
|
||||
eventfd_close(struct file *fp, struct thread *td)
|
||||
{
|
||||
@@ -244,9 +265,7 @@ eventfd_write(struct file *fp, struct uio *uio, struct ucred *active_cred,
|
||||
if (error == 0) {
|
||||
MPASS(UINT64_MAX - efd->efd_count > count);
|
||||
efd->efd_count += count;
|
||||
KNOTE_LOCKED(&efd->efd_sel.si_note, 0);
|
||||
selwakeup(&efd->efd_sel);
|
||||
wakeup(&efd->efd_count);
|
||||
eventfd_wakeup(efd);
|
||||
}
|
||||
mtx_unlock(&efd->efd_lock);
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ int eventfd_create_file(struct thread *td, struct file *fp, uint32_t initval,
|
||||
int flags);
|
||||
struct eventfd *eventfd_get(struct file *fp);
|
||||
void eventfd_put(struct eventfd *efd);
|
||||
void eventfd_signal(struct eventfd *efd);
|
||||
|
||||
#else
|
||||
|
||||
|
||||
Reference in New Issue
Block a user