]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sys/umtxvar.h
umtx: Expose struct abs_timeout to the rest of the kernel.
[FreeBSD/FreeBSD.git] / sys / sys / umtxvar.h
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2002, Jeffrey Roberson <jeff@freebsd.org>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice unmodified, this list of conditions, and the following
12  *    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  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  *
30  */
31
32 #ifndef _SYS_UMTXVAR_H_
33 #define _SYS_UMTXVAR_H_
34
35 #ifdef _KERNEL
36
37 /*
38  * The umtx_key structure is used by both the Linux futex code and the
39  * umtx implementation to map userland addresses to unique keys.
40  */
41 enum {
42         TYPE_SIMPLE_WAIT,
43         TYPE_CV,
44         TYPE_SEM,
45         TYPE_SIMPLE_LOCK,
46         TYPE_NORMAL_UMUTEX,
47         TYPE_PI_UMUTEX,
48         TYPE_PP_UMUTEX,
49         TYPE_RWLOCK,
50         TYPE_FUTEX,
51         TYPE_SHM,
52         TYPE_PI_ROBUST_UMUTEX,
53         TYPE_PP_ROBUST_UMUTEX,
54 };
55
56 /* Key to represent a unique userland synchronous object */
57 struct umtx_key {
58         int     hash;
59         int     type;
60         int     shared;
61         union {
62                 struct {
63                         struct vm_object *object;
64                         uintptr_t       offset;
65                 } shared;
66                 struct {
67                         struct vmspace  *vs;
68                         uintptr_t       addr;
69                 } private;
70                 struct {
71                         void            *a;
72                         uintptr_t       b;
73                 } both;
74         } info;
75 };
76
77 #define THREAD_SHARE            0
78 #define PROCESS_SHARE           1
79 #define AUTO_SHARE              2
80
81 struct umtx_abs_timeout {
82         int clockid;
83         bool is_abs_real;       /* TIMER_ABSTIME && CLOCK_REALTIME* */
84         struct timespec cur;
85         struct timespec end;
86 };
87
88 struct thread;
89
90 static inline int
91 umtx_key_match(const struct umtx_key *k1, const struct umtx_key *k2)
92 {
93
94         return (k1->type == k2->type &&
95             k1->info.both.a == k2->info.both.a &&
96             k1->info.both.b == k2->info.both.b);
97 }
98
99 void umtx_abs_timeout_init(struct umtx_abs_timeout *, int, int,
100     const struct timespec *);
101 int umtx_copyin_timeout(const void *, struct timespec *);
102 void umtx_exec(struct proc *p);
103 int umtx_key_get(const void *, int, int, struct umtx_key *);
104 void umtx_key_release(struct umtx_key *);
105 struct umtx_q *umtxq_alloc(void);
106 void umtxq_free(struct umtx_q *);
107 int kern_umtx_wake(struct thread *, void *, int, int);
108 void umtx_pi_adjust(struct thread *, u_char);
109 void umtx_thread_init(struct thread *);
110 void umtx_thread_fini(struct thread *);
111 void umtx_thread_alloc(struct thread *);
112 void umtx_thread_exit(struct thread *);
113
114 #endif /* _KERNEL */
115 #endif /* !_SYS_UMTXVAR_H_ */