2 .\" This file and its contents are supplied under the terms of the
3 .\" Common Development and Distribution License ("CDDL"), version 1.0.
4 .\" You may only use this file in accordance with the terms of version
7 .\" A full copy of the text of the CDDL should have accompanied this
8 .\" source. A copy of the CDDL is also available via the Internet at
9 .\" http://www.illumos.org/license/CDDL.
12 .\" Copyright (c) 2014, Joyent, Inc. All Rights Reserved.
19 .Nd create a file descriptor for event notification
24 .Fa "unsigned int initval"
32 instance that has an associated 64-bit unsigned counter. It returns a file
33 descriptor that can be operated upon via
36 and the facilities that notify of file descriptor activity (e.g.,
39 .Xr epoll_wait 3C Ns ).
40 To dispose of the instance,
42 should be called on the file descriptor.
46 argument specifies the initial value of the 64-bit counter associated with the
47 instance. (Note that this limits the initial value to be a 32-bit quantity
48 despite the fact that the underlying counter is 64-bit.)
50 The \fIflags\fR argument specifies additional parameters for the
51 instance, and can have any of the following values:
55 Instance will be closed upon an
64 Instance will be set to be non-blocking. A
68 instance that has been initialized with
72 in lieu of blocking if the count associated with the instance is zero.
76 Provide counting semaphore semantics whereby a
78 will atomically decrement rather than atomically clear the count when it
79 becomes non-zero. See below for details on
85 The following operations can be performed upon an
91 Atomically reads and modifies the value of the 64-bit counter associated
92 with the instance. The precise semantics
95 depend on the disposition of
98 respect to the instance: if
100 was set when the instance was created,
103 .Em atomically decrement
104 the counter if (and when) it is non-zero, copying the value 1 to the eight
105 byte buffer passed to the system call; if
111 the counter if (and when) it is non-zero, copying the former value of the
112 counter to the eight byte buffer passed to the
113 system call. In either case,
115 will block if the counter is
118 if the instance was created with
119 .Sy EFD_NONBLOCK Ns ).
120 If the buffer specified to
123 eight bytes in length,
129 Atomically adds the 64-bit value pointed to by the buffer to the 64-bit
130 counter associated with the instance. If the resulting value would overflow,
133 will block until the value would not overflow
136 EAGAIN if the instance was created with
137 .Sy EFD_NONBLOCK Ns ).
138 If the buffer specified to
140 is less than eight bytes in length,
144 .It Sy poll(2), port_get(3C), epoll_wait(3C)
146 Provide notification when the 64-bit counter associated
147 with the instance is ready for reading or writing, as specified.
148 If the 64-bit value associated with the instance is non-zero,
152 will be set; if the value 1 can be added the value
161 Upon succesful completion, a file descriptor associated with the instance
162 is returned. Otherwise,
163 .Sy -1 is returned and
165 is set to indicate the error.
169 function will fail if:
177 .Pf { Sy OPEN_MAX Ns }
178 file descriptors open in the calling process.