]> rtime.felk.cvut.cz Git - frescor/fosa.git/blobdiff - include/fosa_threads_and_signals.h
Adding FOSA_CPP_BEING|END_DECLS to allow interfacing with C++
[frescor/fosa.git] / include / fosa_threads_and_signals.h
index c332ce4bd0fa770eda0e14cda133db38fd24936e..b2d685f24c5f2f2cc179a241882fec677e56236c 100644 (file)
@@ -1,5 +1,5 @@
-// -----------------------------------------------------------------------
-//  Copyright (C) 2006 - 2007 FRESCOR consortium partners:
+//----------------------------------------------------------------------
+//  Copyright (C) 2006 - 2007 by the FRESCOR consortium:
 //
 //    Universidad de Cantabria,              SPAIN
 //    University of York,                    UK
 //    Visual Tools S.A.                      SPAIN
 //    Rapita Systems Ltd                     UK
 //    Evidence                               ITALY
-//    
-//    See http://www.frescor.org for a link to partners' websites
 //
-//           FRESCOR project (FP6/2005/IST/5-034026) is funded
+//    See http://www.frescor.org
+//
+//        The FRESCOR project (FP6/2005/IST/5-034026) is funded
 //        in part by the European Union Sixth Framework Programme
 //        The European Union is not liable of any use that may be
 //        made of this code.
 //
-//  This file is part of the FRSH implementation
 //
-//  FRSH is free software; you can  redistribute it and/or  modify
-//  it under the terms of  the GNU General Public License as published by
-//  the Free Software Foundation;  either  version 2, or (at  your option)
-//  any later version.
+//  based on previous work (FSF) done in the FIRST project
+//
+//   Copyright (C) 2005  Mälardalen University, SWEDEN
+//                       Scuola Superiore S.Anna, ITALY
+//                       Universidad de Cantabria, SPAIN
+//                       University of York, UK
 //
-//  FRSH  is distributed  in  the hope  that  it  will  be useful,  but
-//  WITHOUT  ANY  WARRANTY;     without  even the   implied   warranty  of
-//  MERCHANTABILITY  or  FITNESS FOR  A  PARTICULAR PURPOSE. See  the  GNU
-//  General Public License for more details.
+// This file is part of FOSA (Frsh Operating System Abstraction)
 //
-//  You should have  received a  copy of  the  GNU  General Public License
-//  distributed  with  FRSH;  see file COPYING.   If not,  write to the
-//  Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
-//  02111-1307, USA.
+// FOSA is free software; you can redistribute it and/or modify it
+// under terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option) any
+// later version.  FOSA is distributed in the hope that it will be
+// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details. You should have received a
+// copy of the GNU General Public License along with FOSA; see file
+// COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+// Cambridge, MA 02139, USA.
 //
-//  As a special exception, if you include this header file into source
-//  files to be compiled, this header file does not by itself cause
-//  the resulting executable to be covered by the GNU General Public
-//  License.  This exception does not however invalidate any other
-//  reasons why the executable file might be covered by the GNU General
-//  Public License.
+// As a special exception, including FOSA header files in a file,
+// instantiating FOSA generics or templates, or linking other files
+// with FOSA objects to produce an executable application, does not
+// by itself cause the resulting executable application to be covered
+// by the GNU General Public License. This exception does not
+// however invalidate any other reasons why the executable file might be
+// covered by the GNU Public License.
 // -----------------------------------------------------------------------
 //fosa_thread_and_signals.h
 //==============================================
 #ifndef        FOSA_THREAD_AND_SIGNALS_H_
 #define        FOSA_THREAD_AND_SIGNALS_H_
 
+#include "fosa_types.h"
+
+
+FOSA_CPP_BEGIN_DECLS
+
+
 /**
  * @defgroup threadandsignals Thread and Signals
  * @ingroup fosa
  *
- * This module defines the functions that manipulate frsh_threads and
- * frsh_signals inside FRSH implementation.
+ * This module defines the functions that manipulate fosa_threads and
+ * fosa_signals inside FRSH implementation.
  *
  * Applications can refer to FRSH threads but they cannot create them
  * directly, instead they must use frsh_thread_create*() which in turn
  * use fosa_thread_create().
  *
  * For signals, we assume that the OS provides a direct mapping
- * for frsh_signal_t and frsh_signal_info_t in the native interface.
+ * for fosa_signal_t and fosa_signal_info_t in the native interface.
  *
  * @{
  **/
  * Compare two thread identifiers to determine if they refer to the 
  * same thread
  **/
