Module: xenomai-3
Branch: next
Commit: 309d1dd9e4dd8456102a3469658f26f5f24c00db
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=309d1dd9e4dd8456102a3469658f26f5f24c00db

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue May 19 11:31:28 2015 +0200

psos: turn long names options into a standard tunable

---

 include/psos/psos.h |   13 ++++++++++++-
 lib/psos/init.c     |   21 +++++++++------------
 lib/psos/internal.h |   16 ++++++++++++++--
 lib/psos/pt.c       |    4 ++--
 lib/psos/queue.c    |    4 ++--
 lib/psos/rn.c       |    4 ++--
 lib/psos/sem.c      |    4 ++--
 lib/psos/task.c     |    4 ++--
 8 files changed, 45 insertions(+), 25 deletions(-)

diff --git a/include/psos/psos.h b/include/psos/psos.h
index 3359892..a6f1559 100644
--- a/include/psos/psos.h
+++ b/include/psos/psos.h
@@ -25,6 +25,7 @@
 #define _XENOMAI_PSOS_PSOS_H
 
 #include <sys/types.h>
+#include <boilerplate/tunables.h>
 
 #ifndef SUCCESS
 #define SUCCESS 0
@@ -369,7 +370,17 @@ int psos_task_normalize_priority(u_long psos_prio);
 
 u_long psos_task_denormalize_priority(int core_prio);
 
-extern unsigned int psos_long_names;
+extern int psos_long_names;
+
+static inline define_config_tunable(long_names, int, on)
+{
+       psos_long_names = on;
+}
+
+static inline read_config_tunable(long_names, int)
+{
+       return psos_long_names;
+}
 
 #ifdef __cplusplus
 }
diff --git a/lib/psos/init.c b/lib/psos/init.c
index be4e157..81c09af 100644
--- a/lib/psos/init.c
+++ b/lib/psos/init.c
@@ -46,7 +46,7 @@
  * - Tasks, Events, Queues, Semaphores
  * - Partitions, Regions, Timers
  */
-unsigned int psos_long_names;
+int psos_long_names = 0;
 
 static unsigned int clock_resolution = 1000000; /* 1ms */
 
@@ -68,6 +68,12 @@ static const struct option psos_options[] = {
                .val = 0
        },
        {
+#define long_names_opt 2
+               .name = "psos-long-names",
+               .flag = &psos_long_names,
+               .val = 1
+       },
+       {
                .name = NULL,
                .has_arg = 0,
                .flag = NULL,
@@ -84,6 +90,8 @@ static int psos_parse_option(int optnum, const char *optarg)
        case time_slice_opt:
                time_slice_in_ticks = atoi(optarg);
                break;
+       case long_names_opt:
+               break;
        default:
                /* Paranoid, can't happen. */
                return -EINVAL;
@@ -129,17 +137,6 @@ static int psos_init(void)
        return 0;
 }
 
