Xenomai  3.0.5
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 cobalt_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 struct cobalt_thread *cobalt_thread_find(pid_t pid);
143 
144 struct cobalt_thread *cobalt_thread_find_local(pid_t pid);
145 
146 struct cobalt_thread *cobalt_thread_lookup(unsigned long pth);
147 
148 COBALT_SYSCALL_DECL(thread_create,
149  (unsigned long pth, int policy,
150  struct sched_param_ex __user *u_param,
151  int xid, __u32 __user *u_winoff));
152 
153 struct cobalt_thread *
154 cobalt_thread_shadow(struct task_struct *p,
155  struct cobalt_local_hkey *lhkey,
156  __u32 __user *u_winoff);
157 
158 COBALT_SYSCALL_DECL(thread_setmode,
159  (int clrmask, int setmask, int __user *u_mode_r));
160 
161 COBALT_SYSCALL_DECL(thread_setname,
162  (unsigned long pth, const char __user *u_name));
163 
164 COBALT_SYSCALL_DECL(thread_kill, (unsigned long pth, int sig));
165 
166 COBALT_SYSCALL_DECL(thread_join, (unsigned long pth));
167 
168 COBALT_SYSCALL_DECL(thread_getpid, (unsigned long pth));
169 
170 COBALT_SYSCALL_DECL(thread_getstat,
171  (pid_t pid, struct cobalt_threadstat __user *u_stat));
172 
173 COBALT_SYSCALL_DECL(thread_setschedparam_ex,
174  (unsigned long pth,
175  int policy,
176  const struct sched_param_ex __user *u_param,
177  __u32 __user *u_winoff,
178  int __user *u_promoted));
179 
180 COBALT_SYSCALL_DECL(thread_getschedparam_ex,
181  (unsigned long pth,
182  int __user *u_policy,
183  struct sched_param_ex __user *u_param));
184 
185 void cobalt_thread_map(struct xnthread *curr);
186 
187 struct xnthread_personality *cobalt_thread_exit(struct xnthread *curr);
188 
189 struct xnthread_personality *cobalt_thread_finalize(struct xnthread *zombie);
190 
191 #ifdef CONFIG_XENO_OPT_COBALT_EXTENSION
192 
193 int cobalt_thread_extend(struct cobalt_extension *ext,
194  void *priv);
195 
196 void cobalt_thread_restrict(void);
197 
198 static inline
199 int cobalt_thread_extended_p(const struct cobalt_thread *thread,
200  const struct cobalt_extension *ext)
201 {
202  return thread->extref.extension == ext;
203 }
204 
205 #else /* !CONFIG_XENO_OPT_COBALT_EXTENSION */
206 
207 static inline
208 int cobalt_thread_extended_p(const struct cobalt_thread *thread,
209  const struct cobalt_extension *ext)
210 {
211  return 0;
212 }
213 
214 #endif /* !CONFIG_XENO_OPT_COBALT_EXTENSION */
215 
216 extern xnticks_t cobalt_time_slice;
217 
218 #endif /* !_COBALT_POSIX_THREAD_H */
static struct xnthread * xnthread_current(void)
Retrieve the current Cobalt core TCB.
Definition: thread.h:371