-bool fosa_thread_equal(frsh_thread_id_t t1, frsh_thread_id_t t2);
+bool fosa_thread_equal(fosa_thread_id_t t1, fosa_thread_id_t t2);
 
 
 /**
@@ -99,7 +110,71 @@ bool fosa_thread_equal(frsh_thread_id_t t1, frsh_thread_id_t t2);
  *
  * Return the thread id of the calling thread
  **/
-frsh_thread_id_t fosa_thread_self();
+fosa_thread_id_t fosa_thread_self();
+
+
+/*************************
+ * Thread attributes
+ *************************/ 
+
+/**
+ * fosa_thread_attr_init()
+ *
+ * Initialize a thread attributes object
+ *
+ * This function initializes the object pointed to by attr to all 
+ * the default values defined by FRSH
+ *
+ * @return 0 if successful; otherwise it returns \n
+ *   FOSA_ENOMEM: insufficient memory exists to initialize the thread 
+ *           attributes object
+ **/
+int fosa_thread_attr_init(fosa_thread_attr_t *attr);
+
+
+/**
+ * fosa_thread_attr_destroy()
+ *
+ * Destroy a thread attributes object
+ *
+ * This function is used to destroy the thread attributes object,
+ * pointed to by attr, and deallocate any system resources allocated for it
+ * 
+ * Returns 0
+ */
+int fosa_thread_attr_destroy(fosa_thread_attr_t *attr);
+
+
+/**
+ * fosa_thread_attr_set_stacksize()
+ *
+ * Set the thread minimum stack size in a thread attributes object
+ *
+ * This function sets the minimum stack size of the thread attributes
+ * object attr to the value given by stacksize, in bytes. This
+ * function has no runtime effect on the stack size, except when the
+ * attributes object is used to create a thread, when it will be
+ * created with the specified minimum stack size
+ * 
+ * @return 0 if successful, or the following error code:
+ *    FOSA_EINVAL: the specified stacksize  value is not supported in
+ *            this implementation
+ */
+int fosa_thread_attr_set_stacksize(fosa_thread_attr_t *attr, 
+                                   size_t stacksize);
+
+/**
+ * fosa_thread_attr_get_stacksize()
+ *
+ * Get the thread minimum stack size from a thread attributes object
+ *
+ * This function sets the variable pointed to by stacksize to the
+ * minimum stack size stored in the thread attributes object attr.
+ * 
+ * @return 0
+ */
+int fosa_thread_attr_get_stacksize(const fosa_thread_attr_t *attr, 
+                                   size_t *stacksize);
 
 
 /*************************
@@ -119,26 +194,26 @@ frsh_thread_id_t fosa_thread_self();
  *
  * Returns 0 if successful; otherwise it returs a code error:
  *
- *     EAGAIN: the system lacks the necessary resources to create a
+ *     FOSA_EAGAIN: the system lacks the necessary resources to create a
  *             new thread or the maximum number of threads has been
  *             reached
  *
- *     EINVAL: the value specified by attr is invalid (for instance,
+ *     FOSA_EINVAL: the value specified by attr is invalid (for instance,
  *              it has not been correctly initialized)
  *
- *     EREJECT: the cretion of the thread was rejected by the frsh scheduler
+ *     FOSA_EREJECT: the cretion of the thread was rejected by the frsh scheduler
  *               possibly because of incorrect attributes, or because the 
  *               requested minimum capacity cannot be guaranteed
  *
  **/
  int fosa_thread_create
-    (frsh_thread_id_t *tid, const frsh_thread_attr_t *attr, 
-     frsh_thread_code_t code, void * arg);
+    (fosa_thread_id_t *tid, const fosa_thread_attr_t *attr, 
+     fosa_thread_code_t code, void * arg);
 
 
 /**
  * Note: no thread termination primitive is provided. The termination
- * of a thread will be notifoed by the system to the FRSH scheduler
+ * of a thread will be notified by the system to the FRSH scheduler
  * through the scheduler API
  **/
 
@@ -159,7 +234,9 @@ frsh_thread_id_t fosa_thread_self();
  * Create a new key for thread specific data.
  *
  * Prior to setting data in a key, we need ask the system to create
- * one for us.
+ * one for us.  The thread specific data of all the threads is set to
+ * the value NULL until changed to a different value via
+ * fosa_thread_set_specific_data().
  *
  * @return 0 if successful \n
  *   FOSA_EINVAL If we already have reached the FOSA_MAX_KEYS limit.
