Module: xenomai-rpm
Branch: queue/vfile
Commit: 1a277a62d437fc75808d315b3fbc66fd2c59d8b2
URL:    
http://git.xenomai.org/?p=xenomai-rpm.git;a=commit;h=1a277a62d437fc75808d315b3fbc66fd2c59d8b2

Author: Philippe Gerum <r...@xenomai.org>
Date:   Mon Jun  7 19:41:23 2010 +0200

psos: convert to vfile

---

 ksrc/skins/psos+/module.c |    9 +---
 ksrc/skins/psos+/queue.c  |  131 ++++++++++++++++++++++++++++----------------
 ksrc/skins/psos+/rn.c     |  122 +++++++++++++++++++++++++++---------------
 ksrc/skins/psos+/sem.c    |  117 +++++++++++++++++++++++++---------------
 4 files changed, 236 insertions(+), 143 deletions(-)

diff --git a/ksrc/skins/psos+/module.c b/ksrc/skins/psos+/module.c
index bdba58b..33ac213 100644
--- a/ksrc/skins/psos+/module.c
+++ b/ksrc/skins/psos+/module.c
@@ -52,14 +52,7 @@ xntbase_t *psos_tbase;
 
 psos_rholder_t __psos_global_rholder;
 
-#ifdef CONFIG_PROC_FS
-xnptree_t __psos_ptree = {
-
-       .dir = NULL,
-       .name = "psos",
-       .entries = 0,
-};
-#endif /* CONFIG_PROC_FS */
+DEFINE_XNPTREE(__psos_ptree, "psos");
 
 void k_fatal(u_long err_code, u_long flags)
 {
diff --git a/ksrc/skins/psos+/queue.c b/ksrc/skins/psos+/queue.c
index 703ca3b..8993b28 100644
--- a/ksrc/skins/psos+/queue.c
+++ b/ksrc/skins/psos+/queue.c
@@ -31,67 +31,102 @@ static u_long q_destroy_internal(psosqueue_t *queue);
 
 #ifdef CONFIG_PROC_FS
 
-static int msgq_read_proc(char *page,
-                         char **start,
-                         off_t off, int count, int *eof, void *data)
-{
-       psosqueue_t *queue = (psosqueue_t *)data;
-       char *p = page;
-       int len;
-       spl_t s;
-
-       p += sprintf(p, "maxnum=%lu:maxlen=%lu:mcount=%d\n",
-                    queue->maxnum, queue->maxlen, countq(&queue->inq));
+struct vfile_priv {
+       struct xnpholder *curr;
+       unsigned long maxnum;
+       unsigned long maxlen;
+       int msgcount;
+};
 
-       xnlock_get_irqsave(&nklock, s);
+struct vfile_data {
+       char name[XNOBJECT_NAME_LEN];
+};
 
-       if (xnsynch_nsleepers(&queue->synchbase) > 0) {
-               xnpholder_t *holder;
+static int vfile_rewind(struct xnvfile_snapshot_iterator *it)
+{
+       struct vfile_priv *priv = xnvfile_snapshot_iterator_priv(it);
+       psosqueue_t *queue = xnvfile_priv(it->vfile);
 
-               /* Pended queue -- dump waiters. */
+       queue = psos_h2obj_active((u_long)queue, PSOS_QUEUE_MAGIC, psosqueue_t);
+       if (queue == NULL)
+               return -EIDRM;
 
-               holder = getheadpq(xnsynch_wait_queue(&queue->synchbase));
+       priv->curr = getheadpq(xnsynch_wait_queue(&queue->synchbase));
+       priv->maxnum = queue->maxnum;
+       priv->maxlen = queue->maxlen;
+       priv->msgcount = countq(&queue->inq);
 
-               while (holder) {
-                       xnthread_t *sleeper = link2thread(holder, plink);
-                       p += sprintf(p, "+%s\n", xnthread_name(sleeper));
-                       holder =
-                           nextpq(xnsynch_wait_queue(&queue->synchbase),
-                                  holder);
-               }
-       }
+       return xnsynch_nsleepers(&queue->synchbase);
+}
 
-       xnlock_put_irqrestore(&nklock, s);
+static int vfile_next(struct xnvfile_snapshot_iterator *it, void *data)
+{
+       struct vfile_priv *priv = xnvfile_snapshot_iterator_priv(it);
+       psosqueue_t *queue = xnvfile_priv(it->vfile);
+       struct vfile_data *p = data;
+       struct xnthread *thread;
+
+       if (priv->curr == NULL)
+               return 0;       /* We are done. */
+
+       /* Fetch current waiter, advance list cursor. */
+       thread = link2thread(priv->curr, plink);
+       priv->curr = nextpq(xnsynch_wait_queue(&queue->synchbase),
+                           priv->curr);
+       /* Collect thread name to be output in ->show(). */
+       strncpy(p->name, xnthread_name(thread), sizeof(p->name));
+
+       return 1;
+}
 
-       len = (p - page) - off;
-       if (len <= off + count)
-               *eof = 1;
-       *start = page + off;
-       if (len > count)
-               len = count;
-       if (len < 0)
-               len = 0;
+static int vfile_show(struct xnvfile_snapshot_iterator *it, void *data)
+{
+       struct vfile_priv *priv = xnvfile_snapshot_iterator_priv(it);
+       struct vfile_data *p = data;
+
+       if (p == NULL) {        /* Dump header. */
+               xnvfile_printf(it, 
+                              "maxnum=%lu:maxlen=%lu:mcount=%d\n",
+                              priv->maxnum,
+                              priv->maxlen,
+                              priv->msgcount);
+               if (it->nrdata > 0)
+                       /* Queue is pended -- dump waiters */
+                       xnvfile_printf(it, 
"-------------------------------------------\n");
+       } else
+               xnvfile_printf(it, "%.*s\n",
+                              (int)sizeof(p->name), p->name);
 
-       return len;
+       return 0;
 }
 
-extern xnptree_t __psos_ptree;
-
-static xnpnode_t msgq_pnode = {
+static struct xnvfile_snapshot_ops vfile_ops = {
+       .rewind = vfile_rewind,
+       .next = vfile_next,
+       .show = vfile_show,
+};
 
-       .dir = NULL,
-       .type = "queues",
-       .entries = 0,
-       .read_proc = &msgq_read_proc,
-       .write_proc = NULL,
-       .root = &__psos_ptree,
+extern struct xnptree __psos_ptree;
+
+static struct xnpnode_file __msgq_pnode = {
+       .node = {
+               .dirname = "queues",
+               .root = &__psos_ptree,
+               .ops = &xnregistry_vfile_ops,
+       },
+       .vfile = {
+               .privsz = sizeof(struct vfile_priv),
+               .datasz = sizeof(struct vfile_data),
+               .ops = &vfile_ops,
+       },
 };
 
 #else /* !CONFIG_PROC_FS */
 
-static xnpnode_t msgq_pnode = {
-
-       .type = "queues"
+static struct xnpnode_file __msgq_pnode = {
+       .node = {
+               .dirname = "queues",
+       },
 };
 
 #endif /* !CONFIG_PROC_FS */
@@ -275,7 +310,7 @@ static u_long q_create_internal(const char *name,
        if (!*name)
                sprintf(queue->name, "anon_q%lu", msgq_ids++);
 
-       ret = xnregistry_enter(queue->name, queue, &queue->handle, &msgq_pnode);
+       ret = xnregistry_enter(queue->name, queue, &queue->handle, 
&__msgq_pnode.node);
        if (ret) {
                queue->handle = XN_NO_HANDLE;
                q_delete((u_long)queue);
diff --git a/ksrc/skins/psos+/rn.c b/ksrc/skins/psos+/rn.c
index 1eef1a4..f8d27d4 100644
--- a/ksrc/skins/psos+/rn.c
+++ b/ksrc/skins/psos+/rn.c
@@ -31,66 +31,100 @@ static int rn_destroy_internal(psosrn_t *rn);
 
 #ifdef CONFIG_PROC_FS
 
-static int rn_read_proc(char *page,
-                       char **start,
-                       off_t off, int count, int *eof, void *data)
-{
-       psosrn_t *rn = (psosrn_t *)data;
-       char *p = page;
-       int len;
-       spl_t s;
+struct vfile_priv {
+       struct xnpholder *curr;
+       unsigned long rnsize;
+       unsigned long memused;
+};
 
-       p += sprintf(p, "size=%lu:used=%lu\n",
-                    (u_long)rn->rnsize, xnheap_used_mem(&rn->heapbase));
+struct vfile_data {
+       char name[XNOBJECT_NAME_LEN];
+};
 
-       xnlock_get_irqsave(&nklock, s);
+static int vfile_rewind(struct xnvfile_snapshot_iterator *it)
+{
+       struct vfile_priv *priv = xnvfile_snapshot_iterator_priv(it);
+       psosrn_t *rn = xnvfile_priv(it->vfile);
 
-       if (xnsynch_nsleepers(&rn->synchbase) == 0) {
-               xnpholder_t *holder;
+       rn = psos_h2obj_active((u_long)rn, PSOS_RN_MAGIC, psosrn_t);
+       if (rn == NULL)
+               return -EIDRM;
 
-               /* Pended region -- dump waiters. */
+       priv->curr = getheadpq(xnsynch_wait_queue(&rn->synchbase));
+       priv->rnsize = rn->rnsize;
+       priv->memused = xnheap_used_mem(&rn->heapbase);
 
-               holder = getheadpq(xnsynch_wait_queue(&rn->synchbase));
+       return xnsynch_nsleepers(&rn->synchbase);
+}
 
-               while (holder) {
-                       xnthread_t *sleeper = link2thread(holder, plink);
-                       p += sprintf(p, "+%s\n", xnthread_name(sleeper));
-                       holder =
-                           nextpq(xnsynch_wait_queue(&rn->synchbase), holder);
-               }
-       }
+static int vfile_next(struct xnvfile_snapshot_iterator *it, void *data)
+{
+       struct vfile_priv *priv = xnvfile_snapshot_iterator_priv(it);
+       psosrn_t *rn = xnvfile_priv(it->vfile);
+       struct vfile_data *p = data;
+       struct xnthread *thread;
 
-       xnlock_put_irqrestore(&nklock, s);
+       priv->memused = xnheap_used_mem(&rn->heapbase); /* Refresh as we 
collect. */
+
+       if (priv->curr == NULL)
+               return 0;       /* We are done. */
 
-       len = (p - page) - off;
-       if (len <= off + count)
-               *eof = 1;
-       *start = page + off;
-       if (len > count)
-               len = count;
-       if (len < 0)
-               len = 0;
+       /* Fetch current waiter, advance list cursor. */
+       thread = link2thread(priv->curr, plink);
+       priv->curr = nextpq(xnsynch_wait_queue(&rn->synchbase),
+                           priv->curr);
+       /* Collect thread name to be output in ->show(). */
+       strncpy(p->name, xnthread_name(thread), sizeof(p->name));
 
-       return len;
+       return 1;
 }
 
-extern xnptree_t __psos_ptree;
+static int vfile_show(struct xnvfile_snapshot_iterator *it, void *data)
+{
+       struct vfile_priv *priv = xnvfile_snapshot_iterator_priv(it);
+       struct vfile_data *p = data;
+
+       if (p == NULL) {        /* Dump header. */
+               xnvfile_printf(it,
+                              "size=%lu:used=%lu\n",
+                              priv->rnsize, priv->memused);
+               if (it->nrdata > 0)
+                       /* Region is pended -- dump waiters */
+                       xnvfile_printf(it, 
"-------------------------------------------\n");
+       } else
+               xnvfile_printf(it, "%.*s\n",
+                              (int)sizeof(p->name), p->name);
+
+       return 0;
+}
 
-static xnpnode_t rn_pnode = {
+static struct xnvfile_snapshot_ops vfile_ops = {
+       .rewind = vfile_rewind,
+       .next = vfile_next,
+       .show = vfile_show,
+};
 
-       .dir = NULL,
-       .type = "regions",
-       .entries = 0,
-       .read_proc = &rn_read_proc,
-       .write_proc = NULL,
-       .root = &__psos_ptree,
+extern struct xnptree __psos_ptree;
+
+static struct xnpnode_file __rn_pnode = {
+       .node = {
+               .dirname = "regions",
+               .root = &__psos_ptree,
+               .ops = &xnregistry_vfile_ops,
+       },
+       .vfile = {
+               .privsz = sizeof(struct vfile_priv),
+               .datasz = sizeof(struct vfile_data),
+               .ops = &vfile_ops,
+       },
 };
 
 #else /* !CONFIG_PROC_FS */
 
-static xnpnode_t rn_pnode = {
-
-       .type = "regions"
+static struct xnpnode_file __rn_pnode = {
+       .node = {
+               .dirname = "regions",
+       },
 };
 
 #endif /* !CONFIG_PROC_FS */
@@ -229,7 +263,7 @@ u_long rn_create(const char *name,
        if (!*name)
                sprintf(rn->name, "anon_rn%lu", rn_ids++);
 
-       ret = xnregistry_enter(rn->name, rn, &rn->handle, &rn_pnode);
+       ret = xnregistry_enter(rn->name, rn, &rn->handle, &__rn_pnode.node);
        if (ret) {
                rn->handle = XN_NO_HANDLE;
                rn_delete((u_long)rn);
diff --git a/ksrc/skins/psos+/sem.c b/ksrc/skins/psos+/sem.c
index 90d0ebf..60a9d01 100644
--- a/ksrc/skins/psos+/sem.c
+++ b/ksrc/skins/psos+/sem.c
@@ -27,65 +27,96 @@ static int sm_destroy_internal(psossem_t *sem);
 
 #ifdef CONFIG_PROC_FS
 
-static int sem_read_proc(char *page,
-                        char **start,
-                        off_t off, int count, int *eof, void *data)
-{
-       psossem_t *sem = (psossem_t *)data;
-       char *p = page;
-       int len;
-       spl_t s;
+struct vfile_priv {
+       struct xnpholder *curr;
+       unsigned long value;
+};
 
-       xnlock_get_irqsave(&nklock, s);
+struct vfile_data {
+       char name[XNOBJECT_NAME_LEN];
+};
 
-       p += sprintf(p, "value=%u\n", sem->count);
+static int vfile_rewind(struct xnvfile_snapshot_iterator *it)
+{
+       struct vfile_priv *priv = xnvfile_snapshot_iterator_priv(it);
+       psossem_t *sem = xnvfile_priv(it->vfile);
 
-       if (xnsynch_nsleepers(&sem->synchbase) == 0) {
-               xnpholder_t *holder;
+       sem = psos_h2obj_active((u_long)sem, PSOS_SEM_MAGIC, psossem_t);
+       if (sem == NULL)
+               return -EIDRM;
 
-               /* Pended semaphore -- dump waiters. */
+       priv->curr = getheadpq(xnsynch_wait_queue(&sem->synchbase));
+       priv->value = sem->count;
 
-               holder = getheadpq(xnsynch_wait_queue(&sem->synchbase));
+       return xnsynch_nsleepers(&sem->synchbase);
+}
 
-               while (holder) {
-                       xnthread_t *sleeper = link2thread(holder, plink);
-                       p += sprintf(p, "+%s\n", xnthread_name(sleeper));
-                       holder =
-                           nextpq(xnsynch_wait_queue(&sem->synchbase), holder);
-               }
-       }
+static int vfile_next(struct xnvfile_snapshot_iterator *it, void *data)
+{
+       struct vfile_priv *priv = xnvfile_snapshot_iterator_priv(it);
+       psossem_t *sem = xnvfile_priv(it->vfile);
+       struct vfile_data *p = data;
+       struct xnthread *thread;
 
-       xnlock_put_irqrestore(&nklock, s);
+       priv->value = sem->count; /* Refresh as we collect. */
+
+       if (priv->curr == NULL)
+               return 0;       /* We are done. */
 
-       len = (p - page) - off;
-       if (len <= off + count)
-               *eof = 1;
-       *start = page + off;
-       if (len > count)
-               len = count;
-       if (len < 0)
-               len = 0;
+       /* Fetch current waiter, advance list cursor. */
+       thread = link2thread(priv->curr, plink);
+       priv->curr = nextpq(xnsynch_wait_queue(&sem->synchbase),
+                           priv->curr);
+       /* Collect thread name to be output in ->show(). */
+       strncpy(p->name, xnthread_name(thread), sizeof(p->name));
 
-       return len;
+       return 1;
 }
 
-extern xnptree_t __psos_ptree;
+static int vfile_show(struct xnvfile_snapshot_iterator *it, void *data)
+{
+       struct vfile_priv *priv = xnvfile_snapshot_iterator_priv(it);
+       struct vfile_data *p = data;
+
+       if (p == NULL) {        /* Dump header. */
+               xnvfile_printf(it, "value=%lu\n", priv->value);
+               if (it->nrdata > 0)
+                       /* Semaphore is pended -- dump waiters */
+                       xnvfile_printf(it, 
"-------------------------------------------\n");
+       } else
+               xnvfile_printf(it, "%.*s\n",
+                              (int)sizeof(p->name), p->name);
+
+       return 0;
+}
 
-static xnpnode_t sem_pnode = {
+static struct xnvfile_snapshot_ops vfile_ops = {
+       .rewind = vfile_rewind,
+       .next = vfile_next,
+       .show = vfile_show,
+};
 
-       .dir = NULL,
-       .type = "semaphores",
-       .entries = 0,
-       .read_proc = &sem_read_proc,
-       .write_proc = NULL,
-       .root = &__psos_ptree,
+extern struct xnptree __psos_ptree;
+
+static struct xnpnode_file __sem_pnode = {
+       .node = {
+               .dirname = "semaphores",
+               .root = &__psos_ptree,
+               .ops = &xnregistry_vfile_ops,
+       },
+       .vfile = {
+               .privsz = sizeof(struct vfile_priv),
+               .datasz = sizeof(struct vfile_data),
+               .ops = &vfile_ops,
+       },
 };
 
 #else /* !CONFIG_PROC_FS */
 
-static xnpnode_t sem_pnode = {
-
-       .type = "semaphores"
+static struct xnpnode_file __sem_pnode = {
+       .node = {
+               .dirname = "semaphores",
+       },
 };
 
 #endif /* !CONFIG_PROC_FS */
@@ -132,7 +163,7 @@ u_long sm_create(const char *name, u_long icount, u_long 
flags, u_long *smid)
        if (!*name)
                sprintf(sem->name, "anon_sem%lu", sem_ids++);
 
-       ret = xnregistry_enter(sem->name, sem, &sem->handle, &sem_pnode);
+       ret = xnregistry_enter(sem->name, sem, &sem->handle, &__sem_pnode.node);
        if (ret) {
                sem->handle = XN_NO_HANDLE;
                sm_delete((u_long)sem);


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to