<div dir="ltr"><br>And I'm adding the test case, and find we haven't the SAPI for freelist yet. I must add it before adding test case, right?  By the way, is the SAPI same as the user-level API layer as Gedare mentioned before? I haven't realized it before.<br>

<div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jul 10, 2013 at 8:31 PM, Gedare Bloom <span dir="ltr"><<a href="mailto:gedare@rtems.org" target="_blank">gedare@rtems.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
You would call extend instead of calling bump, or as part of bumping.<br></blockquote><div>Thanks, I see. <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

<div class=""><div class="h5"><br>
On Wed, Jul 10, 2013 at 2:30 AM, Ashi <<a href="mailto:ashi08104@gmail.com">ashi08104@gmail.com</a>> wrote:<br>
> Thanks for all good explanation.<br>
><br>
><br>
> On Tue, Jul 9, 2013 at 11:24 PM, Sebastian Huber<br>
> <<a href="mailto:sebastian.huber@embedded-brains.de">sebastian.huber@embedded-brains.de</a>> wrote:<br>
>><br>
>> On 07/09/2013 05:29 AM, Ashi wrote:<br>
>>><br>
>>> Hi, Sebastian, thanks for your review!<br>
>>><br>
>>> 在 2013-7-7 下午9:49,"Sebastian Huber" <<a href="mailto:sebastian.huber@embedded-brains.de">sebastian.huber@embedded-brains.de</a><br>
>>> <mailto:<a href="mailto:sebastian.huber@embedded-brains.de">sebastian.huber@embedded-brains.de</a>>>写道:<br>
>>><br>
>>>  ><br>
>>>  > Hello Ashi,<br>
>>>  ><br>
>>>  ><br>
>>>  > On 06/07/13 09:17, Ashi wrote:<br>
>>>  >><br>
>>>  >> Hi all,<br>
>>>  >><br>
>>>  >> this patch adds a data structure called freelist to score, there are<br>
>>> no<br>
>>>  >> test cases yet and should be added later.<br>
>>>  ><br>
>>>  ><br>
>>>  > I would appreciate to have the test for this new stuff included in the<br>
>>> patch.<br>
>>><br>
>>><br>
>>> sure, I will update the patch with test cases.<br>
>>>  ><br>
>>>  ><br>
>>>  >><br>
>>>  >> Freelist is a structure, which contains a chain of nodes. It supports<br>
>>> 2<br>
>>>  >> operation:<br>
>>>  >> - get node from freelist<br>
>>>  >> - put node to freelist.<br>
>>>  >> And when there is no enough node in freelist, it will automatically<br>
>>>  >> increase itself's size by allocate more nodes from heap or<br>
>>> workspace(which<br>
>>>  >> is specified by user).<br>
>>>  ><br>
>>>  ><br>
>>>  > What can I do if I like to get the nodes from a magic space?<br>
>>><br>
>>><br>
>>> sorry for the unclear, you can get nodes from freelist by 'get'<br>
>>> operation. And<br>
>>> if you mean get nodes from heap or workspace, it's done by<br>
>>> _Freelist_Get_node(), which calls _Freelist_Bump() when there is no free<br>
>>> node left.<br>
>><br>
>><br>
>> Yes, the problem is that you limit your Freelist to the heap and<br>
>> workspace.  If you use a handler function (or virtual method if you like)<br>
>> then you can avoid this limitation.<br>
>><br>
>> [...]<br>
>><br>
>>>  >> +/**<br>
>>>  >> + * @typedef freelist_callout<br>
>>>  >> + */<br>
>>>  >> +typedef void (*freelist_callout)(<br>
>>>  >> +  Freelist_Control *fc,<br>
>>>  >> +  void *nodes<br>
>>>  >> +);<br>
>>>  >> +<br>
>>>  >> +/**<br>
>>>  >> + * @typedef Freelist_Control_struct<br>
>>>  >> + *<br>
>>>  >> + * This is used to manage each element.<br>
>>>  >> + */<br>
>>>  >> +struct Freelist_Control_struct {<br>
>>>  >> +  Chain_Control     Freelist;<br>
>>>  >> +  size_t            free_count;<br>
>>>  ><br>
>>>  ><br>
>>>  > Why do we need the free_count?<br>
>>><br>
>>> free_count is used to keep track how many nodes there is in freelist. And<br>
>>> if<br>
>>> free_count is 0 when you try to get node from freelist by call<br>
>>> _Freelist_Get_node(), _Freelist_Get_node() will call _Freelist_Bump() to<br>
>>> allocate more node from heap or workspace.<br>
>><br>
>><br>
>> The list knows if it is empty.  There is not need to store this<br>
>> information in two ways.<br>
>><br>
>><br>
>>>  ><br>
>>>  >> +  size_t            bump_count;<br>
>>>  >> +  size_t            node_size;<br>
>>>  ><br>
>>>  ><br>
>>>  >> +  freelist_callout  callout;<br>
>>>  >> +  bool              use_workspace;<br>
>>>  >> +};<br>
>>>  ><br>
>>>  ><br>
>>>  > I would replace this with an extend handler.<br>
>>>  ><br>
>>>  > /**<br>
>>>  >  * @brief Extends the freelist.<br>
>>>  >  *<br>
>>>  >  * @param[in] freelist The freelist control.<br>
>>>  >  *<br>
>>>  >  * @return The count of new nodes.<br>
>>>  >  */<br>
>>>  > typedef size_t ( *Freelist_Extend )( Freelist_Control *freelist );<br>
>>>  ><br>
>>>  > This is much more flexible since you only specify the interface and<br>
>>> don't<br>
>>> limit this to heap/workspace.<br>
>>>  ><br>
>>>  > You can provide a _Freelist_Extend_with_nothing() which simply returns<br>
>>> 0.<br>
>>><br>
>>> Yeah, this Freelist_Extend is very flexible, but I feel the<br>
>>> Freelist_Extend is<br>
>>> a little complex. As it shows in _Freelist_Bump(), if users provides<br>
>>> their own<br>
>>> extension function, they have to append there new nodes to freelist's<br>
>>> internal<br>
>>> chain and call their callout function on new nodes. And since<br>
>>> _Freelist_Initialize() also would call Freelist_Extend(), if we provided<br>
>>> _Freelist_Extend_with_nothing(), the initialization may fail.<br>
>><br>
>><br>
>> Since the Freelist_Extend gets the Freelist as a first argument it can set<br>
>> the extend handler to _Freelist_Extend_with_nothing() after the first<br>
>> invocation.<br>
>><br>
>> Example:<br>
>><br>
>><br>
>> /**<br>
>>  * @brief Extends the freelist.<br>
>>  *<br>
>>  * @param[in] freelist The freelist control.<br>
>>  */<br>
>> typedef void ( *Freelist_Extend )( Freelist_Control *freelist );<br>
>><br>
>> typedef struct {<br>
>>   Objects_Control obj;<br>
>>   int x;<br>
>> } my_obj;<br>
>><br>
>> void my_extend( Freelist_Control *freelist )<br>
>> {<br>
>>   size_t bump_count = freelist->bump_count;<br>
>>   size_t size = bump_count * sizeof(my_obj);<br>
>>   my_obj *objs = malloc(size);<br>
>><br>
>>   _Freelist_Set_extend_handler( freelist, _Freelist_Extend_with_nothing );<br>
>>   _Chain_Initialize(<br>
>>     _Freelist_Get_list( freelist ),<br>
>>     objs,<br>
>>     bump_count,<br>
>>     size<br>
>>   );<br>
>><br>
>> }<br>
><br>
> I'm a little confused by my_extend() function, is it only called after<br>
> calling _Freelist_Initialize() by user?<br>
>><br>
>><br>
>> [...]<br>
>><br>
>> --<br>
>> Sebastian Huber, embedded brains GmbH<br>
>><br>
>> Address : Dornierstr. 4, D-82178 Puchheim, Germany<br>
>> Phone   : +49 89 189 47 41-16<br>
>> Fax     : +49 89 189 47 41-09<br>
>> E-Mail  : <a href="mailto:sebastian.huber@embedded-brains.de">sebastian.huber@embedded-brains.de</a><br>
>> PGP     : Public key available on request.<br>
>><br>
>> Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.<br>
><br>
><br>
> Cheers,<br>
> Zhongwei<br>
><br>
</div></div></blockquote></div><br></div></div>