--- /dev/null
+// -----------------------------------------------------------------------
+// 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(Frescor Operating System Adaptation layer)
+//================================================
+
+#include <fosa.h>
+
+/*************************
+ * Timing: Clocks
+ *************************/
+
+int fosa_clock_get_time(fosa_clock_id_t clockid,
+ struct timespec *current_time)
+{
+ return clock_gettime(clockid, current_time);
+}
+
+int fosa_thread_get_cputime_clock(frsh_thread_id_t tid,
+ fosa_clock_id_t *clockid)
+{
+ if (tid.linux_pid == tid.linux_tid) {
+ /* we're in a standard UNIX process */
+ *clockid = FOSA_SYSTEM_CLOCK;
+
+ return 0;
+ } else
+ /* we're in a thread */
+ return pthread_getcpuclockid(tid.pthread_id, clockid);
+}
+
+/*************************
+ * Timing: Timers
+ *************************/
+
+int fosa_timer_create(fosa_clock_id_t clockid,
+ frsh_signal_t signal,
+ frsh_signal_info_t info,
+ fosa_timer_id_t *timerid)
+{
+ struct sigevent event;
+
+ event.sigev_notify = SIGEV_SIGNAL;
+ event.sigev_signo = signal;
+ event.sigev_value.sival_int = info.value;
+
+ return timer_create(clockid, &event, timerid);
+}
+
+int fosa_timer_delete(fosa_timer_id_t timerid){
+ timer_delete(timerid);
+ return 0;
+}
+
+int fosa_timer_arm (fosa_timer_id_t timerid,
+ bool abstime,
+ const struct timespec *value)
+{
+ int flags;
+ struct itimerspec when;
+
+ when.it_value = *value; /* one shot timer */
+ when.it_interval.tv_sec = 0;
+ when.it_interval.tv_nsec = 0; /* no periodic behaviour */
+ if (abstime)
+ flags = TIMER_ABSTIME;
+ else
+ flags = 0;
+
+ return timer_settime(timerid, flags, &when, NULL);
+}
+
+int fosa_timer_get_remaining_time(fosa_timer_id_t timerid, struct timespec *remaining_time)
+{
+ errno = EINVAL;
+ return -1;
+}
+
+int fosa_timer_disarm(fosa_timer_id_t timerid, struct timespec *remaining_time)
+{
+ struct itimerspec when;
+
+ /* maybe not needed but safer */
+ when.it_value.tv_sec = 0;
+ when.it_value.tv_nsec = 0;
+ when.it_interval = when.it_value;
+
+ return timer_settime(timerid, TIMER_ABSTIME , &when, NULL);
+}
+
--- /dev/null
+// -----------------------------------------------------------------------
+// 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_mutexes_and_condvars.h
+//==============================================
+// ******** ****** ******** **********
+// **///// /** ** **////// /** /**
+// ** /** ** /** /** /**
+// ******* /** ** /********* /**********
+// **//// /** ** ////////** /**//////**
+// ** /** ** /** /** /**
+// ** /** ** ******** /** /**
+// // /******/ //////// // //
+//
+// FOSA(Frescor Operating System Adaptation layer)
+//================================================
+
+#include <fosa.h>
+
+
+/*******************************************************
+ * Mutexes with priority ceiling
+ ******************************************************/
+
+
+int fosa_mutex_init(frsh_mutex_t *mutex, int prioceiling)
+{
+ /* priority ceiling if, for now, ignored */
+ return pthread_mutex_init(mutex, NULL);
+}
+
+int fosa_mutex_destroy(frsh_mutex_t *mutex)
+{
+ return pthread_mutex_destroy(mutex);
+}
+
+int fosa_mutex_set_prioceiling(frsh_mutex_t *mutex,
+ int new_ceiling,
+ int *old_ceiling)
+{
+ return pthread_mutex_setprioceiling(mutex, new_ceiling, old_ceiling);
+}
+
+int fosa_mutex_get_prioceiling(const frsh_mutex_t *mutex, int *ceiling)
+{
+ return pthread_mutex_getprioceiling(mutex, ceiling);
+}
+
+int fosa_mutex_lock(frsh_mutex_t *mutex)
+{
+ return pthread_mutex_lock(mutex);
+}
+
+int fosa_mutex_trylock(frsh_mutex_t *mutex)
+{
+ return pthread_mutex_trylock(mutex);
+}
+
+int fosa_mutex_unlock(frsh_mutex_t *mutex)
+{
+ return pthread_mutex_unlock(mutex);
+}
+
+/**********************
+ * Condition variables
+ *********************/
+
+int fosa_cond_init(fosa_cond_t *cond)
+{
+ return pthread_cond_init(cond, NULL);
+}
+
+int fosa_cond_destroy(fosa_cond_t *cond)
+{
+ return pthread_cond_destroy(cond);
+}
+
+int fosa_cond_signal(fosa_cond_t *cond)
+{
+ return pthread_cond_signal(cond);
+}
+
+int fosa_cond_broadcast(fosa_cond_t *cond)
+{
+ return pthread_cond_broadcast(cond);
+}
+
+int fosa_cond_wait(fosa_cond_t *cond, frsh_mutex_t *mutex)
+{
+ return pthread_cond_wait(cond, mutex);
+}
+
+int fosa_cond_timedwait(fosa_cond_t *cond,
+ frsh_mutex_t *mutex,
+ const struct timespec *abstime)
+{
+ return pthread_cond_timedwait(cond, mutex, abstime);
+}
+
--- /dev/null
+// -----------------------------------------------------------------------
+// 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(Frescor Operating System Adaptation layer)
+//================================================
+
+#include <linux/unistd.h>
+#include <fosa.h>
+
+/*************************
+ * Thread identification
+ *************************/
+
+bool fosa_thread_equal(frsh_thread_id_t t1, frsh_thread_id_t t2)
+{
+ if ( pthread_equal(t1.pthread_id, t2.pthread_id &&
+ t1.linux_pid == t2.linux_pid &&
+ t1.linux_tid == t2.linux_tid) )
+ return true;
+
+ return false;
+}
+
+frsh_thread_id_t fosa_thread_self()
+{
+ frsh_thread_id_t thread_self;
+ /*
+ * Fill the user pointer with appropriate data for the calling thread
+ * NB. Remember:
+ * frsh_thread_id_t => struct {
+ * pthread_t pthread_id;
+ * pid_t linux_pid;
+ * tid_t linux_tid;
+ * };
+ */
+ thread_self.pthread_id = pthread_self(); /* only valid for threads! */
+ thread_self.linux_pid = getpid();
+ thread_self.linux_tid = syscall(__NR_gettid); /* equal to gettid() */
+
+ return thread_self;
+}
+
+/*************************
+ * Thread creation and termination
+ *************************/
+
+int fosa_thread_create(frsh_thread_id_t *tid,
+ const frsh_thread_attr_t *attr,
+ frsh_thread_code_t code,
+ void *arg)
+{
+ pthread_t tmp_tid;
+
+ /* 'tid' can't be used, act other ways
+ * to get the thread id of the new thread */
+ return pthread_create(&tmp_tid,attr,code, arg);
+}
+
+/**************************************************
+ * 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
+ **************************************************/
+
+int fosa_thread_set_specific_data(int key,
+ frsh_thread_id_t tid,
+ const void *value)
+{
+ //if ((key > 0) && (key < (FOSA_MAX_KEYS-1))) {
+ // tid.pthread_id->tsd[key] = (void *) value;
+ //
+ // return 0;
+ //}
+
+ errno = EINVAL;
+ return -1;
+}
+
+int fosa_thread_get_specific_data(int key,
+ frsh_thread_id_t tid,
+ void **value)
+{
+ //if ((key > 0) && (key < (FOSA_MAX_KEYS-1))) {
+ // *value=pthread_remote_getspecific(key,tid);
+ // *value=tid.pthread_id->tsd[key];
+ //
+ // return 0;
+ //}
+
+ errno = EINVAL;
+ return -1;
+
+}
+
+/******************************************************************
+ * 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.
+ *******************************************************************/
+
+int fosa_get_priority_max() {
+ return sched_get_priority_max(0);
+}
+
+int fosa_get_priority_min() {
+ return sched_get_priority_min(0);
+}
+
+int fosa_thread_attr_set_prio(frsh_thread_attr_t *attr, int prio)
+{
+ //if ((sched_get_priority_min(0)<=prio) || (prio<=sched_get_priority_min(0))) {
+ // attr->sched_param.sched_priority = prio;
+ //
+ // return 0;
+ //}
+
+ errno = EINVAL;
+ return -1;
+}
+
+int fosa_thread_attr_get_prio (const frsh_thread_attr_t *attr, int *prio)
+{
+ //*prio = attr->sched_param.sched_priority;
+ //return 0;
+
+ errno = EINVAL;
+ return -1;
+}
+
+int 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.pthread_id,prio);
+ // return 0;
+ //}
+
+ errno = EINVAL;
+ return -1;
+}
+
+int fosa_thread_get_prio (frsh_thread_id_t tid, int *prio)
+{
+ //*prio = tid.pthread_id->sched_param.sched_priority;
+ //return 0;
+
+ errno = EINVAL;
+ return -1;
+}
+
+/*******************************************************************
+ * 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.
+ *******************************************************************/
+
+/* it's an hack and it does not work!
+ * We need to change the API if we want such a feature!!*/
+sigset_t original_mask;
+
+int fosa_set_accepted_signals(frsh_signal_t set[], int size)
+{
+ int x;
+ sigset_t new_mask;
+
+ /* all signal blocked by default */
+ sigfillset(&new_mask);
+ for (x = 0; x < size; x++)
+ /* unblock only the signals in 'set' */
+ sigdelset(&new_mask, set[x]);
+
+ /* NB. save the original mask in the
+ * default variable... Orrible hack!! :-( */
+ return pthread_sigmask(SIG_SETMASK, &new_mask, &original_mask);
+}
+
+int fosa_signal_queue(frsh_signal_t signal,
+ frsh_signal_info_t info,
+ frsh_thread_id_t receiver)
+{
+ union sigval siginfo;
+
+ siginfo.sival_int = info.value;
+ return sigqueue(receiver.linux_pid, signal, siginfo);
+}
+
+int fosa_signal_wait (frsh_signal_t set[],
+ int size,
+ frsh_signal_t *signal_received,
+ frsh_signal_info_t *info)
+{
+ int x;
+ sigset_t wait_mask;
+ siginfo_t recv_signal_info;
+
+ /* only wait for the signals in 'set' */
+ sigemptyset(&wait_mask);
+ for (x = 0; x < size; x++)
+ sigaddset(&wait_mask, set[x]);
+ /* go to sleep and let's hope someone wake up us !! */
+ if (sigwaitinfo(&wait_mask, &recv_signal_info) < 0)
+ return -1;
+ /* return back informations for the caller */
+ *signal_received = recv_signal_info.si_signo;
+ info->value = recv_signal_info.si_value.sival_int;
+ /* reset the signal mask to original one (orrible hack!!) */
+ pthread_sigmask(SIG_SETMASK, &original_mask, NULL);
+
+ return 0;
+}
+
+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;
+ sigset_t wait_mask;
+ siginfo_t recv_signal_info;
+
+ /* only wait for the signals in 'set' */
+ sigemptyset(&wait_mask);
+ for (x = 0; x < size; x++)
+ sigaddset(&wait_mask, set[x]);
+ /* go to sleep and let's hope someone wake up us !! */
+ if (sigtimedwait(&wait_mask, &recv_signal_info, timeout) < 0)
+ return -1;
+ /* return back informations for the caller */
+ if (signal_received != NULL)
+ *signal_received = recv_signal_info.si_signo;
+ if (info != NULL)
+ info->value = recv_signal_info.si_value.sival_int;
+ /* reset the signal mask to original one (orrible hack!!) */
+ pthread_sigmask(SIG_SETMASK, &original_mask, NULL);
+
+ return 0;
+}
+