1 // -----------------------------------------------------------------------
2 // Copyright (C) 2006 - 2007 FRESCOR consortium partners:
4 // Universidad de Cantabria, SPAIN
5 // University of York, UK
6 // Scuola Superiore Sant'Anna, ITALY
7 // Kaiserslautern University, GERMANY
8 // Univ. Politecnica Valencia, SPAIN
9 // Czech Technical University in Prague, CZECH REPUBLIC
11 // Thales Communication S.A. FRANCE
12 // Visual Tools S.A. SPAIN
13 // Rapita Systems Ltd UK
16 // See http://www.frescor.org for a link to partners' websites
18 // FRESCOR project (FP6/2005/IST/5-034026) is funded
19 // in part by the European Union Sixth Framework Programme
20 // The European Union is not liable of any use that may be
23 // This file is part of the FRSH implementation
25 // FRSH is free software; you can redistribute it and/or modify
26 // it under the terms of the GNU General Public License as published by
27 // the Free Software Foundation; either version 2, or (at your option)
30 // FRSH is distributed in the hope that it will be useful, but
31 // WITHOUT ANY WARRANTY; without even the implied warranty of
32 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33 // General Public License for more details.
35 // You should have received a copy of the GNU General Public License
36 // distributed with FRSH; see file COPYING. If not, write to the
37 // Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
40 // As a special exception, if you include this header file into source
41 // files to be compiled, this header file does not by itself cause
42 // the resulting executable to be covered by the GNU General Public
43 // License. This exception does not however invalidate any other
44 // reasons why the executable file might be covered by the GNU General
46 // -----------------------------------------------------------------------
47 //fosa_thread_and_signals.h
48 //==============================================
49 // ******** ****** ******** **********
50 // **///// /** ** **////// /** /**
51 // ** /** ** /** /** /**
52 // ******* /** ** /********* /**********
53 // **//// /** ** ////////** /**//////**
54 // ** /** ** /** /** /**
55 // ** /** ** ******** /** /**
56 // // /******/ //////// // //
58 // FOSA(Frescor Operating System Adaptation layer)
59 //================================================
62 #ifndef FOSA_THREAD_AND_SIGNALS_H_
63 #define FOSA_THREAD_AND_SIGNALS_H_
66 * @defgroup threadandsignals Thread and Signals
68 * This module defines the functions that manipulate frsh_threads and
69 * frsh_signals inside FRSH implementation.
71 * Applications can refer to FRSH threads but they cannot create them
72 * directly, instead they must use frsh_thread_create*() which in turn
73 * use fosa_thread_create().
75 * For signals, application threads cannot signal them but only wait
83 /*************************
84 * Thread identification
85 *************************/
90 * Compare two thread identifiers to determine if they refer to the
93 bool fosa_thread_equal(frsh_thread_id_t t1, frsh_thread_id_t t2);
99 * Return the thread id of the calling thread
101 frsh_thread_id_t fosa_thread_self();
104 /*************************
105 * Thread creation and termination
106 *************************/
109 * fosa_thread_create()
111 * This function creates a new thread using the attributes specified
112 * in attr. If attr is NULL, default attributes are used. The new
113 * thread starts running immediately, executing the function specified
114 * by code, with an argument equal to arg. Upon successful return, the
115 * variable pointed to by tid will contain the identifier of the newly
116 * created thread. The set of signals that may be synchronously
117 * accepted is inherited from the parent thread.
119 * Returns 0 if successful; otherwise it returs a code error:
121 * EAGAIN: the system lacks the necessary resources to create a
122 * new thread or the maximum number of threads has been
125 * EINVAL: the value specified by attr is invalid (for instance,
126 * it has not been correctly initialized)
128 * EREJECT: the cretion of the thread was rejected by the frsh scheduler
129 * possibly because of incorrect attributes, or because the
130 * requested minimum capacity cannot be guaranteed
133 int fosa_thread_create
134 (frsh_thread_id_t *tid, const frsh_thread_attr_t *attr,
135 frsh_thread_code_t code, void * arg);
139 * Note: no thread termination primitive is provided. The termination
140 * of a thread will be notifoed by the system to the FRSH scheduler
141 * through the scheduler API
145 /**************************************************
146 * Thread-specific data
147 * (extended with access from a different thread)
149 * Several data items (pointers) may be associated with each thread
150 * Each item is identified through a key, an integer value between 0
151 * and FOSA_MAX_KEYS-1. The caller is responsible of allocating and
152 * deallocating the memory area pointed to by the pointer
153 **************************************************/
156 * fosa_thread_set_specific_data()
158 * Set thread-specific data
160 * For the thread identified by tid, the thread-specifid data field
161 * identified by key will be set to the value specified by value
163 * Returns 0 if successful; otherwise, an error code is returned
164 * EINVAL: the value of key is not between 0 and FOSA_MAX_KEYS-1
166 * Alternatively, in case of error the implementation is allowed to
167 * notify it to the system console and then terminate the FRSH
168 * implementation and dependant applications
170 int fosa_thread_set_specific_data
171 (int key, frsh_thread_id_t tid, const void * value);
174 * fosa_thread_get_specific_data()
176 * Get thread-specific data
178 * For the thread identified by tid, the thread-specifid data field
179 * identified by key will be copied to the variable pointed to by value
181 * Returns 0 if successful; otherwise, an error code is returned
182 * EINVAL: the value of key is not between 0 and FOSA_MAX_KEYS-1
184 * Alternatively, in case of error the implementation is allowed to
185 * notify it to the system console and then terminate the FRSH
186 * implementation and dependant applications
188 int fosa_thread_get_specific_data(int key, frsh_thread_id_t tid,
192 /******************************************************************
195 * This implementation of FRSH assumes an underlying fixed priority
196 * scheduler with priorities in a range, with a minimum and a
197 * maximumm, a number of priority levels with at least 31
198 * priorities. A larger number implies a larger priority. In systems
199 * in which the underlying scheduler uses the opposite convention, a
200 * mapping is automatically provided by the OS adaptation layer.
201 *******************************************************************/
204 * fosa_get_priority_max()
206 * Return the maximum priority value used in this implementation
208 int fosa_get_priority_max();
211 * fosa_get_priority_min()
213 * Return the minimum priority value used in this implementation
215 int fosa_get_priority_min();
218 * fosa_thread_attr_set_prio()
220 * Change the priority of a thread attributes object
222 * The priority of the thread attriutes object specified by attr is
223 * set to the value specified by prio. This function has no runtime
224 * effect on the priority, except when the attributes object is used
225 * to create a thread, when it will be created with the specified
228 * Returns 0 if successful, or the following error code:
229 * EINVAL: the specified priority value is not between the
230 * minimum and the maximum priorities defined in this
231 * FRSH implementation
232 * Alternatively, in case of error the implementation is allowed to
233 * notify it to the system console and then terminate the FRSH
234 * implementation and dependant applications
236 int fosa_thread_attr_set_prio(frsh_thread_attr_t *attr, int prio);
239 * frsh_thread_attr_get_prio()
241 * Get the priority from a thread attributes object
243 * This function sets the variable pointed to by prio to the
244 * priority stored in the thread attributes object attr.
248 int frsh_thread_attr_get_prio
249 (const frsh_thread_attr_t *attr, size_t *prio);
252 * fosa_thread_set_prio()
254 * Dynamically change the priority of a thread
256 * The priority of the thread identified by tid is
257 * set to the value specified by prio.
259 * Returns 0 if successful, or the following error code:
260 * EINVAL: the specified priority value is not between the
261 * minimum and the maximum priorities defined in this
262 * FRSH implementation
263 * Alternatively, in case of error the implementation is allowed to
264 * notify it to the system console and then terminate the FRSH
265 * implementation and dependant applications
267 int fosa_thread_set_prio(frsh_thread_id_t tid, int prio);
270 * fosa_thread_get_prio()
272 * Dynamically get the priority of a thread
274 * This function sets the variable pointed to by prio to the
275 * priority of the thread identified by tid
279 int fosa_thread_get_prio (frsh_thread_id_t tid, int *prio);
283 /*******************************************************************
286 * Signals represent events that may be notified by the system, or
287 * sent explicitly by the application, and for which a thread may
288 * synchronously wait. Signals carry an associated piece of
289 * information (an integer or a pointer) and are queued until they are
290 * accepted. Signals are identified by an integer signal number (of
291 * the type frsh_signal_t) in the range FOSA_SIGNAL_MIN,
292 * FOSA_SIGNAL_MAX. This range is required to have at least <tbd>
294 *******************************************************************/
297 * fosa_set_accepted_signals()
299 * Establish the set of signals that may be synchronously accepted
300 * by the calling thread
302 * The function uses the array of signal numbers specified by set,
303 * which must be of size equal to size
305 * Returns 0 if successful; otherwise it returns an error code:
306 * EINVAL: the array contains one or more values which are not
307 * between FOSA_SIGNAL_MIN and FOSA_SIGNAL_MAX, or size
310 * Alternatively, in case of error the implementation is allowed to
311 * notify it to the system console and then terminate the FRSH
312 * implementation and dependant applications
314 int frsh_set_accepted_signals(frsh_signal_t set[], int size);
317 * fosa_signal_queue()
321 * This function is used to explicitly send a signal with a specified
324 * The signal number specified by signal is sent together with the
325 * information specified by info, to the thread identified by
326 * receiver. In those implementations that do not support queueing a
327 * signal with information to a thread (such as POSIX), the signal may
328 * be sent to any thread that is waiting for this signal via
329 * fosa_signal_wait(). Portability can be ensured by having the receiver
330 * thread be the one who is waiting for the signal.
332 * Returns 0 if successful; otherwise it returns an error code:
333 * EINVAL: the signal specified by signal is not
334 * between FOSA_SIGNAL_MIN and FOSA_SIGNAL_MAX
336 * EAGAIN: no resources are available to queue the signal; the
337 * maximum number of queued signals has been reached, or a
338 * systemwide resource limit has been exceeded
340 * Alternatively, in case of error the implementation is allowed to
341 * notify it to the system console and then terminate the FRSH
342 * implementation and dependant applications
344 int fosa_signal_queue
345 (frsh_signal_t signal, frsh_signal_info_t info,
346 frsh_thread_id_t receiver);
354 * The function waits for the arrival of one of the signals in the
355 * array of signal numbers specified by set, which must be of size
356 * equal to size. If there is a signal already queued, the function
357 * returns immediately. If there is no signal of the specified set
358 * queued, the calling thread is suspended until a signal from that
359 * set arrives. Upon return, if signal_received is not NULL the number
360 * of the signal received is stored in the variable pointed to by
361 * signal_received; and if info is not NULL the associated information
362 * is stored in the variable pointed to by info.
364 * Returns 0 if successful; otherwise it returns an error code:
365 * EINVAL: the array contains one or more values which are not
366 * between FOSA_SIGNAL_MIN and FOSA_SIGNAL_MAX, or size
369 * Alternatively, in case of error the implementation is allowed to
370 * notify it to the system console and then terminate the FRSH
371 * implementation and dependant applications
374 (frsh_signal_t set[], int size, frsh_signal_t *signal_received,
375 frsh_signal_info_t *info);
378 * fosa_signal_timedwait()
380 * Timed wait for a signal
382 * This function behaves the same as fosa_signal_wait(), except that
383 * the suspension time is limited to the time interval specified in
384 * the timespec structure referenced by timeout.
386 * Returns 0 if successful; otherwise it returns an error code:
387 * EINVAL: the array contains one or more values which are not
388 * between FOSA_SIGNAL_MIN and FOSA_SIGNAL_MAX, or size
389 * is less than 0, or timeout is invalid
390 * EAGAIN: The timeout expired
392 * Alternatively, in case of the EINVAL error the implementation is
393 * allowed to notify it to the system console and then terminate the
394 * FRSH implementation and dependant applications
396 int fosa_signal_timedwait
397 (frsh_signal_t set[], int size, frsh_signal_t *signal_received,
398 frsh_signal_info_t *info, const struct timespec *timeout);
403 #endif /* !FOSA_THREAD_AND_SIGNALS_H_ */