]> rtime.felk.cvut.cz Git - frescor/fosa.git/blob - src_marte/frsh_fosa.c
Renaming src_marte_linux to src_marte (for the moment)
[frescor/fosa.git] / src_marte / frsh_fosa.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 // -----------------------------------------------------------------------
41 //frsh_fosa.c
42 //==============================================
43 //  ********  ******    ********  **********
44 //  **///// /**    **  **//////  /**     /**
45 //  **      /**    ** /**        /**     /**
46 //  ******* /**    ** /********* /**********
47 //  **////  /**    ** ////////** /**//////**
48 //  **      /**    **        /** /**     /**
49 //  **      /**    **  ********  /**     /**
50 //  //       /******/  ////////   //      // 
51 //
52 // FOSA(Frescor Operating System Adaptation layer)
53 //================================================
54
55 #include "frsh_fosa.h"
56 #include <pthread.h>
57 #include <stdio.h>
58
59 #include <misc/error_checks.h>
60
61 /*************************
62  * Thread attributes
63  *************************/ 
64
65 /**
66  * frsh_thread_attr_init()
67  *
68  * Initialize a thread attributes object
69  *
70  * This function initializes the object pointed to by attr to all 
71  * the default values defined by FRSH
72  *
73  * @return 0 if successful; otherwise it returns \n
74  *   FOSA_ENOMEM: insufficient memory exists to initialize the thread 
75  *           attributes object
76  **/
77 int frsh_thread_attr_init(frsh_thread_attr_t *attr)
78 {
79   int ret_value;
80
81   ret_value=pthread_attr_init(attr);
82   if (ret_value==0) {
83     // set the default values
84
85     // detachstate = detached thread (no join operation allowed)
86     CHK(pthread_attr_setdetachstate(attr,PTHREAD_CREATE_DETACHED));
87
88     // inheritsched = explicit, so that we can explicitly set the attributes
89     CHK(pthread_attr_setinheritsched(attr,PTHREAD_EXPLICIT_SCHED));
90     
91     // schedpolicy = fixed priorities
92     CHK(pthread_attr_setschedpolicy(attr,SCHED_FIFO));
93
94     // detachstate = detached thread (no join operation allowed)
95     CHK(pthread_attr_setdetachstate(attr,PTHREAD_CREATE_DETACHED));
96
97   }
98   return ret_value;
99 }
100
101 /**
102  * frsh_thread_attr_destroy()
103  *
104  * Destroy a thread attributes object
105  *
106  * This function is used to destroy the thread attributes object,
107  * pointed to by attr, and deallocate any system resources allocated for it
108  * 
109  * Returns 0
110  */
111 int frsh_thread_attr_destroy(frsh_thread_attr_t *attr)
112 {
113   return pthread_attr_destroy(attr);
114 }
115
116 /**
117  * frsh_thread_attr_set_stacksize()
118  *
119  * Set the thread minimum stack size in a thread attributes object
120  *
121  * This function sets the minimum stack size of the thread attributes
122  * object attr to the value given by stacksize, in bytes. This
123  * function has no runtime effect on the stack size, except when the
124  * attributes object is used to create a thread, when it will be
125  * created with the specified minimum stack size
126  * 
127  * @return 0 if successful, or the following error code:
128  *    FOSA_EINVAL: the specified stacksize  value is not supported in
129  *            this implementation
130  */
131 int frsh_thread_attr_set_stacksize
132      (frsh_thread_attr_t *attr, size_t stacksize)
133 {
134   return pthread_attr_setstacksize(attr,stacksize);
135 }
136
137 /**
138  * frsh_thread_attr_get_stacksize()
139  *
140  * Get the thread minimum stack size from a thread attributes object
141  *
142  * This function sets the variable pointed to by stacksize to the
143  * minimum stack size stored in the thread attributes object attr.
144  * 
145  * @return 0
146  */
147 int frsh_thread_attr_get_stacksize
148       (const frsh_thread_attr_t *attr, size_t *stacksize)
149 {
150   return pthread_attr_getstacksize(attr,stacksize);
151 }