Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177859296
D50849.1795448037.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
D50849.1795448037.diff
View Options
Index: sys/kern/sys_eventfd.c
===================================================================
--- sys/kern/sys_eventfd.c
+++ sys/kern/sys_eventfd.c
@@ -40,6 +40,7 @@
#include <sys/mutex.h>
#include <sys/poll.h>
#include <sys/proc.h>
+#include <sys/refcount.h>
#include <sys/selinfo.h>
#include <sys/stat.h>
#include <sys/uio.h>
@@ -99,6 +100,7 @@
uint32_t efd_flags;
struct selinfo efd_sel;
struct mtx efd_lock;
+ int32_t efd_refcount;
};
int
@@ -116,6 +118,7 @@
efd->efd_count = initval;
mtx_init(&efd->efd_lock, "eventfd", NULL, MTX_DEF);
knlist_init_mtx(&efd->efd_sel.si_note, &efd->efd_lock);
+ refcount_init(&efd->efd_refcount, 1);
fflags = FREAD | FWRITE;
if ((flags & EFD_NONBLOCK) != 0)
@@ -125,16 +128,39 @@
return (0);
}
-static int
-eventfd_close(struct file *fp, struct thread *td)
+struct eventfd_ctx *
+eventfd_get(struct file *fp)
{
struct eventfd_ctx *efd;
+ if (fp->f_data == NULL || fp->f_ops != &eventfdops)
+ return (NULL);
+
efd = fp->f_data;
+ refcount_acquire(&efd->efd_refcount);
+
+ return (efd);
+}
+
+void
+eventfd_put(struct eventfd_ctx *efd)
+{
+ if (!refcount_release(&efd->efd_refcount))
+ return;
+
seldrain(&efd->efd_sel);
knlist_destroy(&efd->efd_sel.si_note);
mtx_destroy(&efd->efd_lock);
free(efd, M_EVENTFD);
+}
+
+static int
+eventfd_close(struct file *fp, struct thread *td)
+{
+ struct eventfd_ctx *efd;
+
+ efd = fp->f_data;
+ eventfd_put(efd);
return (0);
}
Index: sys/sys/eventfd.h
===================================================================
--- sys/sys/eventfd.h
+++ sys/sys/eventfd.h
@@ -38,8 +38,12 @@
#ifdef _KERNEL
+struct eventfd_ctx;
+
int eventfd_create_file(struct thread *td, struct file *fp, uint32_t initval,
int flags);
+struct eventfd_ctx *eventfd_get(struct file *fp);
+void eventfd_put(struct eventfd_ctx *efd);
#else
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 23, 3:33 PM (19 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41934115
Default Alt Text
D50849.1795448037.diff (1 KB)
Attached To
Mode
D50849: eventfd: Add refcounting
Attached
Detach File
Event Timeline