From d28fc863708d1d452e9f02ecbd768803de0b6196 Mon Sep 17 00:00:00 2001 From: faggioli Date: Sat, 14 Feb 2009 18:15:40 +0000 Subject: [PATCH 1/1] Bugfixes and restyling. git-svn-id: http://www.frescor.org/private/svn/frescor/fosa/trunk@1550 35b4ef3e-fd22-0410-ab77-dab3279adceb --- src_aquosa/fosa_app_def_sched.c | 34 +++++------ src_aquosa/fosa_clocks_and_timers.c | 10 ++-- src_aquosa/fosa_group_clocks.c | 10 ++-- src_aquosa/fosa_long_jump.c | 5 +- src_aquosa/fosa_platform_values.c | 2 +- src_aquosa/fosa_threads_and_signals.c | 81 +++++---------------------- src_aquosa/fosa_time.c | 8 +-- 7 files changed, 49 insertions(+), 101 deletions(-) diff --git a/src_aquosa/fosa_app_def_sched.c b/src_aquosa/fosa_app_def_sched.c index ec22b9a..4807a3f 100644 --- a/src_aquosa/fosa_app_def_sched.c +++ b/src_aquosa/fosa_app_def_sched.c @@ -111,7 +111,7 @@ int fosa_ads_scheduler_create(const fosa_ads_scheduler_ops_t * scheduler_ops, size_t scheduler_data_size, void * init_args, size_t init_args_size) { - return -EINVAL; + return FOSA_EINVAL; } /** @@ -135,7 +135,7 @@ int fosa_ads_scheduler_create(const fosa_ads_scheduler_ops_t * scheduler_ops, int fosa_thread_attr_set_appscheduled(fosa_thread_attr_t *attr, bool appscheduled) { - return -EINVAL; + return FOSA_EINVAL; } /** @@ -159,7 +159,7 @@ int fosa_thread_attr_set_appscheduled(fosa_thread_attr_t *attr, int fosa_thread_attr_get_appscheduled(const fosa_thread_attr_t *attr, bool *appscheduled) { - return -EINVAL; + return FOSA_EINVAL; } /** @@ -187,7 +187,7 @@ int fosa_thread_attr_set_appsched_params(fosa_thread_attr_t *attr, const void *param, size_t paramsize) { - return -EINVAL; + return FOSA_EINVAL; } /** @@ -215,7 +215,7 @@ int fosa_thread_attr_set_appsched_params(fosa_thread_attr_t *attr, int fosa_thread_attr_get_appsched_params(const fosa_thread_attr_t *attr, void *param, size_t *paramsize) { - return -EINVAL; + return FOSA_EINVAL; } /** @@ -243,7 +243,7 @@ int fosa_thread_attr_get_appsched_params(const fosa_thread_attr_t *attr, **/ int fosa_ads_set_appscheduled(fosa_thread_id_t thread, bool appscheduled) { - return -EINVAL; + return FOSA_EINVAL; } /** @@ -266,7 +266,7 @@ int fosa_ads_set_appscheduled(fosa_thread_id_t thread, bool appscheduled) **/ int fosa_ads_get_appscheduled(fosa_thread_id_t thread, bool *appscheduled) { - return -EINVAL; + return FOSA_EINVAL; } @@ -295,7 +295,7 @@ int fosa_ads_get_appscheduled(fosa_thread_id_t thread, bool *appscheduled) int fosa_ads_set_appsched_params(fosa_thread_id_t thread, const void *param, size_t paramsize) { - return -EINVAL; + return FOSA_EINVAL; } /** @@ -324,7 +324,7 @@ int fosa_ads_set_appsched_params(fosa_thread_id_t thread, int fosa_ads_get_appsched_params(fosa_thread_id_t thread, void *param, size_t *paramsize) { - return -EINVAL; + return FOSA_EINVAL; } @@ -375,7 +375,7 @@ int fosa_ads_get_appsched_params(fosa_thread_id_t thread, int fosa_adsactions_add_reject(fosa_ads_actions_t *sched_actions, fosa_thread_id_t thread) { - return -EINVAL; + return FOSA_EINVAL; } /** @@ -414,7 +414,7 @@ int fosa_adsactions_add_activate(fosa_ads_actions_t *sched_actions, fosa_thread_id_t thread, fosa_ads_urgency_t urgency) { - return -EINVAL; + return FOSA_EINVAL; } /** @@ -443,7 +443,7 @@ int fosa_adsactions_add_activate(fosa_ads_actions_t *sched_actions, int fosa_adsactions_add_suspend(fosa_ads_actions_t *sched_actions, fosa_thread_id_t thread) { - return -EINVAL; + return FOSA_EINVAL; } /** @@ -470,7 +470,7 @@ int fosa_adsactions_add_timeout(fosa_ads_actions_t *sched_actions, fosa_clock_id_t clock_id, const fosa_abs_time_t *at_time) { - return -EINVAL; + return FOSA_EINVAL; } /** @@ -506,7 +506,7 @@ int fosa_adsactions_add_thread_notification(fosa_ads_actions_t *sched_actions, fosa_clock_id_t clock_id, const fosa_abs_time_t *at_time) { - return -EINVAL; + return FOSA_EINVAL; } @@ -540,7 +540,7 @@ int fosa_adsactions_add_thread_notification(fosa_ads_actions_t *sched_actions, **/ int fosa_ads_set_handled_signal_set(fosa_signal_t set[], int size) { - return -EINVAL; + return FOSA_EINVAL; } @@ -576,7 +576,7 @@ int fosa_ads_set_handled_signal_set(fosa_signal_t set[], int size) **/ int fosa_signal_queue_scheduler(fosa_signal_t signal, fosa_signal_info_t info) { - return -EINVAL; + return FOSA_EINVAL; } /** @@ -625,6 +625,6 @@ int fosa_signal_queue_scheduler(fosa_signal_t signal, fosa_signal_info_t info) int fosa_ads_invoke_withdata(const void *msg, size_t msg_size, void *reply, size_t *reply_size) { - return -EINVAL; + return FOSA_EINVAL; } diff --git a/src_aquosa/fosa_clocks_and_timers.c b/src_aquosa/fosa_clocks_and_timers.c index 9dae54c..5adb0d6 100644 --- a/src_aquosa/fosa_clocks_and_timers.c +++ b/src_aquosa/fosa_clocks_and_timers.c @@ -231,7 +231,7 @@ int fosa_timer_delete(fosa_timer_id_t timerid) * notify it to the system console and then terminate the FRSH * implementation and dependant applications **/ -int fosa_rel_timer_arm (fosa_timer_id_t timerid, const fosa_rel_time_t *value) +int fosa_rel_timer_arm(fosa_timer_id_t timerid, const fosa_rel_time_t *value) { struct itimerspec when; @@ -274,8 +274,8 @@ int fosa_abs_timer_arm(fosa_timer_id_t timerid, const fosa_abs_time_t *value) struct itimerspec when; /* non-periodic one shot timer */ - when.it_value= fosa_abs_time_to_timespec(*value); - when.it_interval=zero_time; + when.it_value = fosa_abs_time_to_timespec(*value); + when.it_interval = zero_time; return timer_settime(timerid, TIMER_ABSTIME, &when, NULL); } @@ -300,7 +300,7 @@ int fosa_timer_get_remaining_time(fosa_timer_id_t timerid, int ret; struct itimerspec time; - if (remaining_time == NULL) + if (!remaining_time) return FOSA_EINVAL; ret = timer_gettime(timerid, &time); @@ -331,7 +331,7 @@ int fosa_timer_disarm(fosa_timer_id_t timerid, int ret; struct itimerspec time; - if (remaining_time == NULL) + if (!remaining_time) return FOSA_EINVAL; ret = timer_gettime(timerid, &time); diff --git a/src_aquosa/fosa_group_clocks.c b/src_aquosa/fosa_group_clocks.c index 6b96063..f0e8a38 100644 --- a/src_aquosa/fosa_group_clocks.c +++ b/src_aquosa/fosa_group_clocks.c @@ -87,7 +87,7 @@ **/ int fosa_thread_set_create(fosa_thread_set_id_t *set) { - return -EINVAL; + return EINVAL; } @@ -111,7 +111,7 @@ int fosa_thread_set_create(fosa_thread_set_id_t *set) **/ int fosa_thread_set_destroy(fosa_thread_set_id_t set) { - return -EINVAL; + return EINVAL; } @@ -135,7 +135,7 @@ int fosa_thread_set_destroy(fosa_thread_set_id_t set) **/ int fosa_thread_set_add(fosa_thread_set_id_t set, fosa_thread_id_t thread_id) { - return -EINVAL; + return EINVAL; } @@ -159,7 +159,7 @@ int fosa_thread_set_add(fosa_thread_set_id_t set, fosa_thread_id_t thread_id) int fosa_thread_set_del(fosa_thread_set_id_t set, fosa_thread_id_t thread_id) { - return -EINVAL; + return EINVAL; } @@ -184,6 +184,6 @@ int fosa_thread_set_del(fosa_thread_set_id_t set, fosa_thread_id_t thread_id) int fosa_get_groupcpu_clock(const fosa_thread_set_id_t set, fosa_clock_id_t *clock_id) { - return -EINVAL; + return EINVAL; } diff --git a/src_aquosa/fosa_long_jump.c b/src_aquosa/fosa_long_jump.c index 829e2c7..b1e193a 100644 --- a/src_aquosa/fosa_long_jump.c +++ b/src_aquosa/fosa_long_jump.c @@ -132,7 +132,7 @@ int fosa_long_jump_save_context(fosa_long_jump_context_t *context) int fosa_long_jump_was_performed(const fosa_long_jump_context_t *context, int *jumped) { - return ENOSYS; + return EINVAL; } /** @@ -140,7 +140,8 @@ int fosa_long_jump_was_performed(const fosa_long_jump_context_t *context, **/ void __long_jump_handler(int n, siginfo_t *info, void *c) { - fosa_long_jump_context_t *context = (fosa_long_jump_context_t*)info->si_ptr; + fosa_long_jump_context_t *context = + (fosa_long_jump_context_t*) info->si_ptr; siglongjmp(*context, 1); } diff --git a/src_aquosa/fosa_platform_values.c b/src_aquosa/fosa_platform_values.c index da350d1..23c1db8 100644 --- a/src_aquosa/fosa_platform_values.c +++ b/src_aquosa/fosa_platform_values.c @@ -84,6 +84,6 @@ int fosa_get_cpu_resource_id(fosa_resource_id_t *cpu_id) { - return -ENOSYS; + return FOSA_EINVAL; } diff --git a/src_aquosa/fosa_threads_and_signals.c b/src_aquosa/fosa_threads_and_signals.c index 1cb4795..3f64a67 100644 --- a/src_aquosa/fosa_threads_and_signals.c +++ b/src_aquosa/fosa_threads_and_signals.c @@ -135,6 +135,14 @@ fosa_thread_id_t fosa_thread_self() * Thread attributes *************************/ +static inline int __fosa_check_thread(const fosa_thread_id_t *tid) +{ + if (tid->linux_pid == tid->linux_tid) + return 0; + + return 1; +} + /** * fosa_thread_attr_init() * @@ -149,13 +157,6 @@ fosa_thread_id_t fosa_thread_self() **/ int fosa_thread_attr_init(fosa_thread_attr_t *attr) { - fosa_thread_id_t self; - - /* only POSIX threads have attributes */ - self = fosa_thread_self(); - if (self.linux_pid == self.linux_tid) - return EINVAL; - return pthread_attr_init(attr); } @@ -171,13 +172,6 @@ int fosa_thread_attr_init(fosa_thread_attr_t *attr) **/ int fosa_thread_attr_destroy(fosa_thread_attr_t *attr) { - fosa_thread_id_t self; - - /* only POSIX threads can have attributes */ - self = fosa_thread_self(); - if (self.linux_pid == self.linux_tid) - return EINVAL; - return pthread_attr_destroy(attr); } @@ -199,13 +193,6 @@ int fosa_thread_attr_destroy(fosa_thread_attr_t *attr) int fosa_thread_attr_set_stacksize(fosa_thread_attr_t *attr, size_t stacksize) { - fosa_thread_id_t self; - - /* only POSIX threads can set the size of the stack */ - self = fosa_thread_self(); - if (self.linux_pid == self.linux_tid) - return EINVAL; - return pthread_attr_setstacksize(attr, stacksize); } @@ -222,13 +209,6 @@ int fosa_thread_attr_set_stacksize(fosa_thread_attr_t *attr, int fosa_thread_attr_get_stacksize(const fosa_thread_attr_t *attr, size_t *stacksize) { - fosa_thread_id_t self; - - /* only POSIX threads can set the size of the stack */ - self = fosa_thread_self(); - if (self.linux_pid == self.linux_tid) - return EINVAL; - return pthread_attr_getstacksize(attr, stacksize); } @@ -301,12 +281,6 @@ int fosa_key_create(int *key) { int i, error = 0; bool found = false; - fosa_thread_id_t self; - - /* only POSIX threads can have specific data */ - self = fosa_thread_self(); - if (self.linux_pid == self.linux_tid) - return EINVAL; if ((error = pthread_mutex_lock(&key_lock)) != 0) return error; @@ -341,12 +315,6 @@ int fosa_key_create(int *key) int fosa_key_destroy(int key) { int error; - fosa_thread_id_t self; - - /* only POSIX threads can have specific data */ - self = fosa_thread_self(); - if (self.linux_pid == self.linux_tid) - return EINVAL; if ((error = pthread_mutex_lock(&key_lock)) != 0) return error; @@ -379,11 +347,8 @@ int fosa_key_destroy(int key) fosa_thread_id_t tid, const void * value) { - fosa_thread_id_t self; - /* only POSIX threads can have specific data */ - self = fosa_thread_self(); - if (self.linux_pid == self.linux_tid) + if (!__fosa_check_thread(&tid)) return EINVAL; return pthread_setspecific(key_list[key], value); @@ -407,11 +372,8 @@ int fosa_thread_get_specific_data(int key, fosa_thread_id_t tid, void ** value) { - fosa_thread_id_t self; - /* only POSIX threads can have specific data */ - self = fosa_thread_self(); - if (self.linux_pid == self.linux_tid) + if (!__fosa_check_thread(&tid)) return EINVAL; if ((value = pthread_getspecific(key_list[key])) != NULL) @@ -470,14 +432,8 @@ int fosa_get_priority_min() int fosa_thread_attr_set_prio(fosa_thread_attr_t *attr, int prio) { int error; - fosa_thread_id_t self; struct sched_param param; - /* normal UNIX processes have no attributes */ - self = fosa_thread_self(); - if (self.linux_pid == self.linux_tid) - return EINVAL; - param.sched_priority = prio; if ((error = pthread_attr_setschedpolicy(attr, SCHED_RR)) == 0) return error; @@ -498,14 +454,8 @@ int fosa_thread_attr_set_prio(fosa_thread_attr_t *attr, int prio) int fosa_thread_attr_get_prio(const fosa_thread_attr_t *attr, int *prio) { int error; - fosa_thread_id_t self; struct sched_param param; - /* normal UNIX processes have no attributes */ - self = fosa_thread_self(); - if (self.linux_pid == self.linux_tid) - return EINVAL; - if ((error = pthread_attr_getschedparam(attr, ¶m)) == 0) *prio = param.sched_priority; @@ -529,8 +479,7 @@ int fosa_thread_set_prio(fosa_thread_id_t tid, int prio) { struct sched_param param; - param.sched_priority=prio; - + param.sched_priority = prio; return sched_setscheduler(0, SCHED_RR, ¶m); } @@ -547,12 +496,12 @@ int fosa_thread_set_prio(fosa_thread_id_t tid, int prio) int fosa_thread_get_prio(fosa_thread_id_t tid, int *prio) { struct sched_param param; - int error; + int ret; - error = sched_getparam(0, ¶m); + ret = sched_getparam(0, ¶m); *prio = param.sched_priority; - return error; + return ret; } /******************************************************************* @@ -609,7 +558,7 @@ int fosa_set_accepted_signals(fosa_signal_t set[], int size) } self = fosa_thread_self(); - if (self.linux_pid == self.linux_tid) + if (__fosa_check_thread(&self)) return pthread_sigmask(SIG_BLOCK, &sigset, NULL); else return sigprocmask(SIG_BLOCK, &sigset, NULL); diff --git a/src_aquosa/fosa_time.c b/src_aquosa/fosa_time.c index fdbf95e..571ccce 100644 --- a/src_aquosa/fosa_time.c +++ b/src_aquosa/fosa_time.c @@ -64,6 +64,7 @@ //================================================ #include "fosa_time.h" +#include "fosa_clocks_and_timers.h" #include "fosa_threads_and_signals.h" /** @@ -79,11 +80,8 @@ void inline fosa_eat(const struct timespec *cpu_time) struct timespec current_time, time_to_go; self = fosa_thread_self(); - if (self.linux_pid == self.linux_tid) - error = clock_getcpuclockid(self.linux_pid, &clock_id); - else - error = pthread_getcpuclockid(self.pthread_id, &clock_id); - if (error != 0) + error = fosa_thread_get_cputime_clock(self, &clock_id); + if (!error) return; if (clock_gettime(clock_id, ¤t_time) != 0) -- 2.39.2