Module: xenomai-3
Branch: master
Commit: 2dd50c880950fc9a93c0f76fbe1f7c202a46092b
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=2dd50c880950fc9a93c0f76fbe1f7c202a46092b

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sun Jul 26 11:25:24 2015 +0200

lib/cobalt: output sync delay fit in a regular integer

---

 include/cobalt/tunables.h |    8 ++++----
 lib/cobalt/init.c         |   29 +++++++++++++++--------------
 lib/cobalt/printf.c       |    6 +++---
 3 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/include/cobalt/tunables.h b/include/cobalt/tunables.h
index 67953c2..67ac77a 100644
--- a/include/cobalt/tunables.h
+++ b/include/cobalt/tunables.h
@@ -31,7 +31,7 @@ extern int __cobalt_print_bufsz;
 
 extern int __cobalt_print_bufcount;
 
-extern unsigned long long __cobalt_print_syncdelay;
+extern int __cobalt_print_syncdelay;
 
 static inline define_config_tunable(main_prio, int, prio)
 {
@@ -63,12 +63,12 @@ static inline read_config_tunable(print_buffer_count, int)
        return __cobalt_print_bufcount;
 }
 
-static inline define_config_tunable(print_sync_delay, unsigned long long, 
delay)
+static inline define_config_tunable(print_sync_delay, int, delay_ms)
 {
-       __cobalt_print_syncdelay = delay;
+       __cobalt_print_syncdelay = delay_ms;
 }
 
-static inline read_config_tunable(print_sync_delay, unsigned long long)
+static inline read_config_tunable(print_sync_delay, int)
 {
        return __cobalt_print_syncdelay;
 }
diff --git a/lib/cobalt/init.c b/lib/cobalt/init.c
index 85dd590..2a81814 100644
--- a/lib/cobalt/init.c
+++ b/lib/cobalt/init.c
@@ -26,6 +26,7 @@
 #include <getopt.h>
 #include <limits.h>
 #include <unistd.h>
+#include <stdint.h>
 #include <semaphore.h>
 #include <boilerplate/setup.h>
 #include <cobalt/uapi/kernel/heap.h>
@@ -230,16 +231,17 @@ int cobalt_init(void)
 }
 
 static int get_int_arg(const char *name, const char *arg,
-                      unsigned long long *valp)
+                      int *valp, int min)
 {
-       unsigned long long value;
+       int value, ret;
        char *p;
        
        errno = 0;
-       value = strtoll(arg, &p, 10);
-       if (errno || *p) {
+       value = (int)strtol(arg, &p, 10);
+       if (errno || *p || value < min) {
+               ret = -errno ?: -EINVAL;
                early_warning("invalid value for %s: %s", name, arg);
-               return -errno;
+               return ret;
        }
 
        *valp = value;
@@ -249,30 +251,29 @@ static int get_int_arg(const char *name, const char *arg,
 
 static int cobalt_parse_option(int optnum, const char *optarg)
 {
-       unsigned long long value;
-       int ret;
+       int value, ret;
 
        switch (optnum) {
        case main_prio_opt:
-               ret = get_int_arg("--main-prio", optarg, &value);
+               ret = get_int_arg("--main-prio", optarg, &value, INT32_MIN);
                if (ret)
                        return ret;
-               __cobalt_main_prio = (int)value;
+               __cobalt_main_prio = value;
                break;
        case print_bufsz_opt:
-               ret = get_int_arg("--print-buffer-size", optarg, &value);
+               ret = get_int_arg("--print-buffer-size", optarg, &value, 0);
                if (ret)
                        return ret;
-               __cobalt_print_bufsz = (int)value;
+               __cobalt_print_bufsz = value;
                break;
        case print_bufcnt_opt:
-               ret = get_int_arg("--print-buffer-count", optarg, &value);
+               ret = get_int_arg("--print-buffer-count", optarg, &value, 0);
                if (ret)
                        return ret;
-               __cobalt_print_bufcount = (int)value;
+               __cobalt_print_bufcount = value;
                break;
        case print_syncdelay_opt:
-               ret = get_int_arg("--print-sync-delay", optarg, &value);
+               ret = get_int_arg("--print-sync-delay", optarg, &value, 0);
                if (ret)
                        return ret;
                __cobalt_print_syncdelay = value;
diff --git a/lib/cobalt/printf.c b/lib/cobalt/printf.c
index e7ff120..c016fb2 100644
--- a/lib/cobalt/printf.c
+++ b/lib/cobalt/printf.c
@@ -72,7 +72,7 @@ __weak int __cobalt_print_bufsz = RT_PRINT_DEFAULT_BUFFER;
 
 __weak int __cobalt_print_bufcount = RT_PRINT_DEFAULT_BUFFERS_COUNT;
 
-__weak unsigned long long __cobalt_print_syncdelay = 
RT_PRINT_DEFAULT_SYNCDELAY;
+__weak int __cobalt_print_syncdelay = RT_PRINT_DEFAULT_SYNCDELAY;
 
 static struct print_buffer *first_buffer;
 static int buffers;
@@ -693,8 +693,8 @@ void cobalt_print_init(void)
        first_buffer = NULL;
        seq_no = 0;
 
-       syncdelay.tv_sec  = __cobalt_print_syncdelay / 1000ULL;
-       syncdelay.tv_nsec = (__cobalt_print_syncdelay % 1000ULL) * 1000000;
+       syncdelay.tv_sec  = __cobalt_print_syncdelay / 1000;
+       syncdelay.tv_nsec = (__cobalt_print_syncdelay % 1000) * 1000000;
 
        /* Fill the buffer pool */
        pool_bitmap_len = (__cobalt_print_bufcount+__WORDSIZE-1)/__WORDSIZE;


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to