<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>MQX Software SolutionsのトピックRe: Why are _mem_test and _mem_free changing the same pointers in the memory pool?</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/Why-are-mem-test-and-mem-free-changing-the-same-pointers-in-the/m-p/305464#M9813</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Don Marquardt,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Actually I am a little bit confused why you said "&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;That means that mem_test starts over at the beginning of the pool and potentially never finishes.&lt;/SPAN&gt;" I agree _mem_test() starts from the beginning of the checking pointers when it is invoked after some task invokes _mem_free()&amp;nbsp; , but&amp;nbsp; during _mem_test() running, the context would not switch to other tasks , so _mem_alloc and _mem_free would not be possibly invoked during that period until _mem_test() is finished or task switching API is called explicitly in _mem_test() , so I don't understand in which case _mem_test() would never finish. Would you please help to clarify? Thanks for your patience!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have a nice weekend!!&lt;/P&gt;&lt;P&gt;B.R&lt;/P&gt;&lt;P&gt;Kan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 18 Apr 2014 09:36:54 GMT</pubDate>
    <dc:creator>Kan_Li</dc:creator>
    <dc:date>2014-04-18T09:36:54Z</dc:date>
    <item>
      <title>Why are _mem_test and _mem_free changing the same pointers in the memory pool?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Why-are-mem-test-and-mem-free-changing-the-same-pointers-in-the/m-p/305461#M9810</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;From _mem_free (this is in all versions of MQX I have access to ...)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;/* Reset the _mem_test pointers */&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;mem_pool_ptr-&amp;gt;POOL_PHYSICAL_CHECK_BLOCK = (STOREBLOCK_STRUCT_PTR) mem_pool_ptr-&amp;gt;POOL_PTR;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;mem_pool_ptr-&amp;gt;POOL_FREE_CHECK_BLOCK = mem_pool_ptr-&amp;gt;POOL_FREE_LIST_PTR;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;_INT_ENABLE();&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And from _mem_test&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;next_block_ptr = NEXT_PHYS(mem_pool_ptr-&amp;gt;POOL_PHYSICAL_CHECK_BLOCK);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;if (next_block_ptr-&amp;gt;PREVBLOCK != mem_pool_ptr-&amp;gt;POOL_PHYSICAL_CHECK_BLOCK){&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;mem_pool_ptr-&amp;gt;POOL_BLOCK_IN_ERROR = next_block_ptr;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;_int_enable();&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;result = MQX_CORRUPT_STORAGE_POOL;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;break;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;} /* Endif */&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;mem_pool_ptr-&amp;gt;POOL_PHYSICAL_CHECK_BLOCK = next_block_ptr;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problem, if I understand correctly, is that if _mem_free gets called from another task while _mem_test is running, the "POOL_PHYSICAL_CHECK_BLOCK" gets reset to the beginning of the pool and the _mem_test starts over again.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The MQX Manual states...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The function can be called by only one task at a time because it keeps state-inprogress&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;variables that MQX controls. This mechanism lets other tasks allocate&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;and free memory while _mem_test() runs.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the case of my system this means that my call to _mem_test never completes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does anyone have a solution that does not disable interrupts for the duration of the _mem_test?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Mar 2014 20:36:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Why-are-mem-test-and-mem-free-changing-the-same-pointers-in-the/m-p/305461#M9810</guid>
      <dc:creator>donmarquardt</dc:creator>
      <dc:date>2014-03-27T20:36:49Z</dc:date>
    </item>
    <item>
      <title>Re: Why are _mem_test and _mem_free changing the same pointers in the memory pool?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Why-are-mem-test-and-mem-free-changing-the-same-pointers-in-the/m-p/305462#M9811</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Don Marquardt,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Actually in _mem_free() and _mem_test(), the interrupt is disabled before the code starts to operate on the pointers, so when one task is running the _mem_test() while another invokes _mem_free(), the task switch would not happen when interrupt is disbaled, so I think you needn't worry about the case that _mem_free gets called from another task while _mem_test is running.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope that helps,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Kan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Apr 2014 01:31:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Why-are-mem-test-and-mem-free-changing-the-same-pointers-in-the/m-p/305462#M9811</guid>
      <dc:creator>Kan_Li</dc:creator>
      <dc:date>2014-04-11T01:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: Why are _mem_test and _mem_free changing the same pointers in the memory pool?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Why-are-mem-test-and-mem-free-changing-the-same-pointers-in-the/m-p/305463#M9812</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I understand that. The problem is that although the pointers are being used "safely", if your system is doing a lot of mem allocs and frees, the pointer gets reset to the beginning of the free pool each time free is called.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That means that mem_test starts over at the beginning of the pool and potentially never finishes.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Apr 2014 17:20:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Why-are-mem-test-and-mem-free-changing-the-same-pointers-in-the/m-p/305463#M9812</guid>
      <dc:creator>donmarquardt</dc:creator>
      <dc:date>2014-04-17T17:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: Why are _mem_test and _mem_free changing the same pointers in the memory pool?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Why-are-mem-test-and-mem-free-changing-the-same-pointers-in-the/m-p/305464#M9813</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Don Marquardt,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Actually I am a little bit confused why you said "&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;That means that mem_test starts over at the beginning of the pool and potentially never finishes.&lt;/SPAN&gt;" I agree _mem_test() starts from the beginning of the checking pointers when it is invoked after some task invokes _mem_free()&amp;nbsp; , but&amp;nbsp; during _mem_test() running, the context would not switch to other tasks , so _mem_alloc and _mem_free would not be possibly invoked during that period until _mem_test() is finished or task switching API is called explicitly in _mem_test() , so I don't understand in which case _mem_test() would never finish. Would you please help to clarify? Thanks for your patience!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have a nice weekend!!&lt;/P&gt;&lt;P&gt;B.R&lt;/P&gt;&lt;P&gt;Kan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Apr 2014 09:36:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Why-are-mem-test-and-mem-free-changing-the-same-pointers-in-the/m-p/305464#M9813</guid>
      <dc:creator>Kan_Li</dc:creator>
      <dc:date>2014-04-18T09:36:54Z</dc:date>
    </item>
    <item>
      <title>Re: Why are _mem_test and _mem_free changing the same pointers in the memory pool?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Why-are-mem-test-and-mem-free-changing-the-same-pointers-in-the/m-p/305465#M9814</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The issue is that both mem_test and mem_free reset the pointer(POOL_PHYSICAL_CHECK_BLOCK) used by mem_test.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;at approx line 93 in mem_tesp.c...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;mem_pool_ptr-&amp;gt;POOL_PHYSICAL_CHECK_BLOCK = next_block_ptr;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;_int_enable();&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; } /* Endwhile */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and in mem_free.c at approx line 243&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; /* Reset the _mem_test pointers */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; mem_pool_ptr-&amp;gt;POOL_PHYSICAL_CHECK_BLOCK = &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (STOREBLOCK_STRUCT_PTR)mem_pool_ptr-&amp;gt;POOL_PTR;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So what happens is that mem_test will potentially start over again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Apr 2014 17:03:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Why-are-mem-test-and-mem-free-changing-the-same-pointers-in-the/m-p/305465#M9814</guid>
      <dc:creator>donmarquardt</dc:creator>
      <dc:date>2014-04-24T17:03:48Z</dc:date>
    </item>
  </channel>
</rss>

