Xenomai  3.0-rc3
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 
96  struct list_head link;
97  struct list_head *container;
98 
100  sigset_t sigpending;
101  struct list_head sigqueues[_NSIG]; /* cobalt_sigpending */
102  struct xnsynch sigwait;
103  struct list_head signext;
104 
106  struct xnsynch monitor_synch;
107  struct list_head monitor_link;
108 
109  struct cobalt_local_hkey hkey;
110 };
111 
112 struct cobalt_sigwait_context {
113  struct xnthread_wait_context wc;
114  sigset_t *set;
115  struct siginfo *si;
116 };
117 
118 static inline struct cobalt_thread *cobalt_current_thread(void)
119 {
120  struct xnthread *curr = xnthread_current();
121  return curr ? container_of(curr, struct cobalt_thread, threadbase) : NULL;
122 }
123 
124 int __cobalt_thread_create(unsigned long pth, int policy,
125  struct sched_param_ex __user *u_param,
126  int xid, __u32 __user *u_winoff);
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 __user *u_policy,
136  struct sched_param_ex *param_ex);
137 
138 struct cobalt_thread *cobalt_thread_find(pid_t pid);
139 
140 struct cobalt_thread *cobalt_thread_find_local(pid_t pid);
141 
142 struct cobalt_thread *cobalt_thread_lookup(unsigned long pth);
143 
144 COBALT_SYSCALL_DECL(thread_create,
145  (unsigned long pth, int policy,
146  struct sched_param_ex __user *u_param,
147  int xid, __u32 __user *u_winoff));
148 
149 struct cobalt_thread *
150 cobalt_thread_shadow(struct task_struct *p,
151  struct cobalt_local_hkey *lhkey,
152  __u32 __user *u_winoff);
153 
154 COBALT_SYSCALL_DECL(thread_setmode,
155  (int clrmask, int setmask, int __user *u_mode_r));
156 
157 COBALT_SYSCALL_DECL(thread_setname,
158  (unsigned long pth, const char __user *u_name));
159 
160 COBALT_SYSCALL_DECL(thread_kill, (unsigned long pth, int sig));
161 
162 COBALT_SYSCALL_DECL(thread_join, (unsigned long pth));
163 
164 COBALT_SYSCALL_DECL(thread_getpid, (unsigned long pth));
165 
166 COBALT_SYSCALL_DECL(thread_getstat,
167  (pid_t pid, struct cobalt_threadstat __user *u_stat));
168 
169 COBALT_SYSCALL_DECL(thread_setschedparam_ex,
170  (unsigned long pth,
171  int policy,
172  const struct sched_param_ex __user *u_param,
173  __u32 __user *u_winoff,
174  int __user *u_promoted));
175 
176 COBALT_SYSCALL_DECL(thread_getschedparam_ex,
177  (unsigned long pth,
178  int __user *u_policy,
179  struct sched_param_ex __user *u_param));
180 
181 void cobalt_thread_map(struct xnthread *curr);
182 
183 struct xnthread_personality *cobalt_thread_exit(struct xnthread *curr);
184 
185 struct xnthread_personality *cobalt_thread_finalize(struct xnthread *zombie);
186 
187 #ifdef CONFIG_XENO_OPT_COBALT_EXTENSION
188 
189 int cobalt_thread_extend(struct cobalt_extension *ext,
190  void *priv);
191 
192 void cobalt_thread_restrict(void);
193 
194 static inline
195 int cobalt_thread_extended_p(const struct cobalt_thread *thread,
196  const struct cobalt_extension *ext)
197 {
198  return thread->extref.extension == ext;
199 }
200 
201 #else /* !CONFIG_XENO_OPT_COBALT_EXTENSION */
202 
203 static inline
204 int cobalt_thread_extended_p(const struct cobalt_thread *thread,
205  const struct cobalt_extension *ext)
206 {
207  return 0;
208 }
209 
210 #endif /* !CONFIG_XENO_OPT_COBALT_EXTENSION */
211 
212 extern xnticks_t cobalt_time_slice;
213 
214 #endif /* !_COBALT_POSIX_THREAD_H */
static struct xnthread * xnthread_current(void)
Retrieve the current Cobalt core TCB.
Definition: thread.h:352