| 1 | /*- |
| 2 | * SPDX-License-Identifier: BSD-4-Clause |
| 3 | * |
| 4 | * Copyright (c) 2005 David Xu <davidxu@freebsd.org> |
| 5 | * Copyright (c) 1994 by Chris Provenzano, proven@mit.edu |
| 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in the |
| 15 | * documentation and/or other materials provided with the distribution. |
| 16 | * 3. All advertising materials mentioning features or use of this software |
| 17 | * must display the following acknowledgement: |
| 18 | * This product includes software developed by Chris Provenzano. |
| 19 | * 4. The name of Chris Provenzano may not be used to endorse or promote |
| 20 | * products derived from this software without specific prior written |
| 21 | * permission. |
| 22 | * |
| 23 | * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO ``AS IS'' AND |
| 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 26 | * ARE DISCLAIMED. IN NO EVENT SHALL CHRIS PROVENZANO BE LIABLE FOR ANY |
| 27 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 29 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 33 | * SUCH DAMAGE. |
| 34 | * |
| 35 | * Description : Basic timers header. |
| 36 | */ |
| 37 | |
| 38 | #ifndef _SYS_TIMERS_H_ |
| 39 | #define _SYS_TIMERS_H_ |
| 40 | |
| 41 | #include <sys/time.h> |
| 42 | |
| 43 | #ifdef _KERNEL |
| 44 | /* |
| 45 | * Structures used to manage POSIX timers in a process. |
| 46 | */ |
| 47 | struct itimer { |
| 48 | 	struct mtx 		it_mtx; |
| 49 | 	struct sigevent		it_sigev; |
| 50 | 	struct itimerspec	it_time; |
| 51 | 	struct proc 		*it_proc; |
| 52 | 	int	it_flags; |
| 53 | 	int	it_usecount; |
| 54 | 	int	it_overrun;		/* Overruns currently accumulating */ |
| 55 | 	int	it_overrun_last;	/* Overruns associated w/ a delivery */ |
| 56 | 	int	it_clockid; |
| 57 | 	ksiginfo_t	it_ksi; |
| 58 | 	struct callout it_callout; |
| 59 | }; |
| 60 | |
| 61 | #define	ITF_DELETING	0x01 |
| 62 | #define	ITF_WANTED	0x02 |
| 63 | #define	ITF_PSTOPPED	0x04 |
| 64 | |
| 65 | #define	TIMER_MAX	32 |
| 66 | |
| 67 | #define	ITIMER_LOCK(it)		mtx_lock(&(it)->it_mtx) |
| 68 | #define	ITIMER_UNLOCK(it)	mtx_unlock(&(it)->it_mtx) |
| 69 | |
| 70 | struct	itimers { |
| 71 | 	struct itimer		*its_timers[TIMER_MAX]; |
| 72 | }; |
| 73 | |
| 74 | struct	kclock { |
| 75 | 	int (*timer_create)(struct itimer *timer); |
| 76 | 	int (*timer_settime)(struct itimer * timer, int flags, |
| 77 | 		struct itimerspec * new_value, |
| 78 | 		struct itimerspec * old_value); |
| 79 | 	int (*timer_delete)(struct itimer * timer); |
| 80 | 	int (*timer_gettime)(struct itimer * timer, |
| 81 | 		struct itimerspec * cur_value); |
| 82 | }; |
| 83 | |
| 84 | void	itimers_exec(struct proc *p); |
| 85 | void	itimers_exit(struct proc *p); |
| 86 | int	itimer_accept(struct proc *p, int tid, ksiginfo_t *ksi); |
| 87 | #endif |
| 88 | #endif /* !_SYS_TIMERS_H_ */ |