extensions
Steven Massey 4 years ago
parent d7bda56855
commit 8bbc35b25c

@ -82,17 +82,19 @@ int main (int i_argc, const char * i_argv [])
u32 numActive = 0;
for (u32 i = 0; i < 5000000; ++i)
for (u32 i = 0; i < 2000000; ++i)
{
u32 index = rand () % c_numPages; // printf ("%5u ", index);
if (pages [index] == NULL)
{
// printf ("acq\n");
pages [index] = AcquireCodePage (& runtime);
++numActive;
}
else
{
// printf ("rel\n");
ReleaseCodePage (& runtime, pages [index]);
pages [index] = NULL;
--numActive;
@ -102,6 +104,19 @@ int main (int i_argc, const char * i_argv [])
}
printf ("num pages: %d\n", runtime.numCodePages);
for (u32 i = 0; i < c_numPages; ++i)
{
if (pages [i])
{
ReleaseCodePage (& runtime, pages [i]);
pages [i] = NULL;
--numActive; expect (runtime.numActiveCodePages == numActive);
}
}
Runtime_Release (& runtime);
Environment_Release (& env);
}
return 0;

@ -178,8 +178,7 @@ void Environment_Release (IM3Environment i_environment)
IM3FuncType next = ftype->next;
m3Free (ftype);
ftype = next;
} m3log (runtime, "freeing %d pages from environment",
CountCodePages (i_environment->pagesReleased));
} m3log (runtime, "freeing %d pages from environment", CountCodePages (i_environment->pagesReleased));
FreeCodePages (& i_environment->pagesReleased);
}
@ -228,10 +227,8 @@ IM3CodePage RemoveCodePageOfCapacity (M3CodePage ** io_list, u32 i_minimumLineCo
while (page)
{
if (page->info.numLines >= i_minimumLineCount)
if (NumFreeLines (page) >= i_minimumLineCount)
{ d_m3Assert (page->info.usageCount == 0);
page->info.lineIndex = 0; // reset the page
IM3CodePage next = page->info.next;
if (prev)
prev->info.next = next; // mid-list
@ -257,7 +254,18 @@ IM3CodePage Environment_AcquireCodePage (IM3Environment i_environment, u32 i_mi
void Environment_ReleaseCodePages (IM3Environment i_environment, IM3CodePage i_codePageList)
{
IM3CodePage end = GetCodePageEnd (i_codePageList);
IM3CodePage end = i_codePageList;
while (end)
{
end->info.lineIndex = 0; // reset page
IM3CodePage next = end->info.next;
if (not next)
break;
end = next;
}
if (end)
{
@ -860,8 +868,6 @@ void ReleaseCodePageNoTrack (IM3Runtime i_runtime, IM3CodePage i_codePage)
{
if (i_codePage)
{
// IM3Environment env = i_runtime->environment;
IM3Runtime env = i_runtime;
IM3CodePage * list;
bool pageFull = (NumFreeLines (i_codePage) < d_m3CodePageFreeLinesThreshold);
@ -875,40 +881,21 @@ void ReleaseCodePageNoTrack (IM3Runtime i_runtime, IM3CodePage i_codePage)
}
IM3CodePage AcquireCodePageWithCapacityR (IM3Runtime i_runtime, u32 i_lineCount)
IM3CodePage AcquireCodePageWithCapacity (IM3Runtime i_runtime, u32 i_minLineCount)
{
IM3CodePage page;
if (i_runtime->pagesOpen)
{
page = PopCodePage (& i_runtime->pagesOpen);
if (NumFreeLines (page) < i_lineCount)
{
IM3CodePage tryAnotherPage = AcquireCodePageWithCapacityR (i_runtime, i_lineCount);
ReleaseCodePageNoTrack (i_runtime, page);
page = tryAnotherPage;
}
}
else
IM3CodePage page = RemoveCodePageOfCapacity (& i_runtime->pagesOpen, i_minLineCount);
if (not page)
{
page = Environment_AcquireCodePage (i_runtime->environment, i_lineCount);
page = Environment_AcquireCodePage (i_runtime->environment, i_minLineCount);
if (not page)
page = NewCodePage (i_lineCount);
if (page)
i_runtime->numCodePages++;
{
page = NewCodePage (i_minLineCount);
if (page)
i_runtime->numCodePages++;
}
}
return page;
}
IM3CodePage AcquireCodePageWithCapacity (IM3Runtime i_runtime, u32 i_lineCount)
{
IM3CodePage page = AcquireCodePageWithCapacityR (i_runtime, i_lineCount);
if (page)
{ m3log (emit, "acquire page: %d", page->info.sequence);

@ -203,6 +203,8 @@ static const u32 c_m3NumTypesPerPage = 8;
typedef struct M3Environment
{
// struct M3Runtime * runtimes;
IM3FuncType funcTypes; // linked list
M3CodePage * pagesReleased;

@ -513,7 +513,7 @@ M3Result ParseModuleSection (M3Module * o_module, u8 i_sectionType, bytes_t i_
}
else
{
m3log (parse, "<skipped (id: %d)>", (u32) i_sectionType);
m3log (parse, " skipped section type: %d", (u32) i_sectionType);
}
return result;

Loading…
Cancel
Save