typedef enum {
ACTIVATE,
- SUSPEND
+ SUSPEND,
+ CAUSE_ERROR
} command_t;
typedef struct {
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);
+ // assert(err == 0);
+
err = fosa_mutex_init(&lock, MX_PRIO);
printf("mutex initialized with ceiling %d. err=%d\n", MX_PRIO, err);
assert(err == 0);
sleep (3);
- fosa_timer_delete(timerid);
+ //////////////////////////////////////////////////////////////
+ // 2e) Cause error
+ //////////////////////////////////////////////////////////////
+ printf("--------------------------------------------------\n");
+ printf("2e) Cause error\n");
- sleep (5);
+ signal_action.command = CAUSE_ERROR;
+ err=fosa_timer_arm(timerid, false, &timerval);
+ printf("causing an ERROR callback in 0.5 secs, err=%d\n", err);
+ assert(err == 0);
+
+ sleep (3);
//////////////////////////////////////////////////////////////
- // 2e) Dettach from application scheduler
+ // 2f) Dettach from application scheduler
//////////////////////////////////////////////////////////////
printf("--------------------------------------------------\n");
- printf("2e) Dettach from application scheduler\n");
+ printf("2f) Dettach from application scheduler\n");
err = fosa_ads_set_appscheduled (tid1, false);
printf("dettach thread 1, err=%d\n", err);
printf("thread 2 is dettached? %d, err=%d\n", !is_appsched, err);
assert(err == 0);
+ fosa_timer_delete(timerid);
+
sleep(1000);
return 0;
}
int reply;
size_t reply_size;
- printf("Thread %d starts\n", (int)arg);
+ printf("Thread %d - starts\n", (int)arg);
for (i=1;i<50;i++) {
nanosleep (&ts, NULL);
- eat (2.0);
-
err=fosa_mutex_lock(&lock);
- printf("mutex locked by %d. err=%d\n", (int)arg, err);
+ printf("Thread %d - mutex locked, err=%d\n", (int)arg, err);
assert(err == 0);
eat (1.0);
err=fosa_mutex_unlock(&lock);
- printf("mutex unlocked %d. err=%d\n", (int)arg, err);
+ printf("Thread %d - mutex unlocked, err=%d\n", (int)arg, err);
assert(err == 0);
err = fosa_ads_invoke_withdata
(whoami, sizeof(whoami), (void *)&reply, &reply_size);
- printf("who am I, correct?: %d, err=%d\n", reply == (int)arg, err);
- assert(err == 0);
+ printf("Thread %d - who am I, correct?: %d, err=%d\n", (int)arg,
+ reply == (int)fosa_thread_self(), err);
+ if (err != 0) {
+ pthread_exit (NULL);
+ }
- eat (1.0);
}
return NULL;
}
struct timespec *current_time)
{
printf ("CALLBACK: %s \n", __func__);
- printf ("received command: %s \n", (char *)msg);
*((int *)reply) = (int)thread;
+ printf ("received command: %s , answer %d \n", (char *)msg,
+ *((int *)reply));
}
static void frsh_callback_notification_for_thread
printf ("CALLBACK: %s \n", __func__);
- if (signal_action->command == SUSPEND) {
- err = fosa_adsactions_add_suspend(actions, signal_action->thread_id);
- printf("suspending thread 1 , err=%d\n", err);
- assert(err == 0);
- } else {
- err = fosa_adsactions_add_activate
- (actions, signal_action->thread_id, frsh->array_prio[0]);
- printf("activating thread 1, err=%d\n", err);
- assert(err == 0);
+ switch (signal_action->command) {
+ case SUSPEND:
+ err=fosa_adsactions_add_suspend(actions, signal_action->thread_id);
+ printf("suspending thread 1 , err=%d\n", err);
+ assert(err == 0);
+ break;
+ case ACTIVATE:
+ err = fosa_adsactions_add_activate
+ (actions, signal_action->thread_id, frsh->array_prio[0]);
+ printf("activating thread 1, err=%d\n", err);
+ assert(err == 0);
+ break;
+ case CAUSE_ERROR:
+ // cause an error by using a wrong thread id: 666 ;D
+ err = fosa_adsactions_add_activate
+ (actions, (frsh_thread_id_t)666, frsh->array_prio[0]);
+ printf("causing an error, err=%d\n", err);
+ assert(err == 0);
+ break;
}
}