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 //==============================================
48 // ******** ****** ******** **********
49 // **///// /** ** **////// /** /**
50 // ** /** ** /** /** /**
51 // ******* /** ** /********* /**********
52 // **//// /** ** ////////** /**//////**
53 // ** /** ** /** /** /**
54 // ** /** ** ******** /** /**
55 // // /******/ //////// // //
57 // FOSA(Frescor Operating System Adaptation layer)
58 //================================================
62 /*************************
63 * Thread identification
64 *************************/
66 bool fosa_thread_equal(frsh_thread_id_t t1, frsh_thread_id_t t2){
67 return pthread_equal(t1,t2);
70 frsh_thread_id_t fosa_thread_self(){
71 return pthread_self();
74 /*************************
75 * Thread creation and termination
76 *************************/
78 int fosa_thread_create (frsh_thread_id_t *tid, const frsh_thread_attr_t *attr,
79 frsh_thread_code_t code, void * arg){
80 return pthread_create(tid,attr,code, arg);
84 /**************************************************
85 * Thread-specific data
86 * (extended with access from a different thread)
88 * Several data items (pointers) may be associated with each thread
89 * Each item is identified through a key, an integer value between 0
90 * and FOSA_MAX_KEYS-1. The caller is responsible of allocating and
91 * deallocating the memory area pointed to by the pointer
92 **************************************************/
94 int fosa_thread_set_specific_data (int key, frsh_thread_id_t tid,
96 if ((0<key) && (key<FOSA_MAX_KEYS-1)){
98 //pthread_setspecific_for(key, tid, value);
104 int fosa_thread_get_specific_data(int key, frsh_thread_id_t tid,
106 if ((0<key) && (key<FOSA_MAX_KEYS-1)){
107 *value=pthread_remote_getspecific(key,tid);
115 /******************************************************************
118 * This implementation of FRSH assumes an underlying fixed priority
119 * scheduler with priorities in a range, with a minimum and a
120 * maximumm, a number of priority levels with at least 31
121 * priorities. A larger number implies a larger priority. In systems
122 * in which the underlying scheduler uses the opposite convention, a
123 * mapping is automatically provided by the OS adaptation layer.
124 *******************************************************************/
126 int fosa_get_priority_max() {
127 return sched_get_priority_max(0);
130 int fosa_get_priority_min(){
131 return sched_get_priority_min(0);
134 int fosa_thread_attr_set_prio(frsh_thread_attr_t *attr, int prio) {
136 /*if ((ched_get_priority_min(0)<=prio) || (prio<=sched_get_priority_min(0))){
137 attr->sched_param.sched_priority = prio;
143 int fosa_thread_attr_get_prio (const frsh_thread_attr_t *attr, size_t *prio){
144 *prio = attr->sched_param.sched_priority;
148 int fosa_thread_set_prio(frsh_thread_id_t tid, int prio){
149 if ((sched_get_priority_min(0)<=prio) || (prio<=sched_get_priority_min(0))){
150 pthread_setschedprio(tid,prio);
156 int fosa_thread_get_prio (frsh_thread_id_t tid, int *prio){
157 *prio = tid->sched_param.sched_priority;
163 /*******************************************************************
166 * Signals represent events that may be notified by the system, or
167 * sent explicitly by the application, and for which a thread may
168 * synchronously wait. Signals carry an associated piece of
169 * information (an integer or a pointer) and are queued until they are
170 * accepted. Signals are identified by an integer signal number (of
171 * the type frsh_signal_t) in the range FOSA_SIGNAL_MIN,
172 * FOSA_SIGNAL_MAX. This range is required to have at least <tbd>
174 *******************************************************************/
176 int fosa_set_accepted_signals(frsh_signal_t set[], int size) {
179 /*rtl_sigset_t bitset;
181 rtl_sigfillset(bitset); // By default all signals will be blocked.
182 for (x=0; x<size; x++)
183 rtl_sigdelset(bitset, set[x]); // Unblock the "set" of signals.
185 return 0;//pthread_sigmask(SIG_SETMASK, bitmask, NULL);
189 int fosa_signal_queue (frsh_signal_t signal, frsh_signal_info_t info,
190 frsh_thread_id_t receiver){
191 /* union sigval value;
193 value.sival_ptr=info;
194 return sigqueue(0, signal, value);*/
197 int fosa_signal_wait (frsh_signal_t set[], int size, frsh_signal_t *signal_received,
198 frsh_signal_info_t *info){
203 rtl_sigemptyset(bitset); // No signals to wait for;
204 for (x=0; x<size; x++)
205 rtl_sigaddset(bitset, set[x]); // Add to the set of signals to be waited for.
206 sigwaitinfo(&bitset, &__info);
207 *signal_received=__info.si_signo;
208 *info = __info.si_value.sival_ptr;
212 int fosa_signal_timedwait (frsh_signal_t set[], int size, frsh_signal_t *signal_received,
213 frsh_signal_info_t *info, const struct timespec *timeout){
220 rtl_sigemptyset(bitset); // No signals to wait for;
221 for (x=0; x<size; x++)
222 rtl_sigaddset(bitset, set[x]); // Add to the set of signals to be waited for.
226 sigwaitinfo(&bitset, &__info);
227 *signal_received=__info.si_signo;
228 *info = __info.si_value.sival_ptr;