]> rtime.felk.cvut.cz Git - frescor/fosa.git/commitdiff
updated test ads and corrected error in appdefsched.c
authorsangorrin <sangorrin@35b4ef3e-fd22-0410-ab77-dab3279adceb>
Wed, 13 Jun 2007 10:18:46 +0000 (10:18 +0000)
committersangorrin <sangorrin@35b4ef3e-fd22-0410-ab77-dab3279adceb>
Wed, 13 Jun 2007 10:18:46 +0000 (10:18 +0000)
git-svn-id: http://www.frescor.org/private/svn/frescor/fosa/trunk@458 35b4ef3e-fd22-0410-ab77-dab3279adceb

src_marte/fosa_app_def_sched.c
src_marte/test_fosa_ads.c

index 672270d5ce9b576876a77578d8c9a80dd2d24425..86fe0be6aee469d3b72a9dac904ed7a2d46aca72 100644 (file)
@@ -211,7 +211,7 @@ void * scheduler_thread_code(void *arg) {
     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
@@ -268,7 +268,7 @@ void * scheduler_thread_code(void *arg) {
            if (!sched_actions.suspended && !sched_actions.activated) {
              CHK(posix_appsched_actions_addactivate
                  (&(sched_actions.actions),event.thread));
-           } 
+           }
          }
        }
        break;
@@ -340,7 +340,7 @@ void * scheduler_thread_code(void *arg) {
           clk,
           &sched_actions,
           &current_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
@@ -412,7 +412,7 @@ int fosa_ads_scheduler_create
   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;
@@ -498,7 +498,17 @@ int fosa_thread_attr_set_appscheduled
         (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);
+    }
 }
 
 /**
@@ -788,7 +798,7 @@ int fosa_adsactions_add_reject(
         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;
@@ -836,7 +846,7 @@ int fosa_adsactions_add_activate(
         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;
@@ -878,7 +888,7 @@ int fosa_adsactions_add_suspend(
         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;
@@ -956,7 +966,7 @@ int fosa_adsactions_add_thread_notification(
         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;
@@ -1012,7 +1022,7 @@ int fosa_ads_set_handled_signal_set(frsh_signal_t set[], int size)
 {
   int i;
 
-#ifdef FULL_ERROR_CHECKING  
+#ifdef FULL_ERROR_CHECKING
   // check errors
   if (!pthread_equal(pthread_self(),scheduler_thread_id)) {
     return FOSA_EPOLICY;
@@ -1081,7 +1091,7 @@ int fosa_ads_invoke_withdata
   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;
index 8af8300940e9aaa9abcf8c8e25a01625923925bf..235354638a21ef3839941421a6822aa56bac8e7b 100644 (file)
@@ -7,16 +7,23 @@
 #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);
 
@@ -141,7 +148,6 @@ int main () {
     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;
@@ -163,10 +169,6 @@ int main () {
     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),
@@ -190,7 +192,7 @@ int main () {
     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);
 
@@ -202,21 +204,21 @@ int main () {
     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, &params, sizeof(params));
-    printf("thread attr set params prio=10, err=%d\n", err);
+            (&th_attr, (void *)&params, 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 *)&params, 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
@@ -353,19 +355,20 @@ static void frsh_callback_init
         (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
@@ -379,7 +382,6 @@ 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;
@@ -404,9 +406,6 @@ static void frsh_callback_new_thread
         err = fosa_adsactions_add_activate(actions, thread, params.prio);
         assert(err == 0);
     }
-
-    set_text_color (WHITE);
-    return;
 }
 
 static void frsh_callback_thread_terminate
@@ -418,7 +417,6 @@ 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);
@@ -428,8 +426,6 @@ static void frsh_callback_thread_terminate
     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
@@ -438,9 +434,7 @@ 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
@@ -452,7 +446,6 @@ 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);
@@ -462,8 +455,6 @@ static void frsh_callback_thread_block
     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
@@ -472,10 +463,8 @@ 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
@@ -488,11 +477,9 @@ 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
@@ -502,9 +489,7 @@ 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????
@@ -512,12 +497,9 @@ 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
@@ -531,7 +513,6 @@ 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) {
@@ -544,8 +525,6 @@ static void frsh_callback_signal
         printf("activating thread 1, err=%d\n", err);
         assert(err == 0);
     }
-    set_text_color (WHITE);
-    return;
 }
 
 static void frsh_callback_appsched_error
@@ -554,8 +533,5 @@ 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;
 }