Version:  2.0.40 2.2.26 2.4.37 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18 3.19 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7

Linux/fs/eventfd.c

  1 /*
  2  *  fs/eventfd.c
  3  *
  4  *  Copyright (C) 2007  Davide Libenzi <davidel@xmailserver.org>
  5  *
  6  */
  7 
  8 #include <linux/file.h>
  9 #include <linux/poll.h>
 10 #include <linux/init.h>
 11 #include <linux/fs.h>
 12 #include <linux/sched.h>
 13 #include <linux/kernel.h>
 14 #include <linux/slab.h>
 15 #include <linux/list.h>
 16 #include <linux/spinlock.h>
 17 #include <linux/anon_inodes.h>
 18 #include <linux/syscalls.h>
 19 #include <linux/export.h>
 20 #include <linux/kref.h>
 21 #include <linux/eventfd.h>
 22 #include <linux/proc_fs.h>
 23 #include <linux/seq_file.h>
 24 
 25 struct eventfd_ctx {
 26         struct kref kref;
 27         wait_queue_head_t wqh;
 28         /*
 29          * Every time that a write(2) is performed on an eventfd, the
 30          * value of the __u64 being written is added to "count" and a
 31          * wakeup is performed on "wqh". A read(2) will return the "count"
 32          * value to userspace, and will reset "count" to zero. The kernel
 33          * side eventfd_signal() also, adds to the "count" counter and
 34          * issue a wakeup.
 35          */
 36         __u64 count;
 37         unsigned int flags;
 38 };
 39 
 40 /**
 41  * eventfd_signal - Adds @n to the eventfd counter.
 42  * @ctx: [in] Pointer to the eventfd context.
 43  * @n: [in] Value of the counter to be added to the eventfd internal counter.
 44  *          The value cannot be negative.
 45  *
 46  * This function is supposed to be called by the kernel in paths that do not
 47  * allow sleeping. In this function we allow the counter to reach the ULLONG_MAX
 48  * value, and we signal this as overflow condition by returning a POLLERR
 49  * to poll(2).
 50  *
 51  * Returns the amount by which the counter was incremented.  This will be less
 52  * than @n if the counter has overflowed.
 53  */
 54 __u64 eventfd_signal(struct eventfd_ctx *ctx, __u64 n)
 55 {
 56         unsigned long flags;
 57 
 58         spin_lock_irqsave(&ctx->wqh.