copy_of_signalset=sch_thread_data->sch_signal_set;
// unlock the scheduler mutex before waiting
- CHK(pthread_mutex_lock(&(sch_thread_data->sch_mutex)));
+ CHK(pthread_mutex_unlock(&(sch_thread_data->sch_mutex)));
// execute pending scheduling actions and wait for next event
err=posix_appsched_execute_actions
if (!sched_actions.suspended && !sched_actions.activated) {
CHK(posix_appsched_actions_addactivate
(&(sched_actions.actions),event.thread));
- }
+ }
}
}
break;
clk,
&sched_actions,
¤t_time);
- // t.b.d. check if state of thread is suspended by default
+ // t.b.d. check if state of thread is suspended by default
break;
case POSIX_APPSCHED_TIMEOUT:
sch_thread_data->scheduler_ops.timeout
int err;
struct sched_param param;
-#ifdef FULL_ERROR_CHECKING
+#ifdef FULL_ERROR_CHECKING
// check for NULL scheduler operations
if (scheduler_ops==NULL) {
return EINVAL;
(frsh_thread_attr_t *attr,
bool appscheduled)
{
- return pthread_attr_setschedpolicy(attr,SCHED_APP);
+ int error_code;
+
+ // set the application-defined scheduler thread
+ error_code=pthread_attr_setappscheduler(attr,scheduler_thread_id);
+ if (error_code!=0) return error_code;
+
+ if (appscheduled) {
+ return pthread_attr_setschedpolicy(attr,SCHED_APP);
+ } else {
+ return pthread_attr_setschedpolicy(attr,SCHED_FIFO);
+ }
}
/**
fosa_ads_actions_t *sched_actions,
frsh_thread_id_t thread)
{
-#ifdef FULL_ERROR_CHECKING
+#ifdef FULL_ERROR_CHECKING
// check errors
if (!pthread_equal(pthread_self(),scheduler_thread_id)) {
return FOSA_EPOLICY;
frsh_thread_id_t thread,
fosa_ads_urgency_t urgency)
{
-#ifdef FULL_ERROR_CHECKING
+#ifdef FULL_ERROR_CHECKING
// check errors
struct sched_param param;
int policy;
fosa_ads_actions_t *sched_actions,
frsh_thread_id_t thread)
{
-#ifdef FULL_ERROR_CHECKING
+#ifdef FULL_ERROR_CHECKING
// check errors
struct sched_param param;
int policy;
fosa_clock_id_t clock_id,
const struct timespec *at_time)
{
-#ifdef FULL_ERROR_CHECKING
+#ifdef FULL_ERROR_CHECKING
// check errors
struct sched_param param;
int policy;
{
int i;
-#ifdef FULL_ERROR_CHECKING
+#ifdef FULL_ERROR_CHECKING
// check errors
if (!pthread_equal(pthread_self(),scheduler_thread_id)) {
return FOSA_EPOLICY;
struct explicit_call_info * call_info;
int error_code;
-#ifdef FULL_ERROR_CHECKING
+#ifdef FULL_ERROR_CHECKING
// check errors
if (pthread_equal(pthread_self(),scheduler_thread_id)) {
return FOSA_EPOLICY;
#include <unistd.h> // for sleep
#include <time.h> // for nanosleep
#include <misc/assert.h> // for assert
-#include <misc/console_management.h> // for set_text_color
#include <misc/load.h> // for adjust, eat
+// linux_lib doesn't have panic
+// ----------------------------
+// #include <stdlib.h>
+// void panic(const char *fmt, ...)
+// {
+// printf("%s \n", fmt);
+// exit(1);
+// }
+
///////////////////////////////////////////////////////
// 0) Function prototypes
///////////////////////////////////////////////////////
static void *thread_code(void *arg);
-
static void frsh_callback_init
(void *sched_data, void *arg);
frsh_thread_attr_t th_attr;
bool is_appsched;
appsched_params_t params;
- frsh_signal_t sched_signal = FOSA_SIGNAL_MAX; // HOW TO PUT SIGNALS IF IS OPAQUE??
frsh_signal_info_t timer_info;
fosa_timer_id_t timerid;
struct timespec timerval;
strncpy(init_args_string, "Hello Scheduler!!", MX_INIT_ARGS_STRING);
init_args_string[MX_INIT_ARGS_STRING] = '\0';
- err = fosa_ads_set_handled_signal_set(&sched_signal, 1);
- printf("scheduler created, err=%d\n", err);
- assert(err == 0);
-
err = fosa_ads_scheduler_create
(&scheduler_ops,
sizeof(frsh_sched_data_t),
printf("thread attr set stack size to 40000, err=%d\n", err);
assert(err == 0);
- err = fosa_thread_attr_set_prio(&th_attr,10);
+ err = fosa_thread_attr_set_prio(&th_attr, MX_PRIO - 1);
printf("thread attr set prio to 10, err=%d\n",err);
assert(err == 0);
printf("thread attr get appscheduled=%d, err=%d\n",is_appsched, err);
assert(err == 0);
- params.prio = MX_PRIO - 1;
+ params.prio = 10;
err = fosa_thread_attr_set_appsched_params
- (&th_attr, ¶ms, sizeof(params));
- printf("thread attr set params prio=10, err=%d\n", err);
+ (&th_attr, (void *)¶ms, sizeof(params));
+ printf("thread attr set params prio=%d, err=%d\n", params.prio, err);
assert(err == 0);
// create thread 1
err = fosa_thread_create (&tid1, &th_attr, thread_code, (void *)1);
- printf("creating thread 1 with prio=%d, err=%d\n",params.prio, err);
+ printf("creating thread 1 with prio=%d, err=%d\n", params.prio, err);
assert(err == 0);
- params.prio = MX_PRIO - 2;
+ params.prio = 15;
err = fosa_thread_attr_set_appsched_params
(&th_attr, (void *)¶ms, sizeof(params));
- printf("thread attr set params prio=10, err=%d\n", err);
+ printf("thread attr set params prio=%d, err=%d\n", params.prio, err);
assert(err == 0);
// create thread 2
(void *sched_data, void *arg)
{
frsh_sched_data_t *frsh = (frsh_sched_data_t *)sched_data;
- int i;
+ int i, err;
+ frsh_signal_t sched_signal = FOSA_SIGNAL_MAX; // HOW TO PUT SIGNALS IF IS OPAQUE??
- set_text_color (GREEN);
printf ("CALLBACK: %s \n", __func__);
printf ("Init args string received: %s \n", (char *)arg);
+ err = fosa_ads_set_handled_signal_set(&sched_signal, 1);
+ printf("set signal set, err=%d\n", err);
+ assert(err == 0);
+
for (i=0; i<MX_THREADS; i++) {
frsh->array_prio[i] = 0;
frsh->array_status[i] = 0;
}
-
- set_text_color (WHITE);
- return;
}
static void frsh_callback_new_thread
frsh_sched_data_t *frsh = (frsh_sched_data_t *)sched_data;
appsched_params_t params;
- set_text_color (GREEN);
printf ("CALLBACK: %s \n", __func__);
index = MX_THREADS;
err = fosa_adsactions_add_activate(actions, thread, params.prio);
assert(err == 0);
}
-
- set_text_color (WHITE);
- return;
}
static void frsh_callback_thread_terminate
struct timespec at_time;
int err;
- set_text_color (GREEN);
printf ("CALLBACK: %s \n", __func__);
fosa_clock_get_time(FOSA_CLOCK_REALTIME, &at_time);
err = fosa_adsactions_add_timeout(actions, FOSA_CLOCK_REALTIME, &at_time);
printf("put a timeout of one second, err=%d\n", err);
assert(err == 0);
-
- set_text_color (WHITE);
}
static void frsh_callback_thread_ready
fosa_ads_actions_t *actions,
struct timespec *current_time)
{
- set_text_color (GREEN);
printf ("CALLBACK: %s \n", __func__);
- set_text_color (WHITE);
}
static void frsh_callback_thread_block
int err;
struct timespec at_time;
- set_text_color (GREEN);
printf ("CALLBACK: %s \n", __func__);
fosa_clock_get_time(FOSA_CLOCK_REALTIME, &at_time);
err = fosa_adsactions_add_timeout(actions, FOSA_CLOCK_REALTIME, &at_time);
printf("put a timeout of one second, err=%d\n", err);
assert(err == 0);
-
- set_text_color (WHITE);
}
static void frsh_callback_change_sched_param_thread
fosa_ads_actions_t *actions,
struct timespec *current_time)
{
- set_text_color (GREEN);
printf ("CALLBACK: %s \n", __func__);
// HOW DO I KNOW THE REASON IS SETPRIO OR SETSCHEDPARAMS????
- set_text_color (WHITE);
}
static void frsh_callback_explicit_call_with_data
fosa_ads_actions_t *actions,
struct timespec *current_time)
{
- set_text_color (GREEN);
printf ("CALLBACK: %s \n", __func__);
printf ("received command: %s \n", (char *)msg);
*((int *)reply) = (int)thread;
- set_text_color (WHITE);
}
static void frsh_callback_notification_for_thread
fosa_ads_actions_t *actions,
struct timespec *current_time)
{
- set_text_color (GREEN);
printf ("CALLBACK: %s \n", __func__);
- set_text_color (WHITE);
}
static void frsh_callback_timeout // WHY NOT WATCHDOG????
fosa_ads_actions_t *actions,
struct timespec *current_time) // WHY IS IN OUT and not IN???
{
- set_text_color (GREEN);
printf ("CALLBACK: %s \n", __func__);
printf("current time sec=%d nsec=%d\n",
current_time->tv_sec, current_time->tv_nsec);
- set_text_color (WHITE);
- return;
}
static void frsh_callback_signal
signal_action_t *signal_action = (signal_action_t *)siginfo.sival_ptr;
frsh_sched_data_t *frsh = (frsh_sched_data_t *)sched_data;
- set_text_color (GREEN);
printf ("CALLBACK: %s \n", __func__);
if (signal_action->command == SUSPEND) {
printf("activating thread 1, err=%d\n", err);
assert(err == 0);
}
- set_text_color (WHITE);
- return;
}
static void frsh_callback_appsched_error
fosa_ads_error_cause_t cause,
fosa_ads_actions_t *actions)
{
- set_text_color (GREEN);
printf ("CALLBACK: %s \n", __func__);
- set_text_color (WHITE);
- return;
}