Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Functions
eventfd.c File Reference
#include <linux/file.h>
#include <linux/poll.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/sched.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/list.h>
#include <linux/spinlock.h>
#include <linux/anon_inodes.h>
#include <linux/syscalls.h>
#include <linux/export.h>
#include <linux/kref.h>
#include <linux/eventfd.h>

Go to the source code of this file.

Data Structures

struct  eventfd_ctx
 

Functions

__u64 eventfd_signal (struct eventfd_ctx *ctx, __u64 n)
 
 EXPORT_SYMBOL_GPL (eventfd_signal)
 
struct eventfd_ctxeventfd_ctx_get (struct eventfd_ctx *ctx)
 
 EXPORT_SYMBOL_GPL (eventfd_ctx_get)
 
void eventfd_ctx_put (struct eventfd_ctx *ctx)
 
 EXPORT_SYMBOL_GPL (eventfd_ctx_put)
 
int eventfd_ctx_remove_wait_queue (struct eventfd_ctx *ctx, wait_queue_t *wait, __u64 *cnt)
 
 EXPORT_SYMBOL_GPL (eventfd_ctx_remove_wait_queue)
 
ssize_t eventfd_ctx_read (struct eventfd_ctx *ctx, int no_wait, __u64 *cnt)
 
 EXPORT_SYMBOL_GPL (eventfd_ctx_read)
 
struct fileeventfd_fget (int fd)
 
 EXPORT_SYMBOL_GPL (eventfd_fget)
 
struct eventfd_ctxeventfd_ctx_fdget (int fd)
 
 EXPORT_SYMBOL_GPL (eventfd_ctx_fdget)
 
struct eventfd_ctxeventfd_ctx_fileget (struct file *file)
 
 EXPORT_SYMBOL_GPL (eventfd_ctx_fileget)
 
struct fileeventfd_file_create (unsigned int count, int flags)
 
 SYSCALL_DEFINE2 (eventfd2, unsigned int, count, int, flags)
 
 SYSCALL_DEFINE1 (eventfd, unsigned int, count)
 

Function Documentation

struct eventfd_ctx* eventfd_ctx_fdget ( int  fd)
read

eventfd_ctx_fdget - Acquires a reference to the internal eventfd context. : [in] Eventfd file descriptor.

Returns a pointer to the internal eventfd context, otherwise the error pointers returned by the following functions:

eventfd_fget

Definition at line 330 of file eventfd.c.

struct eventfd_ctx* eventfd_ctx_fileget ( struct file file)
read

Definition at line 354 of file eventfd.c.

struct eventfd_ctx* eventfd_ctx_get ( struct eventfd_ctx ctx)
read

eventfd_ctx_get - Acquires a reference to the internal eventfd context. : [in] Pointer to the eventfd context.

Returns: In case of success, returns a pointer to the eventfd context.

Definition at line 86 of file eventfd.c.

void eventfd_ctx_put ( struct eventfd_ctx ctx)

eventfd_ctx_put - Releases a reference to the internal eventfd context. : [in] Pointer to eventfd context.

The eventfd context reference must have been previously acquired either with eventfd_ctx_get() or eventfd_ctx_fdget().

Definition at line 100 of file eventfd.c.

ssize_t eventfd_ctx_read ( struct eventfd_ctx ctx,
int  no_wait,
__u64 cnt 
)

eventfd_ctx_read - Reads the eventfd counter or wait if it is zero. : [in] Pointer to eventfd context. : [in] Different from zero if the operation should not block. : [out] Pointer to the 64-bit counter value.

Returns %0 if successful, or the following error codes:

-EAGAIN : The operation would have blocked but was non-zero. -ERESTARTSYS : A signal interrupted the wait operation.

If is zero, the function might sleep until the eventfd internal counter becomes greater than zero.

Definition at line 184 of file eventfd.c.

int eventfd_ctx_remove_wait_queue ( struct eventfd_ctx ctx,
wait_queue_t wait,
__u64 cnt 
)

eventfd_ctx_remove_wait_queue - Read the current counter and removes wait queue. : [in] Pointer to eventfd context. : [in] Wait queue to be removed. : [out] Pointer to the 64-bit counter value.

Returns %0 if successful, or the following error codes:

-EAGAIN : The operation would have blocked.

This is used to atomically remove a wait queue entry from the eventfd wait queue head, and read/reset the counter value.

Definition at line 154 of file eventfd.c.

struct file* eventfd_fget ( int  fd)
read

eventfd_fget - Acquire a reference of an eventfd file descriptor. : [in] Eventfd file descriptor.

Returns a pointer to the eventfd file structure in case of success, or the following error pointer:

-EBADF : Invalid file descriptor. -EINVAL : The file descriptor is not an eventfd file.

Definition at line 305 of file eventfd.c.

struct file* eventfd_file_create ( unsigned int  count,
int  flags 
)
read

eventfd_file_create - Creates an eventfd file pointer. : Initial eventfd counter value. : Flags for the eventfd file.

This function creates an eventfd file pointer, w/out installing it into the fd table. This is useful when the eventfd file is used during the initialization of data structures that require extra setup after the eventfd creation. So the eventfd creation is split into the file pointer creation phase, and the file descriptor installation phase. In this way races with userspace closing the newly installed file descriptor can be avoided. Returns an eventfd file pointer, or a proper error pointer.

Definition at line 377 of file eventfd.c.

__u64 eventfd_signal ( struct eventfd_ctx ctx,
__u64  n 
)

eventfd_signal - Adds
to the eventfd counter. : [in] Pointer to the eventfd context.
: [in] Value of the counter to be added to the eventfd internal counter. The value cannot be negative.

This function is supposed to be called by the kernel in paths that do not allow sleeping. In this function we allow the counter to reach the ULLONG_MAX value, and we signal this as overflow condition by returining a POLLERR to poll(2).

Returns the amount by which the counter was incrememnted. This will be less than
if the counter has overflowed.

Definition at line 52 of file eventfd.c.

EXPORT_SYMBOL_GPL ( eventfd_signal  )
EXPORT_SYMBOL_GPL ( eventfd_ctx_get  )
EXPORT_SYMBOL_GPL ( eventfd_ctx_put  )
EXPORT_SYMBOL_GPL ( eventfd_ctx_remove_wait_queue  )
EXPORT_SYMBOL_GPL ( eventfd_ctx_read  )
EXPORT_SYMBOL_GPL ( eventfd_fget  )
EXPORT_SYMBOL_GPL ( eventfd_ctx_fdget  )
EXPORT_SYMBOL_GPL ( eventfd_ctx_fileget  )
SYSCALL_DEFINE1 ( eventfd  ,
unsigned  int,
count   
)

Definition at line 431 of file eventfd.c.

SYSCALL_DEFINE2 ( eventfd2  ,
unsigned  int,
count  ,
int  ,
flags   
)

Definition at line 406 of file eventfd.c.