Xenomai  3.0.5
task.h
1 /*
2  * Copyright (C) 2011 Philippe Gerum <rpm@xenomai.org>.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library 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 GNU
12  * Lesser General Public License for more details.
13 
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18 #ifndef _XENOMAI_ALCHEMY_TASK_H
19 #define _XENOMAI_ALCHEMY_TASK_H
20 
21 #include <sys/types.h>
22 #include <stdint.h>
23 #include <xeno_config.h>
24 #include <boilerplate/list.h>
25 #include <copperplate/threadobj.h>
26 #include <alchemy/timer.h>
27 #include <alchemy/compat.h>
28 
35 #define T_LOPRIO 0
36 #define T_HIPRIO 99
37 
39 #define T_LOCK __THREAD_M_LOCK
40 
41 #define T_WARNSW __THREAD_M_WARNSW
42 #define T_CONFORMING __THREAD_M_CONFORMING
43 #define T_JOINABLE __THREAD_M_SPARE0
44 
45 struct RT_TASK {
46  uintptr_t handle;
47  pthread_t thread;
48 };
49 
50 typedef struct RT_TASK RT_TASK;
51 
52 struct RT_TASK_MCB {
53  int flowid;
54  int opcode;
55  union {
56  dref_type(void *) __dref;
57  void *data;
58  };
59  ssize_t size;
60 };
61 
62 typedef struct RT_TASK_MCB RT_TASK_MCB;
63 
71 struct RT_TASK_INFO {
75  int prio;
79  struct threadobj_stat stat;
83  char name[XNOBJECT_NAME_LEN];
87  pid_t pid;
88 };
89 
90 typedef struct RT_TASK_INFO RT_TASK_INFO;
91 
92 #define NO_ALCHEMY_TASK ((RT_TASK){ 0, 0 })
93 
94 #ifdef __cplusplus
95 extern "C" {
96 #endif
97 
98 CURRENT_DECL(int, rt_task_create(RT_TASK *task,
99  const char *name,
100  int stksize,
101  int prio,
102  int mode));
103 
104 int rt_task_delete(RT_TASK *task);
105 
106 int rt_task_set_affinity(RT_TASK *task,
107  const cpu_set_t *cpus);
108 
109 int rt_task_start(RT_TASK *task,
110  void (*entry)(void *arg),
111  void *arg);
112 
113 CURRENT_DECL(int, rt_task_spawn(RT_TASK *task, const char *name,
114  int stksize, int prio, int mode,
115  void (*entry)(void *arg),
116  void *arg));
117 
118 int rt_task_shadow(RT_TASK *task,
119  const char *name,
120  int prio,
121  int mode);
122 
123 int rt_task_join(RT_TASK *task);
124 
125 CURRENT_DECL(int, rt_task_set_periodic(RT_TASK *task,
126  RTIME idate, RTIME period));
127 
128 int rt_task_wait_period(unsigned long *overruns_r);
129 
130 int rt_task_sleep(RTIME delay);
131 
132 int rt_task_sleep_until(RTIME date);
133 
134 int rt_task_same(RT_TASK *task1, RT_TASK *task2);
135 
136 int rt_task_suspend(RT_TASK *task);
137 
138 int rt_task_resume(RT_TASK *task);
139 
140 RT_TASK *rt_task_self(void);
141 
142 int rt_task_set_priority(RT_TASK *task, int prio);
143 
144 int rt_task_set_mode(int clrmask, int setmask,
145  int *mode_r);
146 
147 int rt_task_yield(void);
148 
149 int rt_task_unblock(RT_TASK *task);
150 
151 int rt_task_slice(RT_TASK *task, RTIME quantum);
152 
153 int rt_task_inquire(RT_TASK *task,
154  RT_TASK_INFO *info);
155 
156 ssize_t rt_task_send_timed(RT_TASK *task,
157  RT_TASK_MCB *mcb_s, RT_TASK_MCB *mcb_r,
158  const struct timespec *abs_timeout);
159 
160 static inline
161 ssize_t rt_task_send_until(RT_TASK *task,
162  RT_TASK_MCB *mcb_s, RT_TASK_MCB *mcb_r,
163  RTIME timeout)
164 {
165  struct timespec ts;
166  return rt_task_send_timed(task, mcb_s, mcb_r,
167  alchemy_abs_timeout(timeout, &ts));
168 }
169 
170 static inline
171 ssize_t rt_task_send(RT_TASK *task,
172  RT_TASK_MCB *mcb_s, RT_TASK_MCB *mcb_r,
173  RTIME timeout)
174 {
175  struct timespec ts;
176  return rt_task_send_timed(task, mcb_s, mcb_r,
177  alchemy_rel_timeout(timeout, &ts));
178 }
179 
180 int rt_task_receive_timed(RT_TASK_MCB *mcb_r,
181  const struct timespec *abs_timeout);
182 
183 static inline
184 int rt_task_receive_until(RT_TASK_MCB *mcb_r, RTIME timeout)
185 {
186  struct timespec ts;
187  return rt_task_receive_timed(mcb_r,
188  alchemy_abs_timeout(timeout, &ts));
189 }
190 
191 static inline
192 int rt_task_receive(RT_TASK_MCB *mcb_r, RTIME timeout)
193 {
194  struct timespec ts;
195  return rt_task_receive_timed(mcb_r,
196  alchemy_rel_timeout(timeout, &ts));
197 }
198 
199 int rt_task_reply(int flowid,
200  RT_TASK_MCB *mcb_s);
201 
202 int rt_task_bind(RT_TASK *task,
203  const char *name, RTIME timeout);
204 
205 int rt_task_unbind(RT_TASK *task);
206 
207 #ifdef __cplusplus
208 }
209 #endif
210 
213 #endif /* _XENOMAI_ALCHEMY_TASK_H */
int rt_task_start(RT_TASK *task, void(*entry)(void *arg), void *arg)
Start a real-time task.
Definition: task.c:618
int rt_task_unblock(RT_TASK *task)
Unblock a real-time task.
Definition: task.c:1332
int rt_task_create(RT_TASK *task, const char *name, int stksize, int prio, int mode)
Create a task with Alchemy personality.
Definition: task.c:409
int rt_task_join(RT_TASK *task)
Wait on the termination of a real-time task.
Definition: task.c:534
static ssize_t rt_task_send(RT_TASK *task, RT_TASK_MCB *mcb_s, RT_TASK_MCB *mcb_r, RTIME timeout)
Send a message to a real-time task (with relative scalar timeout).
Definition: task.h:171
static int rt_task_receive_until(RT_TASK_MCB *mcb_r, RTIME timeout)
Receive a message from a real-time task (with absolute scalar timeout).
Definition: task.h:184
int rt_task_inquire(RT_TASK *task, RT_TASK_INFO *info)
Retrieve information about a real-time task.
Definition: task.c:1540
int rt_task_same(RT_TASK *task1, RT_TASK *task2)
Compare real-time task descriptors.
Definition: task.c:1083
RT_TASK * rt_task_self(void)
Retrieve the current task descriptor.
Definition: task.c:1208
static int rt_task_receive(RT_TASK_MCB *mcb_r, RTIME timeout)
Receive a message from a real-time task (with relative scalar timeout).
Definition: task.h:192
int rt_task_yield(void)
Manual round-robin.
Definition: task.c:1301
int rt_task_slice(RT_TASK *task, RTIME quantum)
Set a task&#39;s round-robin quantum.
Definition: task.c:1387
int rt_task_delete(RT_TASK *task)
Delete a real-time task.
Definition: task.c:476
static ssize_t rt_task_send_until(RT_TASK *task, RT_TASK_MCB *mcb_s, RT_TASK_MCB *mcb_r, RTIME timeout)
Send a message to a real-time task (with absolute scalar timeout).
Definition: task.h:161
int rt_task_set_mode(int clrmask, int setmask, int *mode_r)
Change the current task mode.
Definition: task.c:1484
int rt_task_receive_timed(RT_TASK_MCB *mcb_r, const struct timespec *abs_timeout)
Receive a message from a real-time task.
Definition: task.c:1899
int rt_task_sleep(RTIME delay)
Delay the current real-time task (with relative delay).
Definition: task.c:994
int rt_task_wait_period(unsigned long *overruns_r)
Wait for the next periodic release point.
Definition: task.c:912
Task status descriptor.
Definition: task.h:71
int rt_task_reply(int flowid, RT_TASK_MCB *mcb_s)
Reply to a remote task message.
Definition: task.c:2018
pid_t pid
Host pid.
Definition: task.h:87
int prio
Task priority.
Definition: task.h:75
ssize_t rt_task_send_timed(RT_TASK *task, RT_TASK_MCB *mcb_s, RT_TASK_MCB *mcb_r, const struct timespec *abs_timeout)
Send a message to a real-time task.
Definition: task.c:1700
int rt_task_set_affinity(RT_TASK *task, const cpu_set_t *cpus)
Set CPU affinity of real-time task.
Definition: task.c:569
int rt_task_sleep_until(RTIME date)
Delay the current real-time task (with absolute wakeup date).
Definition: task.c:952
int rt_task_bind(RT_TASK *task, const char *name, RTIME timeout)
Bind to a task.
Definition: task.c:2130
char name[XNOBJECT_NAME_LEN]
Name of task.
Definition: task.h:83
int rt_task_unbind(RT_TASK *task)
Unbind from a task.
Definition: task.c:2152
int rt_task_suspend(RT_TASK *task)
Suspend a real-time task.
Definition: task.c:1130
int rt_task_set_priority(RT_TASK *task, int prio)
Change the base priority of a real-time task.
Definition: task.c:1254
int rt_task_resume(RT_TASK *task)
Resume a real-time task.
Definition: task.c:1174
int rt_task_shadow(RT_TASK *task, const char *name, int prio, int mode)
Turn caller into a real-time task.
Definition: task.c:713
int rt_task_set_periodic(RT_TASK *task, RTIME idate, RTIME period)
Make a real-time task periodic.
Definition: task.c:828
int rt_task_spawn(RT_TASK *task, const char *name, int stksize, int prio, int mode, void(*entry)(void *arg), void *arg)
Create and start a real-time task.
Definition: task.c:1052