]> rtime.felk.cvut.cz Git - frescor/fosa.git/blob - src_rtlinux/fosa_threads_and_signals.c
Fosa for rtlinux already compiles, however some functions are still missed
[frescor/fosa.git] / src_rtlinux / fosa_threads_and_signals.c
1 // -----------------------------------------------------------------------
2 //  Copyright (C) 2006 - 2007 FRESCOR consortium partners:
3 //
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
10 //    ENEA                                   SWEDEN
11 //    Thales Communication S.A.              FRANCE
12 //    Visual Tools S.A.                      SPAIN
13 //    Rapita Systems Ltd                     UK
14 //    Evidence                               ITALY
15 //    
16 //    See http://www.frescor.org for a link to partners' websites
17 //
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
21 //        made of this code.
22 //
23 //  This file is part of the FRSH implementation
24 //
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)
28 //  any later version.
29 //
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.
34 //
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
38 //  02111-1307, USA.
39 //
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
45 //  Public License.
46 // -----------------------------------------------------------------------
47 //==============================================
48 //  ********  ******    ********  **********
49 //  **///// /**    **  **//////  /**     /**
50 //  **      /**    ** /**        /**     /**
51 //  ******* /**    ** /********* /**********
52 //  **////  /**    ** ////////** /**//////**
53 //  **      /**    **        /** /**     /**
54 //  **      /**    **  ********  /**     /**
55 //  //       /******/  ////////   //      // 
56 //
57 // FOSA(Frescor Operating System Adaptation layer)
58 //================================================
59
60 #include <fosa.h>
61
62 /*************************
63  * Thread identification
64  *************************/ 
65
66 bool fosa_thread_equal(frsh_thread_id_t t1, frsh_thread_id_t t2){
67      return pthread_equal(t1,t2);
68 }
69
70 frsh_thread_id_t fosa_thread_self(){
71      return pthread_self();
72 }
73
74 /*************************
75  * Thread creation and termination
76  *************************/ 
77
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);
81 }
82
83
84 /**************************************************
85  * Thread-specific data
86  *  (extended with access from a different thread)
87  *
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  **************************************************/ 
93
94 int fosa_thread_set_specific_data (int key, frsh_thread_id_t tid, 
95                                            const void * value){
96      if ((0<key) && (key<FOSA_MAX_KEYS-1)){
97            // MISSED
98           //pthread_setspecific_for(key, tid, value);
99           return 0;
100      }
101      return EINVAL;
102 }
103
104 int fosa_thread_get_specific_data(int key, frsh_thread_id_t tid, 
105                                   void ** value){
106      if ((0<key) && (key<FOSA_MAX_KEYS-1)){
107           *value=pthread_remote_getspecific(key,tid);
108           return 0;
109      }
110      return EINVAL;
111
112 }
113
114
115 /******************************************************************
116  * Thread scheduling
117  * 
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  *******************************************************************/
125
126 int fosa_get_priority_max() {
127      return sched_get_priority_max(0);
128 }
129
130 int fosa_get_priority_min(){
131      return sched_get_priority_min(0);
132 }
133
134 int fosa_thread_attr_set_prio(frsh_thread_attr_t *attr, int prio) {
135         // MISSED
136      /*if ((ched_get_priority_min(0)<=prio) || (prio<=sched_get_priority_min(0))){
137           attr->sched_param.sched_priority = prio;
138           return 0;
139      }*/
140      return EINVAL;
141 }
142
143 int fosa_thread_attr_get_prio (const frsh_thread_attr_t *attr, size_t *prio){
144      *prio = attr->sched_param.sched_priority;
145      return 0;
146 }
147
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);
151            return 0;
152      }
153      return EINVAL;
154 }
155
156 int fosa_thread_get_prio (frsh_thread_id_t tid, int *prio){
157      *prio = tid->sched_param.sched_priority;
158      return 0;
159 }
160
161
162
163 /*******************************************************************
164  * Signals
165  *
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>
173  * values.
174  *******************************************************************/
175
176 int fosa_set_accepted_signals(frsh_signal_t set[], int size) {
177      int x;
178      // MISSED
179      /*rtl_sigset_t bitset;
180
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.
184      */
185      return 0;//pthread_sigmask(SIG_SETMASK, bitmask, NULL);
186 }
187
188
189 int fosa_signal_queue (frsh_signal_t signal, frsh_signal_info_t info,
190                        frsh_thread_id_t receiver){
191 /*     union sigval value;
192      
193      value.sival_ptr=info;
194      return sigqueue(0, signal, value);*/
195 }
196
197 int fosa_signal_wait (frsh_signal_t set[], int size, frsh_signal_t *signal_received, 
198                                     frsh_signal_info_t *info){
199 /*     int x;
200      rtl_sigset_t bitset;
201      siginfo_t __info;
202      
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;
209 */
210 }
211
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){
214      
215   /*   
216      int x;
217      rtl_sigset_t bitset;
218      siginfo_t __info;
219      
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.
223
224          ????? // to be done
225      
226      sigwaitinfo(&bitset, &__info);
227      *signal_received=__info.si_signo;
228      *info = __info.si_value.sival_ptr;
229         ??????*/
230 }
231
232
233