[EMAIL PROTECTED] wrote on 14.11.2005 16:56:01:

> Hi,
>
> I'm having now my first contact with the pipe framework, an have some
> comments about it that might be of interest to the core developers:
>
> While the documentation is overall *great*, I fould it a bit lacking
> regarding the pipes. Would be good to have some examples of general usage.


You may take a look at testsuite/klatency example that uses a pipe for rt kernel-mode task ---> normal linux task communication.


>
> As far as I can tell, there is no mention of the usage of P_MSGPTR and
> P_MSGSIZE. I had to learn about them in the headers.
>
> At first sight, the rt_pipe_send call is confusing: why should I pass
> the data size since it is supposed to be embedded in the RT_PIPE_MSG
> structure?.
>
> This is what I first did:
>
> RT_PIPE_MSG *m = rt_pipe_alloc(sizeof(mystruct));
> P_MSGPTR(m) = &mystruct;
> P_MSGSIZE(m) = sizeof(mystruct)
> rt_pipe_send(&mypipe, m, sizeof(mystruct), P_NORMAL);



rt_pipe_write()
{
...
msg = rt_pipe_alloc(size);

    if (!msg)
       return -ENOMEM;

    memcpy(P_MSGPTR(msg),buf,size); <---- copying, not storing a pointer like you did

    nbytes = rt_pipe_send(pipe,msg,size,mode);
...

Actually, if you have already a buffer filled with data, you may directly use a rt_pipe_write() call.

>
> Which is obviously wrong. Please correct me if I'm wrong:

>
> P_MSGPTR and P_MSGSIZE are intended not to be used as an lvalue (is
> there a way to define these macros to generate a compile error if they
> are?).
>
> So, the correct way would be something like this (again, correct me if
> I'm wrong)::
>
> RT_PIPE_MSG *m = rt_pipe_alloc(sizeof(mystruct_t));
> mystruct_t *p = (mystruct_t *)P_MSGPTR(m);
> p->whatever1 = X;
> p->whatever2 = X;
> rt_pipe_send(&mypipe, m, sizeof(mystruct_t), P_NORMAL);
>
> If this is correct, why do I have to specify the size of mystruct_t
> *twice*. Can't it be initialized by rt_pipe_alloc ?.


It's initialized actually (*).

RT_PIPE_MSG *rt_pipe_alloc (size_t size)

{
   RT_PIPE_MSG *msg = (RT_PIPE_MSG *)xnheap_alloc(__pipe_heap,size + sizeof(RT_PIPE_MSG));

   if (msg)
       {
       inith(&msg->link);
       msg->size = size; <--- (*)
       }

   return msg;
}

Please take a look at testsuite/klatency/latency_module.c : latency() for a correct use of the rt_pipe_alloc/send() calls.


>
> Nacho.
>

---
Best regards,
Dmitry

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

Reply via email to