@@ -173,7 +250,7 @@ int fosa_key_create(int *key);
  *
  * Destroy a key
  *
- * This destroys the key and isables its use in the system
+ * This destroys the key and disables its use in the system
  *
  * @return 0 if successful \n
  *   FOSA_EINVAL The key is not initialised or is not in FOSA key range.
@@ -190,14 +267,14 @@ int fosa_key_destroy(int key);
  * identified by key will be set to the value specified by value
  *
  * Returns 0 if successful; otherwise, an error code is returned
- *     EINVAL: the value of key is not between 0 and FOSA_MAX_KEYS-1
+ *     FOSA_EINVAL: the value of key is not between 0 and FOSA_MAX_KEYS-1
  *
  * Alternatively, in case of error the implementation is allowed to
  * notify it to the system console and then terminate the FRSH
  * implementation and dependant applications
  **/
  int fosa_thread_set_specific_data
-       (int key, frsh_thread_id_t tid, const void * value);
+       (int key, fosa_thread_id_t tid, const void * value);
 
 /**
  * fosa_thread_get_specific_data()
@@ -208,13 +285,13 @@ int fosa_key_destroy(int key);
  * identified by key will be copied to the variable pointed to by value
  *
  * Returns 0 if successful; otherwise, an error code is returned
- *     EINVAL: the value of key is not between 0 and FOSA_MAX_KEYS-1
+ *     FOSA_EINVAL: the value of key is not between 0 and FOSA_MAX_KEYS-1
  *
  * Alternatively, in case of error the implementation is allowed to
  * notify it to the system console and then terminate the FRSH
  * implementation and dependant applications
  **/
-int fosa_thread_get_specific_data(int key, frsh_thread_id_t tid, 
+int fosa_thread_get_specific_data(int key, fosa_thread_id_t tid, 
                                   void ** value);
 
 
@@ -255,14 +332,14 @@ int fosa_get_priority_min();
  * priority
  * 
  * Returns 0 if successful, or the following error code:
- *    EINVAL: the specified priority value is not between the 
+ *    FOSA_EINVAL: the specified priority value is not between the 
  *            minimum and the maximum priorities defined in this
  *            FRSH implementation
  * Alternatively, in case of error the implementation is allowed to
  * notify it to the system console and then terminate the FRSH
  * implementation and dependant applications
  **/
-int fosa_thread_attr_set_prio(frsh_thread_attr_t *attr, int prio);
+int fosa_thread_attr_set_prio(fosa_thread_attr_t *attr, int prio);
 
 /**
  * fosa_thread_attr_get_prio()
@@ -275,7 +352,7 @@ int fosa_thread_attr_set_prio(frsh_thread_attr_t *attr, int prio);
  * Returns 0
  **/
  int fosa_thread_attr_get_prio
-          (const frsh_thread_attr_t *attr, size_t *prio);
+          (const fosa_thread_attr_t *attr, int *prio);
 
 /**
  * fosa_thread_set_prio()
@@ -286,14 +363,14 @@ int fosa_thread_attr_set_prio(frsh_thread_attr_t *attr, int prio);
  * set to the value specified by prio. 
  * 
  * Returns 0 if successful, or the following error code:
- *    EINVAL: the specified priority value is not between the 
+ *    FOSA_EINVAL: the specified priority value is not between the 
  *            minimum and the maximum priorities defined in this
  *            FRSH implementation
  * Alternatively, in case of error the implementation is allowed to
  * notify it to the system console and then terminate the FRSH
  * implementation and dependant applications
  **/
-int fosa_thread_set_prio(frsh_thread_id_t tid, int prio);
+int fosa_thread_set_prio(fosa_thread_id_t tid, int prio);
 
 /**
  * fosa_thread_get_prio()
@@ -305,7 +382,7 @@ int fosa_thread_set_prio(frsh_thread_id_t tid, int prio);
  * 
  * Returns 0
  **/
-int fosa_thread_get_prio (frsh_thread_id_t tid, int *prio);
+int fosa_thread_get_prio (fosa_thread_id_t tid, int *prio);
 
 
 
@@ -317,7 +394,7 @@ int fosa_thread_get_prio (frsh_thread_id_t tid, int *prio);
  * synchronously wait. Signals carry an associated piece of
  * information (an integer or a pointer) and are queued until they are
  * accepted.  Signals are identified by an integer signal number (of
- * the type frsh_signal_t) in the range FOSA_SIGNAL_MIN,
+ * the type fosa_signal_t) in the range FOSA_SIGNAL_MIN,
  * FOSA_SIGNAL_MAX.  This range is required to have at least <tbd>
  * values.
  *******************************************************************/
