Module: xenomai-forge
Branch: next
Commit: 5fe70309ec24d672ec57aae29bd3eb77c2a2668f
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=5fe70309ec24d672ec57aae29bd3eb77c2a2668f

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue May 27 07:30:44 2014 +0200

vxworks/registry: convert to fsobstack

---

 lib/vxworks/taskLib.c |   67 +++++++++++++++++++++++++++++--------------------
 lib/vxworks/taskLib.h |    5 ----
 2 files changed, 40 insertions(+), 32 deletions(-)

diff --git a/lib/vxworks/taskLib.c b/lib/vxworks/taskLib.c
index cdb81b2..41001cf 100644
--- a/lib/vxworks/taskLib.c
+++ b/lib/vxworks/taskLib.c
@@ -34,6 +34,7 @@
 #include "copperplate/syncobj.h"
 #include "copperplate/cluster.h"
 #include "copperplate/internal.h"
+#include "copperplate/registry-obstack.h"
 #include "vxworks/errnoLib.h"
 
 union wind_wait_union {
@@ -165,48 +166,60 @@ static void task_finalizer(struct threadobj *thobj)
 
 #ifdef CONFIG_XENO_REGISTRY
 
-static inline char *task_decode_status(struct wind_task *task, char *buf)
+static void task_decode_status(struct fsobstack *o, struct wind_task *task)
 {
-       int status;
+       int status = threadobj_get_status(&task->thobj);
 
-       *buf = '\0';
        if (threadobj_get_lockdepth(&task->thobj) > 0)
-               strcat(buf, "+sched_lock");
-       status = threadobj_get_status(&task->thobj);
+               fsobstack_grow_string(o, " LOCK");
+
        if (threadobj_get_policy(&task->thobj) == SCHED_RR)
-               strcat(buf, "+sched_rr");
+               fsobstack_grow_string(o, " RR");
+
        if (status & __THREAD_S_SUSPENDED)
-               strcat(buf, "+suspended");
+               fsobstack_grow_string(o, " SUSPEND");
+
        if (status & (__THREAD_S_WAIT|__THREAD_S_TIMEDWAIT))
-               strcat(buf, "+pending");
+               fsobstack_grow_string(o, " PEND");
        else if (status & __THREAD_S_DELAYED)
-               strcat(buf, "+delayed");
+               fsobstack_grow_string(o, " DELAY");
        else
-               strcat(buf, "+ready");
-
-       return buf + 1;
+               fsobstack_grow_string(o, " READY");
 }
 
-static ssize_t task_registry_read(struct fsobj *fsobj,
-                                 char *buf, size_t size, off_t offset,
-                                 void *priv)
+static int task_registry_open(struct fsobj *fsobj, void *priv)
 {
+       struct fsobstack *o = priv;
        struct wind_task *task;
-       char sbuf[64];
-       size_t len;
+       int ret;
 
        task = container_of(fsobj, struct wind_task, fsobj);
-       len =  sprintf(buf,       "name       = %s\n", task->name);
-       len += sprintf(buf + len, "errno      = %d\n", 
threadobj_get_errno(&task->thobj));
-       len += sprintf(buf + len, "status     = %s\n", task_decode_status(task, 
sbuf));
-       len += sprintf(buf + len, "priority   = %d\n", 
wind_task_get_priority(task));
-       len += sprintf(buf + len, "lock_depth = %d\n", 
threadobj_get_lockdepth(&task->thobj));
+       ret = threadobj_lock(&task->thobj);
+       if (ret)
+               return -EIO;
+
+       fsobstack_init(o);
+
+       fsobstack_grow_format(o, "errno      = %d\n",
+                             threadobj_get_errno(&task->thobj));
+       fsobstack_grow_string(o, "status     =");
+       task_decode_status(o, task);
+       fsobstack_grow_format(o, "\npriority   = %d\n",
+                             wind_task_get_priority(task));
+       fsobstack_grow_format(o, "lock_depth = %d\n",
+                             threadobj_get_lockdepth(&task->thobj));
+
+       threadobj_unlock(&task->thobj);
+
+       fsobstack_finish(o);
 
-       return (ssize_t)len;
+       return 0;
 }
 
 static struct registry_operations registry_ops = {
-       .read   = task_registry_read
+       .open           = task_registry_open,
+       .release        = fsobj_obstack_release,
+       .read           = fsobj_obstack_read
 };
 
 #else
@@ -239,8 +252,8 @@ static void *task_trampoline(void *arg)
        ret = __bt(registry_add_file(&task->fsobj, O_RDONLY,
                                     "/vxworks/tasks/%s", task->name));
        if (ret)
-               warning("failed to export task %s to registry",
-                       task->name);
+               warning("failed to export task %s to registry, %s",
+                       task->name, symerror(ret));
 
        /* Wait for someone to run taskActivate() upon us. */
        threadobj_wait_start();
@@ -374,7 +387,7 @@ static STATUS __taskInit(struct wind_task *task,
                return ERROR;
        }
 
-       registry_init_file(&task->fsobj, &registry_ops, 0);
+       registry_init_file_obstack(&task->fsobj, &registry_ops);
 
        cta.policy = idata.policy;
        cta.param_ex.sched_priority = cprio;
diff --git a/lib/vxworks/taskLib.h b/lib/vxworks/taskLib.h
index fa458c2..1d75e12 100644
--- a/lib/vxworks/taskLib.h
+++ b/lib/vxworks/taskLib.h
@@ -25,7 +25,6 @@
 #include <vxworks/taskLib.h>
 
 struct wind_task_args {
-
        FUNCPTR entry;
        long arg0;
        long arg1;
@@ -40,15 +39,11 @@ struct wind_task_args {
 };
 
 struct wind_task {
-
        pthread_mutex_t safelock;
-
        struct WIND_TCB *tcb;
        struct WIND_TCB priv_tcb;
-
        char name[XNOBJECT_NAME_LEN];
        struct wind_task_args args;
-
        struct threadobj thobj;
        struct fsobj fsobj;
        struct clusterobj cobj;


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

Reply via email to