Hi Roy,

Thanks, this definitely helps a lot and would be even more helpful if you
could further help me with some minor questions.

What is a pool here? What does pool.get() and pool.put() mean? My guess is
pool is like a heap; get() and put() is similar to new and delete, am I
right?

Why do we need newMsg from MessagePool? It seems we just return an all zero
newMsg if everything goes well.


-Xiaohui

On Fri, May 8, 2009 at 2:57 AM, Roy Shea <[email protected]> wrote:

> Howdy,
>
> > ...in component CtpForwardingEngineP, there are two pools besides
> > SendQueue, namely MessagePool and QEntryPool.
>
> I would rephrase this as "there are two pools and one queue", since the
> SendQueue really is a queue.
>
> ----
> interface Queue<fe_queue_entry_t*> as SendQueue;
> interface Pool<fe_queue_entry_t> as QEntryPool;
> interface Pool<message_t> as MessagePool;
> ----
>
> > Could anyone give me some hint on what is the relation between these
> > three?
>
> Here is my reading of the "forward" function which uses all three of
> these.  A message comes into the system to be forwarded by CTP.  We grab
> memory for a fe_queue_entry_t and a message_t from the QEntryPool and
> MessagePool respectively:
>
> ----
> qe = call QEntryPool.get();
> if (qe == NULL) {
>    call CollectionDebug.logEvent(NET_C_FE_GET_MSGPOOL_ERR);
>    return m;
> }
>
> newMsg = call MessagePool.get();
> if (newMsg == NULL) {
>    call CollectionDebug.logEvent(NET_C_FE_GET_QEPOOL_ERR);
>    return m;
> }
> ----
>
> Quick side note.  Shouldn't we return qu to the QEntryPool if nemMsg is
> null?  I admit that it should not happen...  But a resource leak is
> still a resource leak.
>
> That aside aside, once we have resources in hand the incoming message is
> stuffed into the fe_queue_entry_t and stored on the SendQueue:
>
> ----
> memset(m->metadata, 0, sizeof(message_metadata_t));
>
>
> qe->msg = m;
> qe->client = 0xff;
> qe->retries = MAX_RETRIES;
>
> if (call SendQueue.enqueue(qe) == SUCCESS) {
> ----
>
> and if all goes well then a shiny new message is returned to the caller:
>
> ----
> memset(newMsg, 0, sizeof(message_t));  // Slightly out of order
>
> // Skipping some code
>
> return newMsg; // Assuming SendQueue.enqueue(qe) == SUCCESS
> ----
>
> Hope that helps!
> -Roy
> _______________________________________________
> Tinyos-help mailing list
> [email protected]
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to