Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/sys_eventfd.c
Show First 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | |||||
struct eventfd { | struct eventfd { | ||||
eventfd_t efd_count; | eventfd_t efd_count; | ||||
uint32_t efd_flags; | uint32_t efd_flags; | ||||
struct selinfo efd_sel; | struct selinfo efd_sel; | ||||
struct mtx efd_lock; | struct mtx efd_lock; | ||||
}; | }; | ||||
int | int | ||||
eventfd_create_file(struct thread *td, struct file *fp, uint32_t initval, | eventfd_create_file(struct thread *td, uint32_t initval, int flags) | ||||
dchagin: This is should be a separate review/commit, please. | |||||
int flags) | |||||
{ | { | ||||
struct eventfd *efd; | struct eventfd *efd; | ||||
int fflags; | struct file *fp; | ||||
int error, fd, fflags = 0; | |||||
AUDIT_ARG_FFLAGS(flags); | AUDIT_ARG_FFLAGS(flags); | ||||
AUDIT_ARG_VALUE(initval); | AUDIT_ARG_VALUE(initval); | ||||
if ((flags & ~(EFD_CLOEXEC | EFD_NONBLOCK | EFD_SEMAPHORE)) != 0) | |||||
return (EINVAL); | |||||
if ((flags & EFD_CLOEXEC) != 0) | |||||
fflags |= O_CLOEXEC; | |||||
error = falloc_noinstall(td, &fp); | |||||
if (error != 0) | |||||
return (error); | |||||
efd = malloc(sizeof(*efd), M_EVENTFD, M_WAITOK | M_ZERO); | efd = malloc(sizeof(*efd), M_EVENTFD, M_WAITOK | M_ZERO); | ||||
efd->efd_flags = flags; | efd->efd_flags = flags; | ||||
efd->efd_count = initval; | efd->efd_count = initval; | ||||
mtx_init(&efd->efd_lock, "eventfd", NULL, MTX_DEF); | mtx_init(&efd->efd_lock, "eventfd", NULL, MTX_DEF); | ||||
knlist_init_mtx(&efd->efd_sel.si_note, &efd->efd_lock); | knlist_init_mtx(&efd->efd_sel.si_note, &efd->efd_lock); | ||||
fflags = FREAD | FWRITE; | fflags = FREAD | FWRITE; | ||||
if ((flags & EFD_NONBLOCK) != 0) | if ((flags & EFD_NONBLOCK) != 0) | ||||
fflags |= FNONBLOCK; | fflags |= FNONBLOCK; | ||||
finit(fp, fflags, DTYPE_EVENTFD, efd, &eventfdops); | finit(fp, fflags, DTYPE_EVENTFD, efd, &eventfdops); | ||||
error = finstall(td, fp, &fd, fflags, NULL); | |||||
if (error == 0) | |||||
td->td_retval[0] = fd; | |||||
fdrop(fp, td); | |||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
eventfd_close(struct file *fp, struct thread *td) | eventfd_close(struct file *fp, struct thread *td) | ||||
{ | { | ||||
struct eventfd *efd; | struct eventfd *efd; | ||||
▲ Show 20 Lines • Show All 211 Lines • Show Last 20 Lines |
This is should be a separate review/commit, please.