9 #include <linux/poll.h>
12 #include <linux/sched.h>
13 #include <linux/kernel.h>
14 #include <linux/slab.h>
15 #include <linux/list.h>
19 #include <linux/export.h>
60 if (waitqueue_active(&ctx->
wqh))
62 spin_unlock_irqrestore(&ctx->
wqh.
lock, flags);
73 static void eventfd_free(
struct kref *
kref)
77 eventfd_free_ctx(ctx);
102 kref_put(&ctx->
kref, eventfd_free);
121 poll_wait(file, &ctx->
wqh, wait);
130 spin_unlock_irqrestore(&ctx->
wqh.
lock, flags);
160 eventfd_ctx_do_read(ctx, cnt);
161 __remove_wait_queue(&ctx->
wqh, wait);
162 if (*cnt != 0 && waitqueue_active(&ctx->
wqh))
164 spin_unlock_irqrestore(&ctx->
wqh.
lock, flags);
166 return *cnt != 0 ? 0 : -
EAGAIN;
195 __add_wait_queue(&ctx->
wqh, &wait);
198 if (ctx->
count > 0) {
206 spin_unlock_irq(&ctx->
wqh.
lock);
210 __remove_wait_queue(&ctx->
wqh, &wait);
214 eventfd_ctx_do_read(ctx, cnt);
215 if (waitqueue_active(&ctx->
wqh))
218 spin_unlock_irq(&ctx->
wqh.
lock);
224 static ssize_t eventfd_read(
struct file *file,
char __user *
buf,
size_t count,
231 if (count <
sizeof(cnt))
240 static ssize_t eventfd_write(
struct file *file,
const char __user *buf,
size_t count,
248 if (count <
sizeof(ucnt))
259 __add_wait_queue(&ctx->
wqh, &wait);
270 spin_unlock_irq(&ctx->
wqh.
lock);
274 __remove_wait_queue(&ctx->
wqh, &wait);
279 if (waitqueue_active(&ctx->
wqh))
282 spin_unlock_irq(&ctx->
wqh.
lock);
288 .release = eventfd_release,
289 .poll = eventfd_poll,
290 .read = eventfd_read,
291 .write = eventfd_write,
311 return ERR_PTR(-
EBADF);
312 if (file->
f_op != &eventfd_fops) {
356 if (file->
f_op != &eventfd_fops)
393 kref_init(&ctx->
kref);
401 eventfd_free_ctx(ctx);
418 error = PTR_ERR(file);
419 goto err_put_unused_fd;