-const char *__psos_maybe_short_name(char shrt[5], const char *lng)
-{
-       if (psos_long_names)
-               return lng;
-
-       strncpy(shrt, lng, 5 - 1);
-       shrt[4] = '\0';
-
-       return (const char *)shrt;
-}
-
 static struct setup_descriptor psos_skin = {
        .name = "psos",
        .init = psos_init,
diff --git a/lib/psos/internal.h b/lib/psos/internal.h
index 01432ba..0e5f108 100644
--- a/lib/psos/internal.h
+++ b/lib/psos/internal.h
@@ -18,7 +18,19 @@
 #ifndef _PSOS_INTERNAL_H
 #define _PSOS_INTERNAL_H
 
-const char *__psos_maybe_short_name(char shrt[5],
-                                   const char *lng);
+#include <string.h>
+
+extern int psos_long_names;
+
+static inline
+const char *psos_trunc_name(char dst[5], const char *src)
+{
+       if (psos_long_names)
+               return src;
+
+       strncpy(dst, src, 4)[4] = '\0';
+
+       return dst;
+}
 
 #endif /* !_PSOS_INTERNAL_H */
diff --git a/lib/psos/pt.c b/lib/psos/pt.c
index 324ece6..afdda32 100644
--- a/lib/psos/pt.c
+++ b/lib/psos/pt.c
@@ -145,7 +145,7 @@ u_long pt_create(const char *name,
        if (name == NULL || *name == '\0')
                sprintf(pt->name, "pt%lu", ++anon_ptids);
        else {
-               name = __psos_maybe_short_name(short_name, name);
+               name = psos_trunc_name(short_name, name);
                namecpy(pt->name, name);
        }
 
@@ -295,7 +295,7 @@ u_long pt_ident(const char *name, u_long node, u_long 
*ptid_r)
        if (node)
                return ERR_NODENO;
 
-       name = __psos_maybe_short_name(short_name, name);
+       name = psos_trunc_name(short_name, name);
 
        CANCEL_DEFER(svc);
        cobj = pvcluster_findobj(&psos_pt_table, name);
diff --git a/lib/psos/queue.c b/lib/psos/queue.c
index fce091c..c3a27ae 100644
--- a/lib/psos/queue.c
+++ b/lib/psos/queue.c
@@ -97,7 +97,7 @@ static u_long __q_create(const char *name, u_long count,
        if (name == NULL || *name == '\0')
                sprintf(q->name, "q%lu", ++anon_qids);
        else {
-               name = __psos_maybe_short_name(short_name, name);
+               name = psos_trunc_name(short_name, name);
                namecpy(q->name, name);
        }
 
@@ -215,7 +215,7 @@ static u_long __q_ident(const char *name,
        if (node)
                return ERR_NODENO;
 
-       name = __psos_maybe_short_name(short_name, name);
+       name = psos_trunc_name(short_name, name);
 
        CANCEL_DEFER(svc);
        cobj = cluster_findobj(&psos_queue_table, name);
diff --git a/lib/psos/rn.c b/lib/psos/rn.c
index 5fb1724..e665b33 100644
--- a/lib/psos/rn.c
+++ b/lib/psos/rn.c
@@ -113,7 +113,7 @@ u_long rn_create(const char *name, void *saddr, u_long 
length,
        if (name == NULL || *name == '\0')
                sprintf(rn->name, "rn%lu", ++anon_rnids);
        else {
-               name = __psos_maybe_short_name(short_name, name);
+               name = psos_trunc_name(short_name, name);
                namecpy(rn->name, name);
        }
 
@@ -200,7 +200,7 @@ u_long rn_ident(const char *name, u_long *rnid_r)
        struct service svc;
        char short_name[5];
 
-       name = __psos_maybe_short_name(short_name, name);
+       name = psos_trunc_name(short_name, name);
 
        CANCEL_DEFER(svc);
        cobj = pvcluster_findobj(&psos_rn_table, name);
diff --git a/lib/psos/sem.c b/lib/psos/sem.c
index 5535cda..54fa3c5 100644
--- a/lib/psos/sem.c
+++ b/lib/psos/sem.c
@@ -91,7 +91,7 @@ u_long sm_create(const char *name,
        if (name == NULL || *name == '\0')
                sprintf(sem->name, "sm%lu", ++anon_smids);
        else {
-               name = __psos_maybe_short_name(short_name, name);
+               name = psos_trunc_name(short_name, name);
                namecpy(sem->name, name);
        }
 
@@ -154,7 +154,7 @@ u_long sm_ident(const char *name, u_long node, u_long 
*smid_r)
        if (node)
                return ERR_NODENO;
 
-       name = __psos_maybe_short_name(short_name, name);
+       name = psos_trunc_name(short_name, name);
 
        CANCEL_DEFER(svc);
        cobj = cluster_findobj(&psos_sem_table, name);
diff --git a/lib/psos/task.c b/lib/psos/task.c
index 5142e36..4afab1b 100644
--- a/lib/psos/task.c
+++ b/lib/psos/task.c
@@ -299,7 +299,7 @@ u_long t_create(const char *name, u_long prio,
        if (name == NULL || *name == '\0')
                generate_name(task->name, name, &task_namegen);
        else {
-               name = __psos_maybe_short_name(short_name, name);
+               name = psos_trunc_name(short_name, name);
                namecpy(task->name, name);
        }
 
@@ -526,7 +526,7 @@ u_long t_ident(const char *name, u_long node, u_long *tid_r)
                if (task == NULL)
                        goto out;
        } else {
-               name = __psos_maybe_short_name(short_name, name);
+               name = psos_trunc_name(short_name, name);
                cobj = cluster_findobj(&psos_task_table, name);
                if (cobj == NULL) {
                        ret = ERR_OBJNF;


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

Reply via email to