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