xref: /netbsd/sys/sys/timerfd.h (revision 62a4294c)
1 /*	$NetBSD: timerfd.h,v 1.3 2021/09/21 13:51:46 ryoon Exp $	*/
2 
3 /*-
4  * Copyright (c) 2020 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jason R. Thorpe.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _SYS_TIMERFD_H_
33 #define	_SYS_TIMERFD_H_
34 
35 #include <sys/fcntl.h>
36 #include <sys/ioccom.h>
37 #include <sys/time.h>
38 
39 /*
40  * Definitions for timerfd_create(2) / timerfd_gettime(2) / timerfd_settime(2).
41  * This implementation is API compatible with the Linux interface.
42  */
43 
44 #define	TFD_TIMER_ABSTIME	O_WRONLY
45 #define	TFD_TIMER_CANCEL_ON_SET	O_RDWR
46 #define	TFD_CLOEXEC		O_CLOEXEC
47 #define	TFD_NONBLOCK		O_NONBLOCK
48 
49 #define	TFD_IOC_SET_TICKS	_IOW('T', 0, uint64_t)
50 
51 #ifdef _KERNEL
52 struct lwp;
53 int	do_timerfd_create(struct lwp *, clockid_t, int, register_t *);
54 int	do_timerfd_gettime(struct lwp *, int, struct itimerspec *,
55 	    register_t *);
56 int	do_timerfd_settime(struct lwp *, int, int, const struct itimerspec *,
57 	    struct itimerspec *, register_t *);
58 #else /* ! _KERNEL */
59 __BEGIN_DECLS
60 int	timerfd_create(clockid_t, int);
61 int	timerfd_gettime(int, struct itimerspec *);
62 int	timerfd_settime(int, int, const struct itimerspec *,
63 	    struct itimerspec *);
64 __END_DECLS
65 #endif /* _KERNEL */
66 
67 #endif /* _SYS_TIMERFD_H_ */
68