@@ -332,7 +409,7 @@ int fosa_thread_get_prio (frsh_thread_id_t tid, int *prio);
  * which must be of size equal to size
  *
  * Returns 0 if successful; otherwise it returns an error code:
- *     EINVAL: the array contains one or more values which are not
+ *     FOSA_EINVAL: the array contains one or more values which are not
  *             between FOSA_SIGNAL_MIN and FOSA_SIGNAL_MAX, or size
  *             is less than 0
  *
@@ -340,7 +417,7 @@ int fosa_thread_get_prio (frsh_thread_id_t tid, int *prio);
  * notify it to the system console and then terminate the FRSH
  * implementation and dependant applications
  **/
-int fosa_set_accepted_signals(frsh_signal_t set[], int size);
+int fosa_set_accepted_signals(fosa_signal_t set[], int size);
 
 /**
  * fosa_signal_queue()
@@ -359,10 +436,10 @@ int fosa_set_accepted_signals(frsh_signal_t set[], int size);
  * thread be the one who is waiting for the signal. 
  *
  * Returns 0 if successful; otherwise it returns an error code:
- *     EINVAL: the signal specified by signal is not
+ *     FOSA_EINVAL: the signal specified by signal is not
  *              between FOSA_SIGNAL_MIN and FOSA_SIGNAL_MAX
  *
- *     EAGAIN: no resources are available to queue the signal; the
+ *     FOSA_EAGAIN: no resources are available to queue the signal; the
  *             maximum number of queued signals has been reached, or a
  *             systemwide resource limit has been exceeded
  *
@@ -370,9 +447,11 @@ int fosa_set_accepted_signals(frsh_signal_t set[], int size);
  * notify it to the system console and then terminate the FRSH
  * implementation and dependant applications
  **/
- int fosa_signal_queue
-       (frsh_signal_t signal, frsh_signal_info_t info,
-        frsh_thread_id_t receiver);
+int fosa_signal_queue
+       (fosa_signal_t signal, fosa_signal_info_t info,
+        fosa_thread_id_t receiver);
+
+
 
 
 /**
@@ -391,7 +470,7 @@ int fosa_set_accepted_signals(frsh_signal_t set[], int size);
  * is stored in the variable pointed to by info.
  *
  * Returns 0 if successful; otherwise it returns an error code:
- *     EINVAL: the array contains one or more values which are not
+ *     FOSA_EINVAL: the array contains one or more values which are not
  *             between FOSA_SIGNAL_MIN and FOSA_SIGNAL_MAX, or size
  *             is less than 0
  *
@@ -400,8 +479,8 @@ int fosa_set_accepted_signals(frsh_signal_t set[], int size);
  * implementation and dependant applications
  **/
  int fosa_signal_wait
-      (frsh_signal_t set[], int size, frsh_signal_t *signal_received, 
-       frsh_signal_info_t *info);
+      (fosa_signal_t set[], int size, fosa_signal_t *signal_received, 
+       fosa_signal_info_t *info);
 
 /**
  * fosa_signal_timedwait()
@@ -413,20 +492,21 @@ int fosa_set_accepted_signals(frsh_signal_t set[], int size);
  * the timespec structure referenced by timeout.
  * 
  * Returns 0 if successful; otherwise it returns an error code:
- *     EINVAL: the array contains one or more values which are not
+ *     FOSA_EINVAL: the array contains one or more values which are not
  *             between FOSA_SIGNAL_MIN and FOSA_SIGNAL_MAX, or size
  *             is less than 0, or timeout is invalid
- *     EAGAIN: The timeout expired
+ *     FOSA_EAGAIN: The timeout expired
  *
- * Alternatively, in case of the EINVAL error the implementation is
+ * Alternatively, in case of the FOSA_EINVAL error the implementation is
  * allowed to notify it to the system console and then terminate the
  * FRSH implementation and dependant applications
  **/
  int fosa_signal_timedwait
-      (frsh_signal_t set[], int size, frsh_signal_t *signal_received, 
-       frsh_signal_info_t *info, const struct timespec *timeout);
+      (fosa_signal_t set[], int size, fosa_signal_t *signal_received, 
+       fosa_signal_info_t *info, const struct timespec *timeout);
 
 /*}*/
 
+FOSA_CPP_END_DECLS
 
 #endif             /* !FOSA_THREAD_AND_SIGNALS_H_ */