struct posix_appsched_event event;
struct timespec current_time;
posix_appsched_eventset_t accepted_events;
-// bool active;
-
- printf ("SCHEDULER thread=0x%lx\n\n", (unsigned long) pthread_self ());
// accept events which have a callback associated
posix_appsched_fillset (&accepted_events);
clear_actions (&actions);
while (1) { // scheduler loop
-// printf ("ACTIONS: timeout(0x%x), handled_signals=0x%x\n", actions.timeout_ptr, fosa_handled_signals.sig);
if (posix_appsched_execute_actions(&(actions.actions), &fosa_handled_signals, actions.timeout_ptr,
¤t_time, &event))
- perror ("posix_appsched_execute_actions");
+ {
+ fosa_scheduler_ops.appsched_error
+ (fosa_scheduler_data, 0x0, FOSA_ADS_THREAD_NOT_ATTACHED, &actions);
+ continue;
+ }
-// printf ("\nReceived event=%d. current_time={%ld,%ld}\n", event.event_code, current_time.tv_sec, current_time.tv_nsec);
clear_actions (&actions);
-
switch (event.event_code) {
case POSIX_APPSCHED_NEW:
fosa_scheduler_ops.new_thread
if (!actions.rejected) {
-/* active = actions.activated;
- int suspend = actions.suspended; */
-// #ifndef CONFIG_URGENCY
clear_actions (&actions);
-// printf ("NEW: activate (%d), suspend (%d)\n", actions.activated, actions.suspended);
-// // #endif
// alloc memory for reply info of 'fosa_ads_invoke_with_data ()'
struct reply_info *reply_mem = malloc (sizeof (struct reply_info));
¤t_time);
break;
- case POSIX_APPSCHED_ERROR:
+ case POSIX_APPSCHED_ERROR: // Implemented using the usual error handling mechanism
fosa_scheduler_ops.appsched_error
(fosa_scheduler_data,
event.thread,
pthread_attr_t attr;
struct sched_param sp;
-
- printf ("\nMAIN thread=0x%lx\n\n", (unsigned long)pthread_self ());
-
-
if (!scheduler_ops)
return EINVAL;
fosa_scheduler_ops = *scheduler_ops;
pthread_getschedparam (thread, &policy, &sp);
fosa_thread_get_prio (thread, &fosaprio);
sp.sched_priority = fosa2prtk (fosaprio, urgency);
- printf ("policy=%d, prio=%d, urg=%d, new_prio=%d\n", policy);
+// printf ("policy=%d, prio=%d, urg=%d, new_prio=%d\n", policy);
pthread_setschedparam (thread, policy, &sp);
#endif
return posix_appsched_actions_addactivate (&(sched_actions -> actions), thread);
// however invalidate any other reasons why the executable file might be
// covered by the GNU Public License.
// -----------------------------------------------------------------------
-//fosa_long_jump.h
+//fosa_long_jump.c
//==============================================
// ******** ****** ******** **********
// **///// /** ** **////// /** /**
enum {
LONGJMP_MAGIC = 0x01234567,
- LONGJMP_NSIG = 3,
- LONGJMP_FIRSTSIG = SIGRTMIN + 1,
};
int jmp_used_signals [LONGJMP_NSIG] = {[0 ... (LONGJMP_NSIG - 1)] = 0};
+pthread_mutex_t signal_pool_m = PTHREAD_MUTEX_INITIALIZER
int fosa_long_jump_save_context
sigset_t set;
#ifdef CONFIG_LONGJUMP_FREE_SIGNALS
- // Restore the signal mask beofre the context save
+ // Restore the signal mask
pthread_sigmask (SIG_SETMASK, &(context -> jmp_sigmask), NULL);
// Free this signal
sigaddset (&set, signo);
pthread_sigmask (SIG_BLOCK, &sigmask, NULL);
- pthread_mutex_lock ();
+ pthread_mutex_lock (&signal_pool_m);
jmp_used_signals [signo] = 0;
- pthread_mutex_unlock ();
+ pthread_mutex_unlock (&signal_pool_m);
#endif
// Restore the saved context
sigset_t sigmask;
// Find the first usable signal
- // FIXME: Should be atomical
+ pthread_mutex_lock (&signal_pool_m);
for (i = 0; i < LONGJMP_NSIG && jmp_used_signals [i]; i++);
- if (i >= LONGJMP_NSIG)
+ if (i >= LONGJMP_NSIG) {
+ pthread_mutex_unlock (&signal_pool_m);
return FOSA_ENOMEM;
+ }
jmp_used_signals [i] = 1;
+ pthread_mutex_unlock (&signal_pool_m);
*signal = LONGJMP_FIRSTSIG + i;
*handler = pthread_self ();