#ifndef _FOSA_H_
#define _FOSA_H_
-#include "frsh_fosa.h"
-
#include "fosa_configuration_parameters.h"
#include "fosa_types.h"
#include "fosa_mutexes_and_condvars.h"
#include "fosa_app_def_sched.h"
#include "fosa_long_jump.h"
+#include "fosa_time.h"
/**
* implementation and dependant applications
**/
int fosa_thread_attr_set_appscheduled
- (frsh_thread_attr_t *attr,
+ (fosa_thread_attr_t *attr,
bool appscheduled);
/**
* implementation and dependant applications
**/
int fosa_thread_attr_get_appscheduled
- (const frsh_thread_attr_t *attr,
+ (const fosa_thread_attr_t *attr,
bool *appscheduled);
/**
* implementation and dependant applications
**/
int fosa_thread_attr_set_appsched_params
- (frsh_thread_attr_t *attr,
+ (fosa_thread_attr_t *attr,
const void *param,
size_t paramsize);
* implementation and dependant applications
**/
int fosa_thread_attr_get_appsched_params
- (const frsh_thread_attr_t *attr,
+ (const fosa_thread_attr_t *attr,
void *param,
size_t *paramsize);
* implementation and dependant applications
**/
int fosa_ads_set_appscheduled
- (frsh_thread_id_t thread,
+ (fosa_thread_id_t thread,
bool appscheduled);
/**
* implementation and dependant applications
**/
int fosa_ads_get_appscheduled
- (frsh_thread_id_t thread,
+ (fosa_thread_id_t thread,
bool *appscheduled);
* implementation and dependant applications
**/
int fosa_ads_set_appsched_params
- (frsh_thread_id_t thread,
+ (fosa_thread_id_t thread,
const void *param,
size_t paramsize);
* implementation and dependant applications.
**/
int fosa_ads_get_appsched_params
- (frsh_thread_id_t thread,
+ (fosa_thread_id_t thread,
void *param,
size_t *paramsize);
**/
int fosa_adsactions_add_reject(
fosa_ads_actions_t *sched_actions,
- frsh_thread_id_t thread);
+ fosa_thread_id_t thread);
/**
* fosa_adsactions_add_activate()
**/
int fosa_adsactions_add_activate(
fosa_ads_actions_t *sched_actions,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
fosa_ads_urgency_t urgency);
/**
**/
int fosa_adsactions_add_suspend(
fosa_ads_actions_t *sched_actions,
- frsh_thread_id_t thread);
+ fosa_thread_id_t thread);
/**
* fosa_adsactions_add_timeout()
**/
int fosa_adsactions_add_thread_notification(
fosa_ads_actions_t *sched_actions,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
fosa_clock_id_t clock_id,
const struct timespec *at_time);
* notify it to the system console and then terminate the FRSH
* implementation and dependant applications
**/
-int fosa_ads_set_handled_signal_set(frsh_signal_t set[], int size);
+int fosa_ads_set_handled_signal_set(fosa_signal_t set[], int size);
/**
* notification message.
*
* Besides for the scheduler we don't have always a destinator
- * thread_id needed in frsh_signal_queue for OSE.
+ * thread_id needed in fosa_signal_queue for OSE.
*
* So the fosa implementation will solve this issue internally.
*
* notify it to the system console and then terminate the FRSH
* implementation and dependant applications
**/
-int fosa_signal_queue_scheduler(frsh_signal_t signal, frsh_signal_info_t info);
+int fosa_signal_queue_scheduler(fosa_signal_t signal, fosa_signal_info_t info);
/**
* notify it to the system console and then terminate the FRSH
* implementation and dependant applications
**/
-int fosa_thread_get_cputime_clock(frsh_thread_id_t tid, fosa_clock_id_t *clockid);
+int fosa_thread_get_cputime_clock(fosa_thread_id_t tid, fosa_clock_id_t *clockid);
/*************************
* implementation and dependant applications
**/
int fosa_timer_create
- (fosa_clock_id_t clockid, frsh_signal_t signal, frsh_signal_info_t info,
+ (fosa_clock_id_t clockid, fosa_signal_t signal, fosa_signal_info_t info,
fosa_timer_id_t *timerid);
/**
* implementation and dependant applications
**/
int fosa_timer_create_with_receiver
- (fosa_clock_id_t clockid, frsh_signal_t signal, frsh_signal_info_t info,
- fosa_timer_id_t *timerid, frsh_thread_id_t receiver);
+ (fosa_clock_id_t clockid, fosa_signal_t signal, fosa_signal_info_t info,
+ fosa_timer_id_t *timerid, fosa_thread_id_t receiver);
/**
* fosa_timer_delete()
/**
* Real-time signal number reserved for the long jump handler
**/
-#define FOSA_LONG_JUMP_SIGNAL FRSH_SIGNAL_MIN+1
+#define FOSA_LONG_JUMP_SIGNAL FOSA_SIGNAL_MIN+1
* implementation and dependant applications
*/
int fosa_long_jump_install_handler
-(frsh_signal_t *signal, frsh_thread_id_t *handler);
+(fosa_signal_t *signal, fosa_thread_id_t *handler);
* notify it to the system console and then terminate the FRSH
* implementation and dependant applications
**/
-int fosa_mutex_init(frsh_mutex_t *mutex, int prioceiling);
+int fosa_mutex_init(fosa_mutex_t *mutex, int prioceiling);
/**
* fosa_mutex_destroy()
* notify it to the system console and then terminate the FRSH
* implementation and dependant applications
**/
-int fosa_mutex_destroy(frsh_mutex_t *mutex);
+int fosa_mutex_destroy(fosa_mutex_t *mutex);
/**
* fosa_mutex_set_prioceiling()
* implementation and dependant applications
**/
int fosa_mutex_set_prioceiling
- (frsh_mutex_t *mutex, int new_ceiling, int *old_ceiling);
+ (fosa_mutex_t *mutex, int new_ceiling, int *old_ceiling);
/**
* fosa_mutex_get_prioceiling()
* notify it to the system console and then terminate the FRSH
* implementation and dependant applications
**/
-int fosa_mutex_get_prioceiling(const frsh_mutex_t *mutex, int *ceiling);
+int fosa_mutex_get_prioceiling(const fosa_mutex_t *mutex, int *ceiling);
/**
* fosa_mutex_lock()
* notify it to the system console and then terminate the FRSH
* implementation and dependant applications
**/
-int fosa_mutex_lock(frsh_mutex_t *mutex);
+int fosa_mutex_lock(fosa_mutex_t *mutex);
/**
* fosa_mutex_trylock()
* implementation is allowed to notify it to the system console and
* then terminate the FRSH implementation and dependant applications
**/
-int fosa_mutex_trylock(frsh_mutex_t *mutex);
+int fosa_mutex_trylock(fosa_mutex_t *mutex);
/**
* fosa_mutex_unlock()
* implementation is allowed to notify it to the system console and
* then terminate the FRSH implementation and dependant applications
**/
-int fosa_mutex_unlock(frsh_mutex_t *mutex);
+int fosa_mutex_unlock(fosa_mutex_t *mutex);
/**********************
* notify it to the system console and then terminate the FRSH
* implementation and dependant applications
**/
-int fosa_cond_wait(fosa_cond_t *cond, frsh_mutex_t *mutex);
+int fosa_cond_wait(fosa_cond_t *cond, fosa_mutex_t *mutex);
/**
* fosa_cond_timedwait()
* implementation is allowed to notify it to the system console and
* then terminate the FRSH implementation and dependant applications
**/
-int fosa_cond_timedwait(fosa_cond_t *cond, frsh_mutex_t *mutex,
+int fosa_cond_timedwait(fosa_cond_t *cond, fosa_mutex_t *mutex,
const struct timespec *abstime);
/*@}*/
#include <stdbool.h>
-/////////////////////// RT_LINUX, MARTE_OS & AQuoSA ///////////////////////////
+/////////////////////// MARTE_OS /////////////////////////////
-#if defined(RT_LINUX) || defined(MARTE_OS) || defined(AQuoSA)
+#ifdef MARTE_OS
-#ifdef AQuoSA
-#define __USE_UNIX98
-#endif // AQuoSA
#include <pthread.h>
#include <signal.h>
#include <time.h>
#include <sched.h>
+#include <errno.h>
-#ifdef RT_LINUX
-#include <rtl_timer.h>
-#endif // RT_LINUX
+/* Time */
+/********/
+// typedef struct timespec fosa_rel_time_t;
+// typedef struct timespec fosa_abs_time_t;
-#define FOSA_CLOCK_ID_T_OPAQUE clockid_t
-#define FOSA_SYSTEM_CLOCK_OPAQUE CLOCK_MONOTONIC
+/* Thread and signals */
+/**********************/
+typedef pthread_t FOSA_THREAD_ID_T_OPAQUE;
+typedef pthread_attr_t FOSA_THREAD_ATTR_T_OPAQUE;
-#define FOSA_TIMER_ID_T_OPAQUE timer_t
+typedef int FOSA_SIGNAL_T_OPAQUE;
+/* Signal info is defined as a union in thread_and_signals */
-#define FOSA_COND_T_OPAQUE pthread_cond_t
+#define FOSA_SIGNAL_MIN SIGRTMIN
+#define FOSA_SIGNAL_MAX SIGRTMIN+0
-/*********
- * ADS
- *********/
+#define FOSA_NULL_SIGNAL 0
-#ifdef MARTE_OS
+/* Clocks and timers */
+/**********************/
+typedef clockid_t FOSA_CLOCK_ID_T_OPAQUE;
+typedef timer_t FOSA_TIMER_ID_T_OPAQUE;
+
+#define FOSA_SYSTEM_CLOCK_OPAQUE CLOCK_MONOTONIC
+
+/* Mutex and conditional variables */
+/***********************************/
+typedef pthread_mutex_t FOSA_MUTEX_T_OPAQUE;
+typedef pthread_cond_t FOSA_COND_T_OPAQUE;
+
+
+/* Application defined Scheduling */
+/**********************************/
typedef struct {
posix_appsched_actions_t actions;
- struct timespec * timeout_ptr;
+ struct timespec *timeout_ptr;
struct timespec timeout;
bool rejected;
bool suspended;
bool activated;
} fosa_ads_actions_internal_t;
-
#define FOSA_ADS_ACTIONS_T_OPAQUE fosa_ads_actions_internal_t
-///////////////////
-// Long jumps
-///////////////////
-
+/* Local jump */
+/**************/
#include "marte_non_local_jmp.h"
#define FOSA_LONG_JUMP_CONTEXT_T_OPAQUE struct { \
marte_nonlocaljmp_context_t marte_context; \
- frsh_thread_id_t tid; \
+ fosa_thread_id_t tid; \
}
-#else // MARTE_OS
+/* FOSA errors */
+/***************/
+/** Not enough memory available **/
+#define FOSA_ENOMEM ENOMEM
+
+/** Invalid parameter **/
+#define FOSA_EINVAL EINVAL
+
+/** Still pending information **/
+#define FOSA_EAGAIN EAGAIN
+
+/** FOSA ADS errors **/
+#ifdef MARTE_OS
+#define EREJECT 201 /* (for linux_lib_arch) Appsched has rejected object */
+#endif
+
+#define FOSA_EREJECT EREJECT
+#define FOSA_EMASKED -2
+#define FOSA_EPOLICY -3
+
+#define FOSA_ETIMEDOUT ETIMEDOUT
+
+#endif
+
+/////////////////////// End of MARTE_OS /////////////////////////////
+
+
+/////////////////////// RT_LINUX ///////////////////////////
+
+#ifdef RT_LINUX
+
+/* Very similar to MARTE_OS but I leave separate for clarity */
+
+#include <pthread.h>
+#include <signal.h>
+#include <time.h>
+#include <sched.h>
+#include <errno.h>
+#include <rtl_timer.h>
+
+/* Time */
+/********/
+// typedef struct timespec fosa_rel_time_t;
+// typedef struct timespec fosa_abs_time_t;
+
+
+/* Threads and signals */
+/***********************/
+#define FOSA_THREAD_ID_T_OPAQUE pthread_t
+
+typedef pthread_attr_t FOSA_THREAD_ATTR_T_OPAQUE;
+typedef int FOSA_SIGNAL_T_OPAQUE;
+/* Signal info is defined as a union in fosa_types.h */
+
+// The minimum and maximum signal numbers that may be used by the FRSH
+// implementation
+#define FOSA_SIGNAL_MIN SIGRTMIN
+#define FOSA_SIGNAL_MAX SIGRTMIN+0
+#define FOSA_NULL_SIGNAL 0
+
+/* Clocks and timers */
+/*********************/
+#define FOSA_CLOCK_ID_T_OPAQUE clockid_t
+#define FOSA_TIMER_ID_T_OPAQUE timer_t
+#define FOSA_SYSTEM_CLOCK_OPAQUE CLOCK_MONOTONIC
+
+/* Mutex and cond vars */
+/***********************/
+typedef pthread_mutex_t FOSA_MUTEX_T_OPAQUE;
+#define FOSA_COND_T_OPAQUE pthread_cond_t
+
+
+/* FOSA Errors */
+/***************/
+/** Not enough memory available **/
+#define FOSA_ENOMEM ENOMEM
+/** Invalid parameter **/
+#define FOSA_EINVAL EINVAL
+/** Still pending information **/
+#define FOSA_EAGAIN EAGAIN
+
+/** FOSA ADS errors **/
+#define FOSA_EREJECT EREJECT
+#define FOSA_EMASKED -2
+#define FOSA_EPOLICY -3
+
+#define FOSA_ETIMEDOUT ETIMEDOUT
+
+#endif
+
+/////////////////////// End of RT_LINUX /////////////////////////////
+
+
+////////////////////////// OSE //////////////////////////////////////
+
+#ifdef OSE
+
+/* Time */
+/********/
+// typedef struct timespec fosa_rel_time_t;
+// typedef struct timespec fosa_abs_time_t;
+
+
+/* Put OSE dependent includes and defines here */
+
+#endif /* OSE */
+
+
+
+/////////////////////// AQuoSA ///////////////////////////
+
+#ifdef AQuoSA
+
+#define __USE_UNIX98
+
+#include <pthread.h>
+#include <signal.h>
+#include <errno.h>
+#include <time.h>
+
+/* Time */
+/********/
+// typedef struct timespec fosa_rel_time_t;
+// typedef struct timespec fosa_abs_time_t;
+
+
+/* Threads and signals */
+/***********************/
+typedef struct {
+ pthread_t pthread_id;
+ pid_t linux_pid;
+ pid_t linux_tid;
+} FOSA_THREAD_ID_T_OPAQUE;
+
+
+typedef pthread_attr_t FOSA_THREAD_ATTR_T_OPAQUE;
+typedef int FOSA_SIGNAL_T_OPAQUE;
+
+
+// The minimum and maximum signal numbers that may be used by the FRSH
+// implementation
+#define FOSA_SIGNAL_MIN SIGRTMIN
+#define FOSA_SIGNAL_MAX SIGRTMIN+0
+
+#define FOSA_NULL_SIGNAL 0
+
+
+/* Clocks and signals */
+/**********************/
+#define FOSA_CLOCK_ID_T_OPAQUE clockid_t
+#define FOSA_SYSTEM_CLOCK_OPAQUE CLOCK_MONOTONIC
+#define FOSA_TIMER_ID_T_OPAQUE timer_t
+
+
+
+/* Mutex and cond vars */
+/***********************/
+typedef pthread_mutex_t FOSA_MUTEX_T_OPAQUE;
+#define FOSA_COND_T_OPAQUE pthread_cond_t
+
+
+/* Application Defined Scheduling */
+/**********************************/
/* hack to get AQuoSA sources compile without having none
* of the application level scheduler header files and symbols */
-#ifdef AQuoSA
#define posix_appsched_actions_t int
#define FOSA_LONG_JUMP_CONTEXT_T_OPAQUE int
-#endif // AQuoSA
#define FOSA_ADS_ACTIONS_T_OPAQUE posix_appsched_actions_t
-#endif // MARTE_OS
+/* FOSA Errors */
+
+/** Not enough memory available **/
+#define FOSA_ENOMEM ENOMEM
+
+/** Invalid parameter **/
+#define FOSA_EINVAL EINVAL
+
+/** Still pending information **/
+#define FOSA_EAGAIN EAGAIN
+
+#define FOSA_EREJECT EREJECT
+#define FOSA_EMASKED -2
+#define FOSA_EPOLICY -3
+
+#define FOSA_ETIMEDOUT ETIMEDOUT
+
+
+#endif
+////////////////// END of AQuoSA //////////////////////
+
+
+////////////////////////// VIRTUAL TIME //////////////////////////////////////
+#ifdef VIRTUAL_TIME
+
+/* Time */
+/********/
+// typedef struct timespec fosa_rel_time_t;
+// typedef struct timespec fosa_abs_time_t;
+
+#include <fosa_vt.h>
+
+#define FOSA_THREAD_ID_T_OPAQUE vt_posix_process_t
+#define FOSA_THREAD_ATTR_T_OPAQUE fosa_thread_attr_t
+#define FOSA_SIGNAL_T_OPAQUE int
+
+#define FOSA_MUTEX_T_OPAQUE fosa_mutex_t
+
+// The minimum and maximum signal numbers that may be used by the FRSH
+// implementation
+#define FOSA_SIGNAL_MIN 8
+#define FOSA_SIGNAL_MAX 31
-#endif // defined(RT_LINUX) || defined(MARTE_OS) || defined(AQuoSA)
+// the min. and max. priority a fosa thread can have
+#define FOSA_PRIORITY_MAX VT_PRIORITY_MIN - 1
+#define FOSA_PRIORITY_MIN VT_PRIORITY_MAX
+#define FOSA_NULL_SIGNAL 0
-////////////////// END OF RT_LINUX, MARTE_OS and AQuoSA //////////////////////
+/* FOSA Errors and return values*/
+
+/** Invalid parameter **/
+#define FOSA_EINVAL -1
+
+/** Not enough memory available **/
+#define FOSA_ENOMEM -2
+
+/** Still pending information **/
+#define FOSA_EAGAIN -3
+
+/** Mutex not available **/
+#define FOSA_EBUSY -4
+
+/** Cond var timedout **/
+#define FOSA_ETIMEDOUT -5
+
+/** FOSA ADS errors **/
+#define FOSA_EREJECT -6
+#define FOSA_EMASKED -7
+
+
+/** Sched policy not correct */
+#define FOSA_EPOLICY -8
+
+/** the value given by thread_id is not valid for ADS */
+#define FOSA_ESRCH -9
+
+/** retval if no action performed **/
+#define FOSA_NO_ACTION 0
+
+#endif /* VIRTUAL_TIME */
+//////////////////////////End of VIRTUAL TIME ///////////////////////////////////
////////////////////////// DUMMY_OS //////////////////////////////////////
/* independent at the FRSH code. */
/*****************************************************************/
-#define FOSA_CLOCK_ID_T_OPAQUE int
-#define FOSA_SYSTEM_CLOCK_OPAQUE 42
+/* Time */
+/********/
+// typedef struct timespec fosa_rel_time_t;
+// typedef struct timespec fosa_abs_time_t;
-#define FOSA_TIMER_ID_T_OPAQUE int
+/* Thread and signals */
+/**********************/
+typedef int FOSA_THREAD_ID_T_OPAQUE;
+typedef int FOSA_THREAD_ATTR_T_OPAQUE;
-#define FOSA_COND_T_OPAQUE int
+typedef int FOSA_SIGNAL_T_OPAQUE;
+typedef int FOSA_SIGNAL_INFO_T_OPAQUE;
+/* Signal info is defined as a union in thread_and_signals */
-/*********
- * ADS
- *********/
+#define FOSA_SIGNAL_MIN 42
+#define FOSA_SIGNAL_MAX 44
-#define FOSA_ADS_ACTIONS_T_OPAQUE int
+#define FOSA_NULL_SIGNAL 0
+/* Clocks and timers */
+/**********************/
+typedef int FOSA_CLOCK_ID_T_OPAQUE;
+typedef int FOSA_TIMER_ID_T_OPAQUE;
+#define FOSA_SYSTEM_CLOCK_OPAQUE 25
+
+/* Mutex and conditional variables */
+/***********************************/
+typedef int FOSA_MUTEX_T_OPAQUE;
+typedef int FOSA_COND_T_OPAQUE;
+
+/* Application defined Scheduling */
+/**********************************/
+#define FOSA_ADS_ACTIONS_T_OPAQUE int
#endif /* DUMMY */
* @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);
/**
*
* 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);
/*************************
*
**/
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);
/**
* 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()
* 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);
* 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()
* Returns 0
**/
int fosa_thread_attr_get_prio
- (const frsh_thread_attr_t *attr, int *prio);
+ (const fosa_thread_attr_t *attr, int *prio);
/**
* fosa_thread_set_prio()
* 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()
*
* 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);
* 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.
*******************************************************************/
* 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()
* implementation and dependant applications
**/
int fosa_signal_queue
- (frsh_signal_t signal, frsh_signal_info_t info,
- frsh_thread_id_t receiver);
+ (fosa_signal_t signal, fosa_signal_info_t info,
+ fosa_thread_id_t receiver);
* 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()
* 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);
/*}*/
--- /dev/null
+/*
+** fosa_time.h
+**
+** Made by Miguel marciano
+** Login <miguel@namir.ctr.unican.es>
+**
+** Started on Mon Jan 21 20:01:04 2008 Miguel marciano
+** Last update Mon Jan 21 20:01:04 2008 Miguel marciano
+*/
+#ifndef FOSA_TIME_H_
+#define FOSA_TIME_H_
+
+/**
+ * fosa_eat()
+ *
+ * Eat some time using system clock facilities
+ **/
+void inline fosa_eat(const struct timespec *cpu_time);
+
+
+#endif /* !FOSA_TIME_H_ */
#define _FOSA_TYPES_H_
#include "fosa_opaque_types.h"
-#include "frsh_fosa.h"
+/**
+ * @addtogroup threadandsignals
+ *
+ * @{
+ **/
+
+/* Coming from FRSH-FOSA */
+
+/** identifier of a FOSA thread **/
+typedef FOSA_THREAD_ID_T_OPAQUE fosa_thread_id_t;
+
+
+/** thread attributes object **/
+typedef FOSA_THREAD_ATTR_T_OPAQUE fosa_thread_attr_t;
+
+typedef FOSA_SIGNAL_T_OPAQUE fosa_signal_t;
+
+/**
+ * The type references a function that may become a thread's
+ * code
+ **/
+typedef void * (*fosa_thread_code_t) (void *);
+
+
+/** information associated to a signal **/
+#if defined(VIRTUAL_TIME)
+
+#include <vt_ose.h>
+typedef vt_posix_signal_info_t fosa_signal_info_t;
+
+#else
+
+typedef union {int sival_int; void * sival_ptr; } fosa_signal_info_t;
+/* typedef FOSA_SIGNAL_INFO_T_OPAQUE fosa_signal_info_t; */
+
+#endif
+
+/* @} */
+
+
/**
* @addtogroup clocksandtimers
*
* @{
**/
// a condition variable
+/** Mutex object. Attributes are handled by FOSA **/
+typedef FOSA_MUTEX_T_OPAQUE fosa_mutex_t;
+
typedef FOSA_COND_T_OPAQUE fosa_cond_t;
/*@}*/
typedef struct {
void (*init) (void * sched_data, void * arg);
void (*new_thread) (void * sched_data,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
fosa_ads_actions_t * actions,
struct timespec *current_time);
void (*thread_terminate) (void * sched_data,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
fosa_ads_actions_t * actions,
struct timespec *current_time);
void (*thread_ready) (void * sched_data,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
fosa_ads_actions_t * actions,
struct timespec *current_time);
void (*thread_block) (void * sched_data,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
fosa_ads_actions_t * actions,
struct timespec *current_time);
//void (*thread_yield) (void * sched_data,
- // frsh_thread_id_t thread,
+ // fosa_thread_id_t thread,
// fosa_ads_actions_t * actions,
// struct timespec *current_time);
void (*change_sched_param_thread) (void * sched_data,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
fosa_ads_actions_t * actions,
struct timespec *current_time);
//void msg_from_scheduler(void * sched_data,
// fosa_ads_actions_t * actions,
// struct timespec *current_time);
//void (*explicit_call) (void * sched_data,
- // frsh_thread_id_t thread,
+ // fosa_thread_id_t thread,
// int user_event_code,
// fosa_ads_actions_t * actions,
// struct timespec *current_time);
void (*explicit_call_with_data) (void * sched_data,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
const void * msg, size_t msg_size,
void *reply, size_t *reply_size,
fosa_ads_actions_t * actions,
struct timespec *current_time);
void (*notification_for_thread) (void * sched_data,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
fosa_clock_id_t clock,
fosa_ads_actions_t * actions,
struct timespec *current_time);
fosa_ads_actions_t * actions,
struct timespec *current_time);
void (*signal) (void * sched_data,
- frsh_signal_t signal,
- frsh_signal_info_t siginfo,
+ fosa_signal_t signal,
+ fosa_signal_info_t siginfo,
fosa_ads_actions_t * actions,
struct timespec *current_time);
//void (*priority_inherit) (void * sched_data,
- // frsh_thread_id_t thread,
+ // fosa_thread_id_t thread,
// int sched_priority,
// fosa_ads_actions_t * actions,
// struct timespec *current_time);
//void (*priority_uninherit) (void * sched_data,
- // frsh_thread_id_t thread,
+ // fosa_thread_id_t thread,
// int sched_priority,
// fosa_ads_actions_t * actions,
// struct timespec *current_time);
void (*appsched_error) (void * sched_data,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
fosa_ads_error_cause_t cause,
fosa_ads_actions_t * actions);
} fosa_ads_scheduler_ops_t;
--- /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. Politécnica 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.
+//
+//
+// 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
+//
+// FSF API web pages: http://marte.unican.es/fsf/docs
+// http://shark.sssup.it/contrib/first/docs/
+//
+// This file is part of FRSH API
+//
+// FRSH API 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 API 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 API; 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.
+// -----------------------------------------------------------------------
+/*-----------------------------------------------------------------------
+ * V1.0 Dec 2001
+ *
+ * 't i m e s p e c _ o p e r a t i o n s'
+ *
+ * H
+ *
+ * File 'timespec_operations.h' by MAR.
+ * (july 2002) transformed into macros by Jul.
+ * Some basic operations with the type 'timespec'.
+ *
+ * ----------------------------------------------------------------------
+ * Copyright (C) 2001 Universidad de Cantabria, SPAIN
+ *
+ * Authors: Mario Aldea Rivas aldeam@ctr.unican.es
+ * Michael Gonzalez Harbour mgh@ctr.unican.es
+ *
+ * MaRTE OS 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.
+ *
+ * MaRTE OS 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 MaRTE OS; 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 link this unit with other files to
+ * produce an executable, this unit 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 Public License.
+ *
+ *---------------------------------------------------------------------------*/
+// 16-Jul-2007 SANGORRIN corrections to msec_addto_timespec and msec2timespec
+// 23-Jul-2007 SANGORRIN moved t2d and d2t from frsh_time_operations
+// (TODO: test for __ALL__ the functions)
+// -----------------------------------------------------------------------
+
+#ifndef _MARTE_MISC_TIMESPEC_OPERATIONS_H_
+#define _MARTE_MISC_TIMESPEC_OPERATIONS_H_
+
+/**
+ * @file timespec_operations.h
+ **/
+
+#include <time.h> // for timespec
+#include <string.h> // for memset
+
+#define smaller_timespec(t1, t2) \
+ ( \
+ (t1)->tv_sec < (t2)->tv_sec || ((t1)->tv_sec == (t2)->tv_sec && \
+ (t1)->tv_nsec < (t2)->tv_nsec) \
+ )
+
+#define smaller_or_equal_timespec(t1, t2) \
+ ( \
+ (t1)->tv_sec < (t2)->tv_sec || ((t1)->tv_sec == (t2)->tv_sec && \
+ (t1)->tv_nsec <= (t2)->tv_nsec) \
+ )
+
+#define incr_timespec(t1, t2) \
+do { \
+ (t1)->tv_sec += (t2)->tv_sec; \
+ (t1)->tv_nsec += (t2)->tv_nsec; \
+ if ((t1)->tv_nsec >= 1000000000) { \
+ (t1)->tv_sec ++; \
+ (t1)->tv_nsec -= 1000000000; \
+ } \
+} while (0)
+
+#define decr_timespec(t1, t2) \
+do { \
+ if ((t1)->tv_nsec < (t2)->tv_nsec) { \
+ (t1)->tv_sec -= (t2)->tv_sec + 1; \
+ (t1)->tv_nsec = (t1)->tv_nsec + 1000000000 - (t2)->tv_nsec; \
+ } else { \
+ (t1)->tv_sec -= (t2)->tv_sec; \
+ (t1)->tv_nsec -= (t2)->tv_nsec; \
+ } \
+} while (0)
+
+#define add_timespec( sum , t1 , t2 ) \
+do { \
+ (sum)->tv_sec = (t1)->tv_sec + (t2)->tv_sec; \
+ (sum)->tv_nsec = (t1)->tv_nsec + (t2)->tv_nsec; \
+ if ((sum)->tv_nsec >= 1000000000) { \
+ (sum)->tv_sec ++; \
+ (sum)->tv_nsec -= 1000000000; \
+ } \
+} while (0)
+
+#define float_to_timespec( f1 , t1 ) \
+( \
+ (t1)->tv_sec = (int)(f1), \
+ (t1)->tv_nsec = (int)(((f1)-(float)((t1)->tv_sec))*1000000000.0), \
+ (t1) \
+)
+
+#define float_to_timespec_value(f1, t1) \
+( \
+ (t1).tv_sec = (int)(f1), \
+ (t1).tv_nsec = (int)(((f1)-(float)((t1).tv_sec))*1000000000.0), \
+ (t1) \
+)
+
+//---------------//
+// msec2timespec //
+//---------------//
+
+static inline struct timespec msec2timespec(long msec)
+{
+ struct timespec result = {-1, -1};
+
+ if (msec >= 1000) {
+ result.tv_sec = msec/1000;
+ result.tv_nsec = (msec % 1000) * 1000000;
+ } else {
+ result.tv_sec = 0;
+ result.tv_nsec = msec * 1000000;
+ }
+
+ return result;
+}
+
+static inline long timespec2msec(const struct timespec *timespec)
+{
+
+ return (timespec->tv_sec % 2147482) * 1000 + timespec->tv_nsec/1000000;
+}
+
+
+#define HOURS_IN_MSECS 3600000
+#define MINUTES_IN_MSECS 60000
+
+#define HOURS_IN_TS 1000000
+#define MINUTES_IN_TS 100000
+
+static inline long timespec2msects(const struct timespec *timespec)
+{
+ long msec_total = -1;
+ long minutes = -1;
+ long hours = -1;
+
+ long remainder_msecs = -1;
+ long timestamp = -1;
+
+ msec_total = (timespec->tv_sec % 2147482) * 1000 + timespec->tv_nsec/1000000;
+
+ hours = msec_total / HOURS_IN_MSECS;
+ minutes = (msec_total % HOURS_IN_MSECS) / MINUTES_IN_MSECS;
+ remainder_msecs = ( (msec_total % HOURS_IN_MSECS) % MINUTES_IN_MSECS);
+
+ timestamp = hours*HOURS_IN_TS + minutes*MINUTES_IN_TS + remainder_msecs;
+
+ return timestamp;
+}
+
+
+//------------------------//
+// timespec_lessthan_msec //
+//------------------------//
+
+static inline int timespec_lessthan_msec(struct timespec *timespec, long msec)
+{
+ struct timespec msec_timespec = {0, 0};
+
+ msec_timespec = msec2timespec(msec);
+ return smaller_timespec(timespec, &msec_timespec);
+}
+
+//---------------------//
+// msec_addto_timespec //
+//---------------------//
+
+static inline void msec_addto_timespec(long msec, struct timespec *timespec)
+{
+ struct timespec msec_timespec = {0, 0};
+
+ msec_timespec = msec2timespec(msec);
+ incr_timespec(timespec, &msec_timespec);
+}
+
+//--------------------------//
+// t2d (timespec to double) //
+//--------------------------//
+
+static inline double t2d(struct timespec time)
+{
+ return time.tv_nsec*0.000000001 + (double)time.tv_sec;
+}
+
+//--------------------------//
+// d2t (double to timespec) //
+//--------------------------//
+
+static inline struct timespec d2t(double time)
+{
+ struct timespec tmp;
+
+ tmp.tv_sec = (long) time;
+ tmp.tv_nsec = (long)((time - (double)tmp.tv_sec) * 1000000000);
+
+ return tmp;
+}
+
+#endif /* _MARTE_MISC_TIMESPEC_OPERATIONS_H_ */
CFLAGS += -D$(PLATFORM) \
- -I$(FRSH_PATH)/include \
-I$(FOSA_PATH)/include \
-I$(UTILS_PATH)/include
// before suspend or activate it.
// -----------------------------------------------------------------------
-#include "fosa_app_def_sched.h"
-#include "fosa_configuration_parameters.h"
-#include "fosa_threads_and_signals.h"
-#include "frsh_error.h"
-#include "frsh_fosa.h"
+#include "fosa.h"
#include <pthread.h>
#include <stdio.h>
sch_thread_data->scheduler_ops.signal
(scheduler_data,
event.event_info.siginfo.si_signo,
- *((frsh_signal_info_t *)(&(event.event_info.siginfo.si_value))),
+ *((fosa_signal_info_t *)(&(event.event_info.siginfo.si_value))),
// the above casting construct is used to overcome the compiler
// restriction that does not allow casts between unions
&sched_actions,
* implementation and dependant applications
**/
int fosa_thread_attr_set_appscheduled
- (frsh_thread_attr_t *attr,
+ (fosa_thread_attr_t *attr,
bool appscheduled)
{
int error_code;
* implementation and dependant applications
**/
int fosa_thread_attr_get_appscheduled
- (const frsh_thread_attr_t *attr,
+ (const fosa_thread_attr_t *attr,
bool *appscheduled)
{
int policy, ret_value;
* implementation and dependant applications
**/
int fosa_thread_attr_set_appsched_params
- (frsh_thread_attr_t *attr,
+ (fosa_thread_attr_t *attr,
const void *param,
size_t paramsize)
{
* implementation and dependant applications
**/
int fosa_thread_attr_get_appsched_params
- (const frsh_thread_attr_t *attr,
+ (const fosa_thread_attr_t *attr,
void *param,
size_t *paramsize)
{
* implementation and dependant applications
**/
int fosa_ads_set_appscheduled
- (frsh_thread_id_t thread,
+ (fosa_thread_id_t thread,
bool appscheduled)
{
int error_code = 0;
* implementation and dependant applications
**/
int fosa_ads_get_appscheduled
- (frsh_thread_id_t thread,
+ (fosa_thread_id_t thread,
bool *appscheduled)
{
int error_code, policy;
* implementation and dependant applications
**/
int fosa_ads_set_appsched_params
- (frsh_thread_id_t thread,
+ (fosa_thread_id_t thread,
const void *param,
size_t paramsize)
{
* implementation and dependant applications.
**/
int fosa_ads_get_appsched_params
- (frsh_thread_id_t thread,
+ (fosa_thread_id_t thread,
void *param,
size_t *paramsize)
{
**/
int fosa_adsactions_add_reject(
fosa_ads_actions_t *sched_actions,
- frsh_thread_id_t thread)
+ fosa_thread_id_t thread)
{
#ifdef FULL_ERROR_CHECKING
// check errors
**/
int fosa_adsactions_add_activate(
fosa_ads_actions_t *sched_actions,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
fosa_ads_urgency_t urgency)
{
#ifdef FULL_ERROR_CHECKING
**/
int fosa_adsactions_add_suspend(
fosa_ads_actions_t *sched_actions,
- frsh_thread_id_t thread)
+ fosa_thread_id_t thread)
{
#ifdef FULL_ERROR_CHECKING
// check errors
**/
int fosa_adsactions_add_thread_notification(
fosa_ads_actions_t *sched_actions,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
fosa_clock_id_t clock_id,
const struct timespec *at_time)
{
* notify it to the system console and then terminate the FRSH
* implementation and dependant applications
**/
-int fosa_ads_set_handled_signal_set(frsh_signal_t set[], int size)
+int fosa_ads_set_handled_signal_set(fosa_signal_t set[], int size)
{
int i;
* notification message.
*
* Besides for the scheduler we don't have always a destinator
- * thread_id needed in frsh_signal_queue for OSE.
+ * thread_id needed in fosa_signal_queue for OSE.
*
* So the fosa implementation will solve this issue internally.
*
* notify it to the system console and then terminate the FRSH
* implementation and dependant applications
**/
-int fosa_signal_queue_scheduler(frsh_signal_t signal, frsh_signal_info_t info)
+int fosa_signal_queue_scheduler(fosa_signal_t signal, fosa_signal_info_t info)
{
// In MaRTE OS this function is completely equivalent to
// fosa_signal_queue, because there is no notion of receiver.
- frsh_thread_id_t receiver = 0; // Dummy value, not used by MaRTE OS
+ fosa_thread_id_t receiver = 0; // Dummy value, not used by MaRTE OS
return fosa_signal_queue(signal, info, receiver);
}
* implementation and dependant applications
**/
int fosa_thread_get_cputime_clock
- (frsh_thread_id_t tid, fosa_clock_id_t *clockid)
+ (fosa_thread_id_t tid, fosa_clock_id_t *clockid)
{
return pthread_getcpuclockid(tid,clockid);
}
* implementation and dependant applications
**/
int fosa_timer_create
- (fosa_clock_id_t clockid, frsh_signal_t signal, frsh_signal_info_t info,
+ (fosa_clock_id_t clockid, fosa_signal_t signal, fosa_signal_info_t info,
fosa_timer_id_t *timerid)
{
struct sigevent evp;
* implementation and dependant applications
**/
int fosa_timer_create_with_receiver
- (fosa_clock_id_t clockid, frsh_signal_t signal, frsh_signal_info_t info,
- fosa_timer_id_t *timerid, frsh_thread_id_t receiver)
+ (fosa_clock_id_t clockid, fosa_signal_t signal, fosa_signal_info_t info,
+ fosa_timer_id_t *timerid, fosa_thread_id_t receiver)
{
// in POSIX the receiver thread cannot be specified
return fosa_timer_create(clockid,signal,info,timerid);
//================================================
#include <stdio.h>
-#include "fosa_long_jump.h"
-#include "fosa_configuration_parameters.h"
-#include "fosa_threads_and_signals.h"
+#include <stdlib.h>
+
+#include "fosa.h"
#include <marte_non_local_jmp.h>
/**
*/
static int handler_installed=0;
-static frsh_thread_id_t handler_tid;
+static fosa_thread_id_t handler_tid;
/**
* fosa_long_jump_save_context
void * fosa_long_jump_handler (void * arg) {
- frsh_signal_t set[1];
- frsh_signal_t sig;
- frsh_signal_info_t siginfo;
+ fosa_signal_t set[1];
+ fosa_signal_t sig;
+ fosa_signal_info_t siginfo;
fosa_long_jump_context_t *info;
// initialize signal handling
set[0]=FOSA_LONG_JUMP_SIGNAL;
if (fosa_set_accepted_signals(set, 1) !=0) {
- printf("FRSH_ERR_INTERNAL_ERROR, Error setting the signal mask\n");
+ printf("FOSA_ERR_INTERNAL_ERROR, Error setting the signal mask\n");
exit(1);
}
while (1) {
// Wait for a budget overrun signal
if ((fosa_signal_wait(set, 1, &sig, &siginfo)) == -1) {
- printf("FRSH_ERR_INTERNAL_ERROR, signal wait in long jump handler\n");
+ printf("FOSA_ERR_INTERNAL_ERROR, signal wait in long jump handler\n");
exit(1);
}
// Restore thread's context
* implementation and dependant applications
*/
int fosa_long_jump_install_handler
-(frsh_signal_t *signal, frsh_thread_id_t *handler)
+(fosa_signal_t *signal, fosa_thread_id_t *handler)
{
- frsh_thread_attr_t attr;
+ fosa_thread_attr_t attr;
int err;
if (!handler_installed) {
//////////////////////////////////////////////////
// Create the thread attributes object
- err=frsh_thread_attr_init (&attr);
+ err=fosa_thread_attr_init (&attr);
if (err != 0) {
printf("Error while initializing the attributes\n");
return err;
}
// destroy the thread attributes object
- err=frsh_thread_attr_destroy (&attr);
+ err=fosa_thread_attr_destroy (&attr);
if (err != 0) {
printf("Error while destroying the attributes\n");
return err;
* notify it to the system console and then terminate the FRSH
* implementation and dependant applications
**/
-int fosa_mutex_init(frsh_mutex_t *mutex, int prioceiling)
+int fosa_mutex_init(fosa_mutex_t *mutex, int prioceiling)
{
pthread_mutexattr_t attr;
int ret_value;
* notify it to the system console and then terminate the FRSH
* implementation and dependant applications
**/
-int fosa_mutex_destroy(frsh_mutex_t *mutex)
+int fosa_mutex_destroy(fosa_mutex_t *mutex)
{
return pthread_mutex_destroy(mutex);
}
* implementation and dependant applications
**/
int fosa_mutex_set_prioceiling
- (frsh_mutex_t *mutex, int new_ceiling, int *old_ceiling)
+ (fosa_mutex_t *mutex, int new_ceiling, int *old_ceiling)
{
return pthread_mutex_setprioceiling(mutex,new_ceiling,old_ceiling);
}
* notify it to the system console and then terminate the FRSH
* implementation and dependant applications
**/
-int fosa_mutex_get_prioceiling(const frsh_mutex_t *mutex, int *ceiling)
+int fosa_mutex_get_prioceiling(const fosa_mutex_t *mutex, int *ceiling)
{
return pthread_mutex_getprioceiling(mutex,ceiling);
}
* notify it to the system console and then terminate the FRSH
* implementation and dependant applications
**/
-int fosa_mutex_lock(frsh_mutex_t *mutex)
+int fosa_mutex_lock(fosa_mutex_t *mutex)
{
return pthread_mutex_lock(mutex);
}
* implementation is allowed to notify it to the system console and
* then terminate the FRSH implementation and dependant applications
**/
-int fosa_mutex_trylock(frsh_mutex_t *mutex)
+int fosa_mutex_trylock(fosa_mutex_t *mutex)
{
return pthread_mutex_trylock(mutex);
}
* implementation is allowed to notify it to the system console and
* then terminate the FRSH implementation and dependant applications
**/
-int fosa_mutex_unlock(frsh_mutex_t *mutex)
+int fosa_mutex_unlock(fosa_mutex_t *mutex)
{
return pthread_mutex_unlock(mutex);
}
* notify it to the system console and then terminate the FRSH
* implementation and dependant applications
**/
-int fosa_cond_wait(fosa_cond_t *cond, frsh_mutex_t *mutex)
+int fosa_cond_wait(fosa_cond_t *cond, fosa_mutex_t *mutex)
{
return pthread_cond_wait(cond,mutex);
}
* implementation is allowed to notify it to the system console and
* then terminate the FRSH implementation and dependant applications
**/
-int fosa_cond_timedwait(fosa_cond_t *cond, frsh_mutex_t *mutex,
+int fosa_cond_timedwait(fosa_cond_t *cond, fosa_mutex_t *mutex,
const struct timespec *abstime)
{
return pthread_cond_timedwait(cond,mutex,abstime);
* 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)
{
return pthread_equal(t1,t2);
}
*
* Return the thread id of the calling thread
**/
-frsh_thread_id_t fosa_thread_self()
+fosa_thread_id_t fosa_thread_self()
{
return pthread_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)
+{
+ int ret_value;
+
+ ret_value=pthread_attr_init(attr);
+ if (ret_value==0) {
+ // set the default values
+
+ // detachstate = detached thread (no join operation allowed)
+ CHK(pthread_attr_setdetachstate(attr,PTHREAD_CREATE_DETACHED));
+
+ // inheritsched = explicit, so that we can explicitly set the attributes
+ CHK(pthread_attr_setinheritsched(attr,PTHREAD_EXPLICIT_SCHED));
+
+ // schedpolicy = fixed priorities
+ CHK(pthread_attr_setschedpolicy(attr,SCHED_FIFO));
+
+ // detachstate = detached thread (no join operation allowed)
+ CHK(pthread_attr_setdetachstate(attr,PTHREAD_CREATE_DETACHED));
+
+ }
+ return ret_value;
+}
+
+/**
+ * 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)
+{
+ return pthread_attr_destroy(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)
+{
+ return pthread_attr_setstacksize(attr,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)
+{
+ return pthread_attr_getstacksize(attr,stacksize);
+}
+
/*************************
* 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)
+ (fosa_thread_id_t *tid, const fosa_thread_attr_t *attr,
+ fosa_thread_code_t code, void * arg)
{
return pthread_create(tid,attr,code,arg);
}
int i,ret_value;
bool found=false;
+ ret_value = 0;
// initialize the keys data structure if needed
CHK(pthread_once(&keys_initialized, init_keys));
* 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)
{
return pthread_setspecific_for(key_list[key],tid,value);
}
* 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)
{
return pthread_getspecific_from(key_list[key],tid,value);
* 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)
{
struct sched_param param;
* Returns 0
**/
int fosa_thread_attr_get_prio
- (const frsh_thread_attr_t *attr, int *prio)
+ (const fosa_thread_attr_t *attr, int *prio)
{
struct sched_param param;
int ret_value;
* 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)
{
struct sched_param param;
int policy, ret_value;
*
* 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)
{
struct sched_param param;
int policy, ret_value;
* 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.
*******************************************************************/
* 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)
{
sigset_t signalset;
int i;
* implementation and dependant applications
**/
int fosa_signal_queue
- (frsh_signal_t signal, frsh_signal_info_t info,
- frsh_thread_id_t receiver)
+ (fosa_signal_t signal, fosa_signal_info_t info,
+ fosa_thread_id_t receiver)
{
// note: in MaRTE OS the signal is sent to any interested thread
pid_t pid=1; // dummy value; the pid is ignored in MaRTE OS
* 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)
{
int err,i;
sigset_t signalset;
err=sigwaitinfo(&signalset,&siginfo);
if (err!=-1) {
*signal_received=siginfo.si_signo;
- *info=*((frsh_signal_info_t *)(&siginfo.si_value));
+ *info=*((fosa_signal_info_t *)(&siginfo.si_value));
return 0;
} else {
return errno;
* 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)
{
// the implementation of sigtimedwait is not yet available in MaRTE OS
// however invalidate any other reasons why the executable file might be
// covered by the GNU Public License.
// -----------------------------------------------------------------------
-//frsh_fosa.c
+// fosa_time.c
//==============================================
// ******** ****** ******** **********
// **///// /** ** **////// /** /**
// FOSA(Frescor Operating System Adaptation layer)
//================================================
-#include "frsh_fosa.h"
+#include "fosa.h"
#include <pthread.h>
#include <stdio.h>
#include <time.h>
#include <misc/error_checks.h>
-/*************************
- * Thread attributes
- *************************/
/**
- * frsh_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 frsh_thread_attr_init(frsh_thread_attr_t *attr)
-{
- int ret_value;
-
- ret_value=pthread_attr_init(attr);
- if (ret_value==0) {
- // set the default values
-
- // detachstate = detached thread (no join operation allowed)
- CHK(pthread_attr_setdetachstate(attr,PTHREAD_CREATE_DETACHED));
-
- // inheritsched = explicit, so that we can explicitly set the attributes
- CHK(pthread_attr_setinheritsched(attr,PTHREAD_EXPLICIT_SCHED));
-
- // schedpolicy = fixed priorities
- CHK(pthread_attr_setschedpolicy(attr,SCHED_FIFO));
-
- // detachstate = detached thread (no join operation allowed)
- CHK(pthread_attr_setdetachstate(attr,PTHREAD_CREATE_DETACHED));
-
- }
- return ret_value;
-}
-
-/**
- * frsh_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 frsh_thread_attr_destroy(frsh_thread_attr_t *attr)
-{
- return pthread_attr_destroy(attr);
-}
-
-/**
- * frsh_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 frsh_thread_attr_set_stacksize
- (frsh_thread_attr_t *attr, size_t stacksize)
-{
- return pthread_attr_setstacksize(attr,stacksize);
-}
-
-/**
- * frsh_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 frsh_thread_attr_get_stacksize
- (const frsh_thread_attr_t *attr, size_t *stacksize)
-{
- return pthread_attr_getstacksize(attr,stacksize);
-}
-
-
-/**
- * frsh_eat()
+ * fosa_eat()
*
* Eat some time using system clock facilities
**/
#include <fosa_vt.h>
#endif
-void inline frsh_eat(const struct timespec *cpu_time)
+void inline fosa_eat(const struct timespec *cpu_time)
{
#ifdef VIRTUAL_TIME
vt_time_t vt_clock;
}
#endif
}
+
+
+
int main () {
int err;
fosa_clock_id_t clockid = FOSA_CLOCK_REALTIME;
- frsh_signal_t signal = FOSA_SIGNAL_MAX;
- frsh_signal_t received;
- frsh_signal_info_t info, info_received;
+ fosa_signal_t signal = FOSA_SIGNAL_MAX;
+ fosa_signal_t received;
+ fosa_signal_info_t info, info_received;
fosa_timer_id_t timerid;
bool abstime = false;
struct timespec timerval;
- frsh_signal_t set[1];
+ fosa_signal_t set[1];
info.sival_int=69;
{
int err = -1;
- frsh_thread_attr_t attr;
- frsh_thread_id_t tid;
+ fosa_thread_attr_t attr;
+ fosa_thread_id_t tid;
- frsh_signal_t signal_received;
- frsh_signal_info_t info_programmed, info_received;
+ fosa_signal_t signal_received;
+ fosa_signal_info_t info_programmed, info_received;
struct timespec work_interval = {3, 200000000}; // 3.2 seconds
fosa_clock_id_t clockid;
fosa_timer_id_t timerid;
struct timespec budget = {-1, -1};
- frsh_signal_t signal_set[1];
+ fosa_signal_t signal_set[1];
/* Create the thread attributes and define its priority */
/********************************************************/
- if (frsh_thread_attr_init (&attr) != 0) {
+ if (fosa_thread_attr_init (&attr) != 0) {
printf("Error while initializing the attributes\n");
exit(1);
}
/* and real time differ */
/*********************************************************/
printf("Main works for some time...\n");
- frsh_eat(&work_interval);
+ fosa_eat(&work_interval);
/* Now we do the wait in order to allow the thread to run */
/**********************************************************/
printf("Start periodic work at %d, %d\n",
before_work_time.tv_sec, before_work_time.tv_nsec);
- frsh_eat(&work_interval);
+ fosa_eat(&work_interval);
err = fosa_clock_get_time(FOSA_CLOCK_REALTIME, &after_work_time);
assert(err == 0);
{
int err = -1;
- frsh_thread_attr_t attr;
- frsh_thread_id_t tid;
+ fosa_thread_attr_t attr;
+ fosa_thread_id_t tid;
- frsh_signal_t signal_received;
- frsh_signal_info_t info_received;
+ fosa_signal_t signal_received;
+ fosa_signal_info_t info_received;
struct timespec work_interval = {3, 200000000}; // 3.2 seconds
- frsh_signal_t signal_set[1];
+ fosa_signal_t signal_set[1];
/* At the same time ensure that the main priority is */
/* higher */
/********************************************************/
- if (frsh_thread_attr_init (&attr) != 0) {
+ if (fosa_thread_attr_init (&attr) != 0) {
printf("Error while initializing the attributes\n");
exit(1);
}
/* and real time differ */
/*********************************************************/
printf("Main works for some time...\n");
- frsh_eat(&work_interval);
+ fosa_eat(&work_interval);
/* Now we do the wait in order to allow the thread to run */
/**********************************************************/
fosa_timer_id_t timerid;
struct timespec budget = {-1, -1};
- frsh_signal_info_t info_programmed;
+ fosa_signal_info_t info_programmed;
memset(&clockid, 0, sizeof(clockid) );
memset(&timerid, 0, sizeof(timerid) );
printf("Start periodic work at %d, %d\n",
before_work_time.tv_sec, before_work_time.tv_nsec);
- frsh_eat(&work_interval);
+ fosa_eat(&work_interval);
err = fosa_clock_get_time(FOSA_CLOCK_REALTIME, &after_work_time);
assert(err == 0);
// covered by the GNU Public License.
// -----------------------------------------------------------------------
-#include "fosa_app_def_sched.h"
-#include "fosa_threads_and_signals.h"
-#include "fosa_mutexes_and_condvars.h"
-#include "fosa_clocks_and_timers.h"
#include <stdio.h> // for printf
#include <string.h> // for strlen, strncpy
#include <unistd.h> // for sleep
#include <time.h> // for nanosleep
-#include <misc/load.h> // for adjust, eat
+
// TODO: use #include <assert.h> when it works for all architectures
#include <stdlib.h> // for exit in assert
+#include "fosa.h"
+
static void inline assert(expression)
{
if (!expression) {
static void *thread_code(void *arg);
-static void frsh_callback_init
+static void fosa_callback_init
(void *sched_data, void *arg);
-static void frsh_callback_new_thread
+static void fosa_callback_new_thread
(void *sched_data,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
fosa_ads_actions_t *actions,
struct timespec *current_time);
-static void frsh_callback_thread_terminate
+static void fosa_callback_thread_terminate
(void *sched_data,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
fosa_ads_actions_t *actions,
struct timespec *current_time);
-static void frsh_callback_thread_ready
+static void fosa_callback_thread_ready
(void *sched_data,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
fosa_ads_actions_t *actions,
struct timespec *current_time);
-static void frsh_callback_thread_block
+static void fosa_callback_thread_block
(void *sched_data,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
fosa_ads_actions_t *actions,
struct timespec *current_time);
-static void frsh_callback_change_sched_param_thread
+static void fosa_callback_change_sched_param_thread
(void *sched_data,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
fosa_ads_actions_t *actions,
struct timespec *current_time);
-static void frsh_callback_explicit_call_with_data
+static void fosa_callback_explicit_call_with_data
(void *sched_data,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
const void * msg,
size_t msg_size,
void *reply,
fosa_ads_actions_t *actions,
struct timespec *current_time);
-static void frsh_callback_notification_for_thread
+static void fosa_callback_notification_for_thread
(void *sched_data,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
fosa_clock_id_t clock,
fosa_ads_actions_t *actions,
struct timespec *current_time);
-static void frsh_callback_timeout
+static void fosa_callback_timeout
(void *sched_data,
fosa_ads_actions_t *actions,
struct timespec *current_time);
-static void frsh_callback_signal
+static void fosa_callback_signal
(void *sched_data,
- frsh_signal_t signal,
- frsh_signal_info_t siginfo,
+ fosa_signal_t signal,
+ fosa_signal_info_t siginfo,
fosa_ads_actions_t *actions,
struct timespec *current_time);
-static void frsh_callback_appsched_error
+static void fosa_callback_appsched_error
(void *sched_data,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
fosa_ads_error_cause_t cause,
fosa_ads_actions_t *actions);
///////////////////////////////////////////////////////
static fosa_ads_scheduler_ops_t scheduler_ops = {
- .init = frsh_callback_init,
- .new_thread = frsh_callback_new_thread,
- .thread_terminate = frsh_callback_thread_terminate,
- .thread_ready = frsh_callback_thread_ready,
- .thread_block = frsh_callback_thread_block,
- .change_sched_param_thread = frsh_callback_change_sched_param_thread,
- .explicit_call_with_data = frsh_callback_explicit_call_with_data,
- .notification_for_thread = frsh_callback_notification_for_thread,
- .timeout = frsh_callback_timeout,
- .signal = frsh_callback_signal,
- .appsched_error = frsh_callback_appsched_error,
+ .init = fosa_callback_init,
+ .new_thread = fosa_callback_new_thread,
+ .thread_terminate = fosa_callback_thread_terminate,
+ .thread_ready = fosa_callback_thread_ready,
+ .thread_block = fosa_callback_thread_block,
+ .change_sched_param_thread = fosa_callback_change_sched_param_thread,
+ .explicit_call_with_data = fosa_callback_explicit_call_with_data,
+ .notification_for_thread = fosa_callback_notification_for_thread,
+ .timeout = fosa_callback_timeout,
+ .signal = fosa_callback_signal,
+ .appsched_error = fosa_callback_appsched_error,
};
-static frsh_mutex_t lock;
+static fosa_mutex_t lock;
const unsigned int MX_INIT_ARGS_STRING = 30;
const unsigned int MX_PRIO = 20;
typedef struct {
fosa_ads_urgency_t array_prio[MX_THREADS];
int array_status[MX_THREADS];
-} frsh_sched_data_t;
+} fosa_sched_data_t;
typedef struct {
fosa_ads_urgency_t prio;
} command_t;
typedef struct {
- frsh_thread_id_t thread_id;
+ fosa_thread_id_t thread_id;
command_t command;
} signal_action_t;
int err;
char init_args_string[MX_INIT_ARGS_STRING + 1];
- frsh_thread_id_t tid1, tid2, tid3;
- frsh_thread_attr_t th_attr;
+ fosa_thread_id_t tid1, tid2, tid3;
+ fosa_thread_attr_t th_attr;
bool is_appsched;
appsched_params_t params;
- frsh_signal_info_t timer_info;
+ fosa_signal_info_t timer_info;
fosa_timer_id_t timerid;
struct timespec timerval;
signal_action_t signal_action;
- adjust(); // for function eat
err = fosa_thread_set_prio (fosa_thread_self(), MX_PRIO + 1);
printf("set main to highest priority, err=%d\n", err);
err = fosa_ads_scheduler_create
(&scheduler_ops,
- sizeof(frsh_sched_data_t),
+ sizeof(fosa_sched_data_t),
init_args_string, // INIT IS CALLED INMEDIATELY??!!!
strlen(init_args_string) + 1);
printf("scheduler created, err=%d\n", err);
printf("--------------------------------------------------\n");
printf("2b) Create two application scheduled threads\n");
- err = frsh_thread_attr_init(&th_attr);
+ err = fosa_thread_attr_init(&th_attr);
printf("thread attributes object initialized, err=%d\n", err);
assert(err == 0);
- err = frsh_thread_attr_set_stacksize(&th_attr,40000);
+ err = fosa_thread_attr_set_stacksize(&th_attr,40000);
printf("thread attr set stack size to 40000, err=%d\n", err);
assert(err == 0);
printf("created thread 3 (rejected=%d), err=%d\n",
(err == FOSA_EREJECT), err);
- err = frsh_thread_attr_destroy(&th_attr);
+ err = fosa_thread_attr_destroy(&th_attr);
printf("thread attributes object destroyed, err=%d\n",err);
assert(err == 0);
char whoami[] = "who am i?";
int reply;
size_t reply_size;
+ struct timespec one_second = {1, 0};
printf("THREAD %d - starts\n", (int)arg);
for (i=1;i<50;i++) {
err=fosa_mutex_lock(&lock);
assert(err == 0);
- eat (1.0);
+ fosa_eat (&one_second);
printf("THREAD %d - unlocking mutex\n", (int)arg);
err=fosa_mutex_unlock(&lock);
///////////////////////////////////////////////////////
// 4) Implementation of Application Defined Callbacks
///////////////////////////////////////////////////////
-static void frsh_callback_init
+static void fosa_callback_init
(void *sched_data, void *arg)
{
- frsh_sched_data_t *frsh = (frsh_sched_data_t *)sched_data;
+ fosa_sched_data_t *frsh = (fosa_sched_data_t *)sched_data;
int i, err;
- frsh_signal_t sched_signal = FOSA_SIGNAL_MAX; // HOW TO PUT SIGNALS IF IS OPAQUE??
+ fosa_signal_t sched_signal = FOSA_SIGNAL_MAX; // HOW TO PUT SIGNALS IF IS OPAQUE??
printf ("BEGIN CALLBACK: %s \n", __func__);
printf ("init args string received: %s \n", (char *)arg);
printf ("END CALLBACK: %s \n", __func__);
}
-static void frsh_callback_new_thread
+static void fosa_callback_new_thread
(void *sched_data,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
fosa_ads_actions_t *actions,
struct timespec *current_time)
{
int err;
unsigned int i, index;
- frsh_sched_data_t *frsh = (frsh_sched_data_t *)sched_data;
+ fosa_sched_data_t *frsh = (fosa_sched_data_t *)sched_data;
appsched_params_t params;
size_t size;
printf ("END CALLBACK: %s \n", __func__);
}
-static void frsh_callback_thread_terminate
+static void fosa_callback_thread_terminate
(void *sched_data,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
fosa_ads_actions_t *actions,
struct timespec *current_time)
{
printf ("END CALLBACK: %s \n", __func__);
}
-static void frsh_callback_thread_ready
+static void fosa_callback_thread_ready
(void *sched_data,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
fosa_ads_actions_t *actions,
struct timespec *current_time)
{
printf ("END CALLBACK: %s \n", __func__);
}
-static void frsh_callback_thread_block
+static void fosa_callback_thread_block
(void *sched_data,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
fosa_ads_actions_t *actions,
struct timespec *current_time)
{
printf ("END CALLBACK: %s \n", __func__);
}
-static void frsh_callback_change_sched_param_thread
+static void fosa_callback_change_sched_param_thread
(void *sched_data,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
fosa_ads_actions_t *actions,
struct timespec *current_time)
{
printf ("END CALLBACK: %s \n", __func__);
}
-static void frsh_callback_explicit_call_with_data
+static void fosa_callback_explicit_call_with_data
(void *sched_data,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
const void * msg,
size_t msg_size,
void *reply,
printf ("END CALLBACK: %s \n", __func__);
}
-static void frsh_callback_notification_for_thread
+static void fosa_callback_notification_for_thread
(void *sched_data,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
fosa_clock_id_t clock,
fosa_ads_actions_t *actions,
struct timespec *current_time)
printf ("END CALLBACK: %s \n", __func__);
}
-static void frsh_callback_timeout // WHY NOT WATCHDOG????
+static void fosa_callback_timeout // WHY NOT WATCHDOG????
(void *sched_data,
fosa_ads_actions_t *actions,
struct timespec *current_time) // WHY IS IN OUT and not IN???
printf ("END CALLBACK: %s \n", __func__);
}
-static void frsh_callback_signal
+static void fosa_callback_signal
(void *sched_data,
- frsh_signal_t signal,
- frsh_signal_info_t siginfo, // HOW DO I KNOW THE ORIGIN (see signal_info type)
+ fosa_signal_t signal,
+ fosa_signal_info_t siginfo, // HOW DO I KNOW THE ORIGIN (see signal_info type)
fosa_ads_actions_t *actions,
struct timespec *current_time)
{
int err;
signal_action_t *signal_action = (signal_action_t *)siginfo.sival_ptr;
- frsh_sched_data_t *frsh = (frsh_sched_data_t *)sched_data;
+ fosa_sched_data_t *frsh = (fosa_sched_data_t *)sched_data;
printf ("BEGIN CALLBACK: %s \n", __func__);
case CAUSE_ERROR:
// cause an error by overwriting actions with 666 ;D
*(int *)actions = 666;
+ err = 666;
printf("causing an error, err=%d\n", err);
break;
}
printf ("END CALLBACK: %s \n", __func__);
}
-static void frsh_callback_appsched_error
+static void fosa_callback_appsched_error
(void *sched_data,
- frsh_thread_id_t thread,
+ fosa_thread_id_t thread,
fosa_ads_error_cause_t cause,
fosa_ads_actions_t *actions)
{
--- /dev/null
+include ../../../config.mk
+include ../../../rules.mk
+
+
int stsize, prio;
- frsh_thread_id_t tid1=fosa_thread_self();
- frsh_thread_id_t tid2=fosa_thread_self();
+ fosa_thread_id_t tid1=fosa_thread_self();
+ fosa_thread_id_t tid2=fosa_thread_self();
printf("equal thread comparison=%d\n",fosa_thread_equal(tid1,tid2));
- frsh_thread_attr_t th_attr;
+ fosa_thread_attr_t th_attr;
- err=frsh_thread_attr_init(&th_attr);
+ err=fosa_thread_attr_init(&th_attr);
printf("thread attributes object initialized, err=%d\n",err);
- err=frsh_thread_attr_set_stacksize(&th_attr,40000);
+ err=fosa_thread_attr_set_stacksize(&th_attr,40000);
printf("thread attr set stack size to 40000, err=%d\n",err);
- err=frsh_thread_attr_get_stacksize(&th_attr,&stsize);
+ err=fosa_thread_attr_get_stacksize(&th_attr,&stsize);
printf("thread attr get stack size=%d, err=%d\n",stsize,err);
err=fosa_thread_attr_set_prio(&th_attr,27);
sleep(2);
- err=frsh_thread_attr_destroy(&th_attr);
+ err=fosa_thread_attr_destroy(&th_attr);
printf("thread attributes object destroyed, err=%d\n",err);
//////////////////////////////////
printf("--------------------------------------------------\n");
printf("test signals\n");
- frsh_signal_t received;
- frsh_signal_info_t sigvalue, value_received;
+ fosa_signal_t received;
+ fosa_signal_info_t sigvalue, value_received;
struct timespec timeout;
- frsh_signal_t sig=FOSA_SIGNAL_MIN+1;
- frsh_signal_t timer_sig=FOSA_SIGNAL_MIN+3;
- frsh_signal_t siglist[2];
+ fosa_signal_t sig=FOSA_SIGNAL_MIN+1;
+ fosa_signal_t timer_sig=FOSA_SIGNAL_MIN+3;
+ fosa_signal_t siglist[2];
siglist[0]=sig;
siglist[1]=timer_sig;
printf("--------------------------------------------------\n");
printf("test timers and signals\n");
- frsh_signal_info_t timer_info;
+ fosa_signal_info_t timer_info;
fosa_timer_id_t timerid;
struct timespec timerval, remaining_time;
int value=333;
int key;
- frsh_thread_id_t tid=fosa_thread_self();
+ fosa_thread_id_t tid=fosa_thread_self();
err=fosa_key_create(&key);
printf("key created=%d. err=%d\n",key,err);
printf("--------------------------------------------------\n");
printf("test mutexes\n");
- frsh_mutex_t lock;
+ fosa_mutex_t lock;
int old;
err=fosa_mutex_init(&lock,24);
printf("--------------------------------------------------\n");
printf("test application-defined scheduling\n");
- frsh_thread_attr_t th1_attr;
+ fosa_thread_attr_t th1_attr;
bool is_appsched;
- err=frsh_thread_attr_init(&th1_attr);
+ err=fosa_thread_attr_init(&th1_attr);
printf("thread attributes object initialized, err=%d\n",err);
err=fosa_thread_attr_set_appscheduled(&th1_attr,true);
include ../../../config.mk
include ../../../rules.mk
-LDFLAGS += frsh_error.o $(FOSA_PATH)/marte_non_local_jump/non_local_jump.o
+LDFLAGS += $(FOSA_PATH)/marte_non_local_jump/non_local_jump.o
-CFLAGS += -I$(FRSH_PATH)/src_ads # Quick hack for frsh_error
+testbench_long_jump.exe: testbench_long_jump.c libfosa
-frsh_error.o: frsh_error.c
+test_fosa_long_jump.exe: test_fosa_long_jump.c libfosa
-testbench_long_jump.exe: testbench_long_jump.c frsh_error.o libfosa
-
-test_fosa_long_jump.exe: test_fosa_long_jump.c frsh_error.o libfosa
-
-fosa_long_jump_calibrate.exe: fosa_long_jump_calibrate.c frsh_error.o libfosa
+fosa_long_jump_calibrate.exe: fosa_long_jump_calibrate.c libfosa
+++ /dev/null
-//----------------------------------------------------------------------
-// Copyright (C) 2006 - 2007 by the FRESCOR consortium:
-//
-// 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
-//
-// 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.
-//
-//
-// 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
-//
-// This file is part of FRSH (FRescor ScHeduler)
-//
-// FRSH 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. 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 along with FRSH; see file
-// COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
-// Cambridge, MA 02139, USA.
-//
-// As a special exception, including FRSH header files in a file,
-// instantiating FRSH generics or templates, or linking other files
-// with FRSH 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.
-// -----------------------------------------------------------------------
-//==============================================
-// ******** ******* ******** ** **
-// **///// /**////** **////// /** /**
-// ** /** /** /** /** /**
-// ******* /******* /********* /**********
-// **//// /**///** ////////** /**//////**
-// ** /** //** /** /** /**
-// ** /** //** ******** /** /**
-// // // // //////// // //
-//
-// FRSH(FRescor ScHeduler), pronounced "fresh"
-//==============================================
-
-#include <stdio.h>
-#include <string.h>
-
-#include "frsh.h"
-#include "frsh_internal.h"
-
-
-////////////////////////////////////////////////////////////////////////
-// ERROR REPORTING
-////////////////////////////////////////////////////////////////////////
-
-/* Use to debug an error condition */
-/***********************************/
-int global_error_condition = 0;
-
-
-
-/* These variables get initialised in frsh_init() */
-/**************************************************/
-struct timespec frsh_trace_init_timespec = {-1, -1};
-long frsh_trace_init_timemsec = -1;
-
-
-//error codes to message section
-static const int frsh_strerror_table_size = FRSH_ERR_LAST_VALUE-FRSH_ERR_BASE_VALUE;
-static char * frsh_strerror_table[] =
-{
- "TOO_MANY_TASKS ",
- "BAD_ARGUMENT ",
- "INVALID_SYNCH_OBJ_HANDLE ",
- "NO_RENEGOTIATION_REQUESTED ",
- "CONTRACT_REJECTED ",
- "NOT_SCHEDULED_CALLING_THREAD ",
- "NOT_BOUND_THREAD ",
- "UNKNOWN_SCHEDULED_THREAD ",
- "NOT_CONTRACTED_SERVER ",
- "NOT_SCHEDULED_THREAD ",
- "TOO_MANY_SERVICE_JOBS ",
- "TOO_MANY_SYNCH_OBJS ",
- "TOO_MANY_SERVERS_IN_SYNCH_OBJ ",
- "TOO_MANY_EVENTS_IN_SYNCH_OBJ ",
- "INTERNAL_ERROR ",
- "TOO_MANY_SERVERS ",
- "INVALID_SCHEDULER_REPLY ",
- "TOO_MANY_PENDING_REPLENISHMENTS",
- "SYSTEM_ALREADY_INITIALIZED ",
- "SHARED_OBJ_ALREADY_INITIALIZED ",
- "SHARED_OBJ_NOT_INITIALIZED ",
- "SCHED_POLICY_NOT_COMPATIBLE ",
- "SERVER_WORKLOAD_NOT_COMPATIBLE ",
- "ALREADY_BOUND ",
- "WRONG_NETWORK ",
- "TOO_LARGE ",
- "BUFFER_FULL ",
- "NO_SPACE ",
- "NO_MESSAGES ",
- "MODULE_NOT_SUPPORTED ",
- "SYSTEM_NOT_INITIALIZED ",
- "TOO_MANY_SHARED_OBJS ",
- "CONTRACT_LABEL_ALREADY_EXISTS ",
- "BUDGET_EXPIRED ",
- "SHARED_OBJECT_NOT_PROTECTED ",
- "NOT_IMPLEMENTED ",
- "CONTRACT_TYPE_NOT_COMPATIBLE ",
- "CAPACITY_NOT_DECREASING ",
- "CONTRACT_LABEL_UNKNOWN "
-};
-
-
-
-/**
- * frsh_strerror()
- *
- * This function converts an error code to an error message that is
- * stored in the buffer starting at the location pointed to by
- * message. The size of this buffer is specified by the size
- * argument. If the error message is longer than size-1, it is
- * truncated to that length. Regardless of whether the message is
- * truncated or not, a final zero character that marks the end of the
- * string is stored in the buffer. The function fails if the error
- * code passed does not correspond to any of the frsh error codes.
- * [@return:
- * FRSH_ERR_BAD_ARGUMENT : error is not a valid value
- * ]
- **/
-int frsh_strerror (int error, char *message, size_t size)
-{
- char *s;
-//printf("debug: error=%x, LAST=%x, BASE=%x\n", error, FRSH_ERR_LAST_VALUE, FRSH_ERR_BASE_VALUE);
- if ((error > FRSH_ERR_LAST_VALUE) ||
- (error <= FRSH_ERR_BASE_VALUE))
- return FRSH_ERR_BAD_ARGUMENT;
-
- s = frsh_strerror_table[error - FRSH_ERR_BASE_VALUE -1];
-
- if ( message != NULL && size > 0) {
- strncpy(message, s, size);
- message[size-1] = '\0';
- }
-
- return 0;
-}
-
-/* ------------------------------------------------------------------------------------ */
-void my_frsh_strerror(int error, char *sss)
-{
- char s[32];
- frsh_strerror(error, s, 32);
- printf("(%x ", error);
- printf(s);
- printf(") ");
- printf(sss);
-}
//#include <signal.h>
//#include <frsh.h>
-#include <frsh_fosa.h>
-#include <fosa_threads_and_signals.h>
-#include <fosa_clocks_and_timers.h>
-
-
+#include "fosa.h"
#include "timespec_operations.h"
#include "marte_non_local_jmp.h"
#define RT_ERROR_TIMER -3
typedef struct {
- frsh_thread_id_t tid;
+ fosa_thread_id_t tid;
marte_nonlocaljmp_context_t *context_ptr;
int dummy;
} budget_timer_info_t;
int main()
{
- frsh_signal_t set[1];
- frsh_thread_attr_t attr;
+ fosa_signal_t set[1];
+ fosa_thread_attr_t attr;
- frsh_thread_id_t tid1, tid2;
+ fosa_thread_id_t tid1, tid2;
int terror = 0;
// set signal mask
}
// Create the thread attributes object
- if (frsh_thread_attr_init (&attr) != 0) {
+ if (fosa_thread_attr_init (&attr) != 0) {
printf("Error while initializing the attributes\n");
exit(1);
}
printf("start regular code %d\n",i);
// regular code
// eat one second of budget
- frsh_eat(&exec_time);
+ fosa_eat(&exec_time);
// every five cycles eat an additional one second of budget */
if (i%5==0) {
printf("aqui\n");
- frsh_eat(&exec_time);
+ fosa_eat(&exec_time);
printf("aqui tambien\n");
}
}
fosa_timer_id_t timerid;
fosa_clock_id_t clockid;
budget_timer_info_t timerinfo;
- frsh_signal_info_t siginfo;
+ fosa_signal_info_t siginfo;
int i=0;
timerinfo.tid=pthread_self();
void * signal_handler_thread (void * arg) {
- frsh_signal_t set[1];
- frsh_signal_t sig;
- frsh_signal_info_t siginfo;
+ fosa_signal_t set[1];
+ fosa_signal_t sig;
+ fosa_signal_info_t siginfo;
budget_timer_info_t *info;
#include <unistd.h>
#include <time.h> // For clock_nanosleep
-#include "frsh_error.h"
#include "fosa.h"
-#include "frsh_fosa.h"
#include "timespec_operations.h"
+#include <misc/error_checks.h>
+
+
+
/*************************/
/* D E F I N I T I O N S */
/*************************/
int main()
{
- int terror = -1;
- frsh_thread_attr_t periodic_attr;
- frsh_signal_t signal_set[1];
- frsh_thread_id_t periodic_tid;
+ fosa_thread_attr_t periodic_attr;
+ fosa_signal_t signal_set[1];
+ fosa_thread_id_t periodic_tid;
memset(&context, 0, sizeof(context) );
/* We set the signal mask */
signal_set[0] = FOSA_LONG_JUMP_SIGNAL;
- PRW( fosa_set_accepted_signals(signal_set, 1) );
+
+ CHK( fosa_set_accepted_signals(signal_set, 1) );
/* We create a new thread with a given priority */
- PRW( frsh_thread_attr_init(&periodic_attr) );
- PRW( fosa_thread_attr_set_prio(&periodic_attr, PERIODIC_THREAD_PRIORITY) );
- PRW( fosa_thread_create(&periodic_tid, &periodic_attr, periodic_code, NULL) );
+ CHK( fosa_thread_attr_init(&periodic_attr) );
+ CHK( fosa_thread_attr_set_prio(&periodic_attr, PERIODIC_THREAD_PRIORITY) );
+ CHK( fosa_thread_create(&periodic_tid, &periodic_attr, periodic_code, NULL) );
printf("Main goes to sleep...\n");
static void *periodic_code(void *thread_arg)
{
- int terror = -1;
-
struct timespec period = {2, 500000000}; // 2.5 secs
- frsh_thread_id_t jump_handler_thread;
+ fosa_thread_id_t jump_handler_thread;
- frsh_signal_t jump_signal;
- frsh_signal_info_t jump_signal_info;
+ fosa_signal_t jump_signal;
+ fosa_signal_info_t jump_signal_info;
fosa_clock_id_t clock_id;
fosa_timer_id_t jump_timer;
/* - This creates the thread that will wait for */
/* FOSA_JUMP_SIGNAL */
/************************************************/
- PXW( fosa_long_jump_install_handler(&jump_signal, &jump_handler_thread) );
+ CHK( fosa_long_jump_install_handler(&jump_signal, &jump_handler_thread) );
/* We create a budget timer using the thread's CPU clock */
/* */
/* */
/* This signal is delivered to the handler thread. */
/*********************************************************/
- PXW( fosa_thread_get_cputime_clock( fosa_thread_self(), &clock_id) );
+ CHK( fosa_thread_get_cputime_clock( fosa_thread_self(), &clock_id) );
jump_signal_info.sival_ptr = &context;
- PXW( fosa_timer_create_with_receiver(clock_id, jump_signal, jump_signal_info,
+ CHK( fosa_timer_create_with_receiver(clock_id, jump_signal, jump_signal_info,
&jump_timer, jump_handler_thread) );
jumped = 0;
/* For statistical purposes we read the activation time */
- PXW( fosa_clock_get_time(FOSA_CLOCK_REALTIME, &activation_time) );
+ CHK( fosa_clock_get_time(FOSA_CLOCK_REALTIME, &activation_time) );
/************************************/
/* We arm the jump_timer */
- PXW( fosa_timer_arm(jump_timer, false, &budget) );
+ CHK( fosa_timer_arm(jump_timer, false, &budget) );
/* This is the point where the jump returns */
- PXW( fosa_long_jump_save_context(&context) );
+ CHK( fosa_long_jump_save_context(&context) );
/* Query if we come from a jump */
- PXW( fosa_long_jump_was_performed(&context, &jumped) );
+ CHK( fosa_long_jump_was_performed(&context, &jumped) );
if (!jumped)
{
/* HERE COMES THE WORK THAT CAN BE INTERRUPTED */
work_under_a_interruptible_budget();
- PRW( fosa_timer_disarm(&jump_timer, NULL) );
+ CHK( fosa_timer_disarm(jump_timer, NULL) );
printf("NOT JUMPPED\n");
}
else
/* Now we measure the time duration of the block */
/*************************************************/
- PXW( fosa_clock_get_time(FOSA_CLOCK_REALTIME, &old_activation_time) );
+ CHK( fosa_clock_get_time(FOSA_CLOCK_REALTIME, &old_activation_time) );
decr_timespec(&old_activation_time, &activation_time);
printf("Execution time: %6.3f\n", t2d(old_activation_time) );
i++;
printf("Start regular work\n");
- frsh_eat(&exec_time);
+ fosa_eat(&exec_time);
/* Once in every 5 executions we work over the budget */
if (i % 5 == 0)
{
- frsh_eat(&exec_time);
- frsh_eat(&exec_time);
- frsh_eat(&exec_time);
- frsh_eat(&exec_time);
- frsh_eat(&exec_time);
- frsh_eat(&exec_time);
+ fosa_eat(&exec_time);
+ fosa_eat(&exec_time);
+ fosa_eat(&exec_time);
+ fosa_eat(&exec_time);
+ fosa_eat(&exec_time);
+ fosa_eat(&exec_time);
}
printf("End regular work\n");
#include <unistd.h>
#include <time.h> // For clock_nanosleep
-#include "frsh_error.h"
#include "fosa.h"
-#include "frsh_fosa.h"
#include "timespec_operations.h"
+#include <misc/error_checks.h>
/*************************/
int main()
{
- int terror = -1;
- frsh_thread_attr_t periodic_attr;
- frsh_signal_t signal_set[1];
- frsh_thread_id_t periodic_tid;
+ fosa_thread_attr_t periodic_attr;
+ fosa_signal_t signal_set[1];
+ fosa_thread_id_t periodic_tid;
results_t results;
memset(&context, 0, sizeof(context) );
/* We set the signal mask */
signal_set[0] = FOSA_LONG_JUMP_SIGNAL;
- PRW( fosa_set_accepted_signals(signal_set, 1) );
+ CHK( fosa_set_accepted_signals(signal_set, 1) );
/* We create a new thread with a given priority */
- PRW( fosa_thread_set_prio(fosa_thread_self(), MAIN_THREAD_PRIORITY) );
+ CHK( fosa_thread_set_prio(fosa_thread_self(), MAIN_THREAD_PRIORITY) );
- PRW( frsh_thread_attr_init(&periodic_attr) );
- PRW( fosa_thread_attr_set_prio(&periodic_attr, PERIODIC_THREAD_PRIORITY) );
- PRW( fosa_thread_create(&periodic_tid, &periodic_attr, periodic_code, &results) );
+ CHK( fosa_thread_attr_init(&periodic_attr) );
+ CHK( fosa_thread_attr_set_prio(&periodic_attr, PERIODIC_THREAD_PRIORITY) );
+ CHK( fosa_thread_create(&periodic_tid, &periodic_attr, periodic_code, &results) );
printf("Main waits for the periodic code to finish...\n");
pthread_join(periodic_tid, NULL);
static void *periodic_code(void *thread_arg)
{
- int terror = -1;
+ fosa_thread_id_t jump_handler_thread;
- struct timespec period = {2, 500000000}; // 2.5 secs
- frsh_thread_id_t jump_handler_thread;
-
- frsh_signal_t jump_signal;
- frsh_signal_info_t jump_signal_info;
+ fosa_signal_t jump_signal;
+ fosa_signal_info_t jump_signal_info;
fosa_clock_id_t clock_id;
fosa_timer_id_t jump_timer;
/* - This creates the thread that will wait for */
/* FOSA_JUMP_SIGNAL */
/************************************************/
- PXW( fosa_long_jump_install_handler(&jump_signal, &jump_handler_thread) );
+ CHK( fosa_long_jump_install_handler(&jump_signal, &jump_handler_thread) );
/* We create a budget timer using the thread's CPU clock */
/* */
/* */
/* This signal is delivered to the handler thread. */
/*********************************************************/
- PXW( fosa_thread_get_cputime_clock( fosa_thread_self(), &clock_id) );
+ CHK( fosa_thread_get_cputime_clock( fosa_thread_self(), &clock_id) );
jump_signal_info.sival_ptr = &context;
- PXW( fosa_timer_create_with_receiver(clock_id, jump_signal, jump_signal_info,
+ CHK( fosa_timer_create_with_receiver(clock_id, jump_signal, jump_signal_info,
&jump_timer, jump_handler_thread) );
results->number_of_jumps = 0;