]> rtime.felk.cvut.cz Git - frescor/fosa.git/blobdiff - src_rtlinux/fosa_threads_and_signals.h
RTLinux compatibility as a kernel module
[frescor/fosa.git] / src_rtlinux / fosa_threads_and_signals.h
diff --git a/src_rtlinux/fosa_threads_and_signals.h b/src_rtlinux/fosa_threads_and_signals.h
deleted file mode 100644 (file)
index 04e80e5..0000000
+++ /dev/null
@@ -1,530 +0,0 @@
-// -----------------------------------------------------------------------
-//  Copyright (C) 2006 - 2007 FRESCOR consortium partners:
-//
-//    Universidad de Cantabria,              SPAIN
-//    University of York,                    UK
-//    Scuola Superiore Sant'Anna,            ITALY
-//    Kaiserslautern University,             GERMANY
-//    Univ. Politecnica  Valencia,           SPAIN
-//    Czech Technical University in Prague,  CZECH REPUBLIC
-//    ENEA                                   SWEDEN
-//    Thales Communication S.A.              FRANCE
-//    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
-//        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.
-//
-//  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.
-//
-//  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.
-//
-//  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.
-// -----------------------------------------------------------------------
-//fosa_thread_and_signals.h
-//==============================================
-//  ********  ******    ********  **********
-//  **///// /**    **  **//////  /**     /**
-//  **      /**    ** /**        /**     /**
-//  ******* /**    ** /********* /**********
-//  **////  /**    ** ////////** /**//////**
-//  **      /**    **        /** /**     /**
-//  **      /**    **  ********  /**     /**
-//  //       /******/  ////////   //      // 
-//
-// FOSA(Frescor Operating System Adaptation layer)
-//================================================
-
-
-#ifndef        FOSA_THREAD_AND_SIGNALS_H_
-#define        FOSA_THREAD_AND_SIGNALS_H_
-
-/**
- * @defgroup threadandsignals Thread and Signals
- * @ingroup fosa
- *
- * This module defines the functions that manipulate frsh_threads and
- * frsh_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.
- *
- * @{
- **/
-
-
-
-/*************************
- * Thread identification
- *************************/ 
-
-/**
- * fosa_thread_equal()
- *
- * 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);
-
-extern inline bool fosa_thread_equal(frsh_thread_id_t t1, frsh_thread_id_t t2){
-     return pthread_equal(t1,t2);
-}
-
-
-/**
- * fosa_thread_self()
- *
- * Return the thread id of the calling thread
- **/
-//frsh_thread_id_t fosa_thread_self();
-
-extern inline frsh_thread_id_t fosa_thread_self(){
-     return pthread_self();
-}
-
-/*************************
- * Thread creation and termination
- *************************/ 
-
-/**
- * fosa_thread_create()
- *
- * This function creates a new thread using the attributes specified
- * in attr. If attr is NULL, default attributes are used. The new
- * thread starts running immediately, executing the function specified
- * by code, with an argument equal to arg. Upon successful return, the
- * variable pointed to by tid will contain the identifier of the newly
- * created thread. The set of signals that may be synchronously
- * accepted is inherited from the parent thread.
- *
- * Returns 0 if successful; otherwise it returs a code error:
- *
- *     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,
- *              it has not been correctly initialized)
- *
- *     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);
-
-extern inline int fosa_thread_create (frsh_thread_id_t *tid, const frsh_thread_attr_t *attr, 
-                               frsh_thread_code_t code, void * arg){
-     return pthread_create(tid,attr,code, arg);
-}
-
-
-/**
- * Note: no thread termination primitive is provided. The termination
- * of a thread will be notifoed by the system to the FRSH scheduler
- * through the scheduler API
- **/
-
-
-/**************************************************
- * Thread-specific data
- *  (extended with access from a different thread)
- *
- * Several data items (pointers) may be associated with each thread
- * Each item is identified through a key, an integer value between 0
- * and FOSA_MAX_KEYS-1. The caller is responsible of allocating and
- * deallocating the memory area pointed to by the pointer
- **************************************************/ 
-
-/**
- * fosa_thread_set_specific_data()
- *
- * Set thread-specific data
- *
- * For the thread identified by tid, the thread-specifid data field
- * 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
- *
- * 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);
-
-extern inline int fosa_thread_set_specific_data (int key, frsh_thread_id_t tid, 
-                                           const void * value){
-     if ((0<key) && (key<FOSA_MAX_KEYS-1)){
-          pthread_setspecific_for(key, tid, value);
-          return 0;
-     }
-     return EINVAL;
-}
-
-/**
- * fosa_thread_get_specific_data()
- *
- * Get thread-specific data
- *
- * For the thread identified by tid, the thread-specifid data field
- * 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
- *
- * 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, 
-//                                  void ** value);
-
-
-extern int fosa_thread_get_specific_data(int key, frsh_thread_id_t tid, 
-                                  void ** value){
-     if ((0<key) && (key<FOSA_MAX_KEYS-1)){
-          *value=pthread_remote_getspecific(key,tid);
-          return 0;
-     }
-     return EINVAL;
-
-}
-
-
-/******************************************************************
- * Thread scheduling
- * 
- * This implementation of FRSH assumes an underlying fixed priority
- * scheduler with priorities in a range, with a minimum and a
- * maximumm, a number of priority levels with at least 31
- * priorities. A larger number implies a larger priority. In systems
- * in which the underlying scheduler uses the opposite convention, a
- * mapping is automatically provided by the OS adaptation layer.
- *******************************************************************/
-
-/**
- * fosa_get_priority_max()
- *
- * Return the maximum priority value used in this implementation
- **/
-//int fosa_get_priority_max();
-extern inline int fosa_get_priority_max() {
-     return sched_get_priority_max(0);
-}
-
-/**
- * fosa_get_priority_min()
- *
- * Return the minimum priority value used in this implementation
- **/
-//int fosa_get_priority_min();
-
-extern inline int fosa_get_priority_min(){
-     return sched_get_priority_min(0);
-}
-
-
-/**
- * fosa_thread_attr_set_prio()
- *
- * Change the priority of a thread attributes object
- *
- * The priority of the thread attriutes object specified by attr is
- * set to the value specified by prio. This function has no runtime
- * effect on the priority, except when the attributes object is used
- * to create a thread, when it will be created with the specified
- * priority
- * 
- * Returns 0 if successful, or the following error code:
- *    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);
-
-extern inline int fosa_thread_attr_set_prio(frsh_thread_attr_t *attr, int prio) {
-     if ((ched_get_priority_min(0)<=prio) || (prio<=sched_get_priority_min(0))){
-          attr->sched_param.sched_priority = prio;
-          return 0;
-     }
-     return EINVAL;
-}
-
-
-
-/**
- * fosa_thread_attr_get_prio()
- *
- * Get the priority from a thread attributes object
- *
- * This function sets the variable pointed to by prio to the
- * priority stored in the thread attributes object attr.
- * 
- * Returns 0
- **/
-// int fosa_thread_attr_get_prio
-//          (const frsh_thread_attr_t *attr, size_t *prio);
-
-extern inline  int fosa_thread_attr_get_prio (const frsh_thread_attr_t *attr, size_t *prio){
-     *prio = attr->sched_param.sched_priority;
-     return 0;
-}
-
-/**
- * fosa_thread_set_prio()
- *
- * Dynamically change the priority of a thread
- *
- * The priority of the thread identified by tid is
- * 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 
- *            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);
-extern inline fosa_thread_set_prio(frsh_thread_id_t tid, int prio){
-     if ((sched_get_priority_min(0)<=prio) || (prio<=sched_get_priority_min(0))){
-           pthread_setschedprio(tid,prio);
-           return 0;
-     }
-     return EINVAL;
-}
-
-
-
-/**
- * fosa_thread_get_prio()
- *
- * Dynamically get the priority of a thread
- *
- * This function sets the variable pointed to by prio to the
- * priority of the thread identified by tid
- * 
- * Returns 0
- **/
-int fosa_thread_get_prio (frsh_thread_id_t tid, int *prio);
-
-extern inline int fosa_thread_get_prio (frsh_thread_id_t tid, int *prio){
-     *prio = tid->sched_param.sched_priority;
-     return 0;
-}
-
-
-
-/*******************************************************************
- * Signals
- *
- * Signals represent events that may be notified by the system, or
- * sent explicitly by the application, and for which a thread may
- * 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,
- * FOSA_SIGNAL_MAX.  This range is required to have at least <tbd>
- * values.
- *******************************************************************/
-
-/**
- * fosa_set_accepted_signals()
- *
- * Establish the set of signals that may be synchronously accepted 
- * by the calling thread
- *
- * The function uses the array of signal numbers specified by set,
- * 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
- *             between FOSA_SIGNAL_MIN and FOSA_SIGNAL_MAX, or size
- *             is less than 0
- *
- * 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_set_accepted_signals(frsh_signal_t set[], int size);
-
-
-extern inline int fosa_set_accepted_signals(frsh_signal_t set[], int size) {
-     int x;
-     rtl_sigset_t bitset;
-
-     rtl_sigfillset(bitset); // By default all signals will be blocked.
-     for (x=0; x<size; x++)
-          rtl_sigdelset(bitset, set[x]); // Unblock the "set" of signals.
-     
-     return pthread_sigmask(SIG_SETMASK, bitmask, NULL);
-}
-
-
-
-/**
- * fosa_signal_queue()
- *
- * Queue a signal
- *
- * This function is used to explicitly send a signal with a specified
- * value
- * 
- * The signal number specified by signal is sent together with the
- * information specified by info, to the thread identified by
- * receiver. In those implementations that do not support queueing a
- * signal with information to a thread (such as POSIX), the signal may
- * be sent to any thread that is waiting for this signal via
- * fosa_signal_wait(). Portability can be ensured by having the receiver
- * 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
- *              between FOSA_SIGNAL_MIN and FOSA_SIGNAL_MAX
- *
- *     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
- *
- * 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_signal_queue
-//       (frsh_signal_t signal, frsh_signal_info_t info,
-//        frsh_thread_id_t receiver);
-
- extern inline int fosa_signal_queue (frsh_signal_t signal, frsh_signal_info_t info,
-                                      frsh_thread_id_t receiver){
-      union sigval value;
-
-      value.sival_ptr=info;
-      return sigqueue(0, signal, value);
- }
-
-
-/**
- * fosa_signal_wait()
- *
- * Wait for a signal
- * 
- * The function waits for the arrival of one of the signals in the
- * array of signal numbers specified by set, which must be of size
- * equal to size. If there is a signal already queued, the function
- * returns immediately. If there is no signal of the specified set
- * queued, the calling thread is suspended until a signal from that
- * set arrives. Upon return, if signal_received is not NULL the number
- * of the signal received is stored in the variable pointed to by
- * signal_received; and if info is not NULL the associated information
- * 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
- *             between FOSA_SIGNAL_MIN and FOSA_SIGNAL_MAX, or size
- *             is less than 0
- *
- * 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_signal_wait
-//      (frsh_signal_t set[], int size, frsh_signal_t *signal_received, 
-//       frsh_signal_info_t *info);
-
-extern inline int fosa_signal_wait (frsh_signal_t set[], int size, frsh_signal_t *signal_received, 
-                                    frsh_signal_info_t *info){
-     int x;
-     rtl_sigset_t bitset;
-     siginfo_t __info;
-     
-     rtl_sigemptyset(bitset); // No signals to wait for;
-     for (x=0; x<size; x++)
-          rtl_sigaddset(bitset, set[x]); // Add to the set of signals to be waited for.
-     sigwaitinfo(&bitset, &__info);
-     *signal_received=__info.si_signo;
-     *info = __info.si_value.sival_ptr;
-
-}
-
-/**
- * fosa_signal_timedwait()
- *
- * Timed wait for a signal
- * 
- * This function behaves the same as fosa_signal_wait(), except that
- * the suspension time is limited to the time interval specified in
- * 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
- *             between FOSA_SIGNAL_MIN and FOSA_SIGNAL_MAX, or size
- *             is less than 0, or timeout is invalid
- *     EAGAIN: The timeout expired
- *
- * Alternatively, in case of the 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);
-
-extern inline int fosa_signal_timedwait (frsh_signal_t set[], int size, frsh_signal_t *signal_received, 
-                                         frsh_signal_info_t *info, const struct timespec *timeout){
-     
-     
-     int x;
-     rtl_sigset_t bitset;
-     siginfo_t __info;
-     
-     rtl_sigemptyset(bitset); // No signals to wait for;
-     for (x=0; x<size; x++)
-          rtl_sigaddset(bitset, set[x]); // Add to the set of signals to be waited for.
-
-         ????? // to be done
-     
-     sigwaitinfo(&bitset, &__info);
-     *signal_received=__info.si_signo;
-     *info = __info.si_value.sival_ptr;
-       ??????
-}
-
-/*}*/
-
-
-#endif             /* !FOSA_THREAD_AND_SIGNALS_H_ */