Xenomai  3.1
thread.h
1 /*
2  * Written by Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18 #ifndef _COBALT_POSIX_THREAD_H
19 #define _COBALT_POSIX_THREAD_H
20 
21 #include <stdarg.h>
22 #include <linux/types.h>
23 #include <linux/time.h>
24 #include <linux/signal.h>
25 #include <cobalt/kernel/thread.h>
26 #include <cobalt/uapi/thread.h>
27 #include <cobalt/uapi/sched.h>
28 /* CAUTION: rtdm/cobalt.h reads this header. */
29 #include <xenomai/posix/syscall.h>
30 #include <xenomai/posix/extension.h>
31 
32 #define PTHREAD_PROCESS_PRIVATE 0
33 #define PTHREAD_PROCESS_SHARED 1
34 
35 #define PTHREAD_CREATE_JOINABLE 0
36 #define PTHREAD_CREATE_DETACHED 1
37 
38 #define PTHREAD_INHERIT_SCHED 0
39 #define PTHREAD_EXPLICIT_SCHED 1
40 
41 #define PTHREAD_MUTEX_NORMAL 0
42 #define PTHREAD_MUTEX_RECURSIVE 1
43 #define PTHREAD_MUTEX_ERRORCHECK 2
44 #define PTHREAD_MUTEX_DEFAULT 0
45 
46 struct cobalt_thread;
47 struct cobalt_threadstat;
48 
49 /*
50  * pthread_mutexattr_t and pthread_condattr_t fit on 32 bits, for
51  * compatibility with libc.
52  */
53 
54 /* The following definitions are copied from linuxthread pthreadtypes.h. */
55 struct _pthread_fastlock {
56  long int __status;
57  int __spinlock;
58 };
59 
60 typedef struct {
61  struct _pthread_fastlock __c_lock;
62  long __c_waiting;
63  char __padding[48 - sizeof (struct _pthread_fastlock)
64  - sizeof (long) - sizeof (long long)];
65  long long __align;
66 } pthread_cond_t;
67 
68 enum {
69  PTHREAD_PRIO_NONE,
70  PTHREAD_PRIO_INHERIT,
71  PTHREAD_PRIO_PROTECT
72 };
73 
74 typedef struct {
75  int __m_reserved;
76  int __m_count;
77  long __m_owner;
78  int __m_kind;
79  struct _pthread_fastlock __m_lock;
80 } pthread_mutex_t;
81 
82 struct cobalt_local_hkey {
84  unsigned long u_pth;
86  struct mm_struct *mm;
87 };
88 
89 struct cobalt_thread {
90  unsigned int magic;
91  struct xnthread threadbase;
92  struct cobalt_extref extref;
93  struct cobalt_process *process;
94  struct list_head next; /* in global/process thread_list */
95 
97  sigset_t sigpending;
98  struct list_head sigqueues[_NSIG]; /* in cobalt_sigpending */
99  struct xnsynch sigwait;
100  struct list_head signext;
101 
103  struct xnsynch monitor_synch;
104  struct list_head monitor_link;
105 
106  struct cobalt_local_hkey hkey;
107 };
108 
109 struct cobalt_sigwait_context {
110  struct xnthread_wait_context wc;
111  sigset_t *set;
112  struct siginfo *si;
113 };
114 
115 static inline struct cobalt_thread *cobalt_current_thread(void)
116 {
117  struct xnthread *curr = xnthread_current();
118  return curr ? container_of(curr, struct cobalt_thread, threadbase) : NULL;
119 }
120 
121 int __cobalt_thread_create(unsigned long pth, int policy,
122  struct sched_param_ex __user *u_param,
123  int xid, __u32 __user *u_winoff);
124 
125 int __cobalt_thread_setschedparam_ex(struct cobalt_thread *thread, int policy,
126  const struct sched_param_ex *param_ex);
127 
128 int cobalt_thread_setschedparam_ex(unsigned long pth,
129  int policy,
130  const struct sched_param_ex *param_ex,
131  __u32 __user *u_winoff,
132  int __user *u_promoted);
133 
134 int cobalt_thread_getschedparam_ex(unsigned long pth,
135  int *policy_r,
136  struct sched_param_ex *param_ex);
137 
138 int __cobalt_thread_getschedparam_ex(struct cobalt_thread *thread,
139  int *policy_r,
140  struct sched_param_ex *param_ex);
141 
142 int cobalt_thread_setschedprio(unsigned long pth,
143  int prio,
144  __u32 __user *u_winoff,
145  int __user *u_promoted);
146 
147 struct cobalt_thread *cobalt_thread_find(pid_t pid);
148 
149 struct cobalt_thread *cobalt_thread_find_local(pid_t pid);
150 
151 struct cobalt_thread *cobalt_thread_lookup(unsigned long pth);
152 
153 COBALT_SYSCALL_DECL(thread_create,
154  (unsigned long pth, int policy,
155  struct sched_param_ex __user *u_param,
156  int xid, __u32 __user *u_winoff));
157 
158 struct cobalt_thread *
159 cobalt_thread_shadow(struct cobalt_local_hkey *lhkey,
160  __u32 __user *u_winoff);
161 
162 COBALT_SYSCALL_DECL(thread_setmode,
163  (int clrmask, int setmask, int __user *u_mode_r));
164 
165 COBALT_SYSCALL_DECL(thread_setname,
166  (unsigned long pth, const char __user *u_name));
167 
168 COBALT_SYSCALL_DECL(thread_kill, (unsigned long pth, int sig));
169 
170 COBALT_SYSCALL_DECL(thread_join, (unsigned long pth));
171 
172 COBALT_SYSCALL_DECL(thread_getpid, (unsigned long pth));
173 
174 COBALT_SYSCALL_DECL(thread_getstat,
175  (pid_t pid, struct cobalt_threadstat __user *u_stat));
176 
177 COBALT_SYSCALL_DECL(thread_setschedparam_ex,
178  (unsigned long pth,
179  int policy,
180  const struct sched_param_ex __user *u_param,
181  __u32 __user *u_winoff,
182  int __user *u_promoted));
183 
184 COBALT_SYSCALL_DECL(thread_getschedparam_ex,
185  (unsigned long pth,
186  int __user *u_policy,
187  struct sched_param_ex __user *u_param));
188 
189 COBALT_SYSCALL_DECL(thread_setschedprio,
190  (unsigned long pth,
191  int prio,
192  __u32 __user *u_winoff,
193  int __user *u_promoted));
194 
195 void cobalt_thread_map(struct xnthread *curr);
196 
197 struct xnthread_personality *cobalt_thread_exit(struct xnthread *curr);
198 
199 struct xnthread_personality *cobalt_thread_finalize(struct xnthread *zombie);
200 
201 #ifdef CONFIG_XENO_OPT_COBALT_EXTENSION
202 
203 int cobalt_thread_extend(struct cobalt_extension *ext,
204  void *priv);
205 
206 void cobalt_thread_restrict(void);
207 
208 static inline
209 int cobalt_thread_extended_p(const struct cobalt_thread *thread,
210  const struct cobalt_extension *ext)
211 {
212  return thread->extref.extension == ext;
213 }
214 
215 #else /* !CONFIG_XENO_OPT_COBALT_EXTENSION */
216 
217 static inline
218 int cobalt_thread_extended_p(const struct cobalt_thread *thread,
219  const struct cobalt_extension *ext)
220 {
221  return 0;
222 }
223 
224 #endif /* !CONFIG_XENO_OPT_COBALT_EXTENSION */
225 
226 extern xnticks_t cobalt_time_slice;
227 
228 #endif /* !_COBALT_POSIX_THREAD_H */
static struct xnthread * xnthread_current(void)
Retrieve the current Cobalt core TCB.
Definition: thread.h:374