Make cacheAgeEntries() do a more consistent amount of work per frame

git-svn-id: https://svn.eduke32.com/eduke32@7763 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2019-07-06 16:30:51 +00:00 committed by Christoph Oelckers
parent 5cfcb96768
commit 53000d1f31

View file

@ -289,21 +289,23 @@ void cacheAllocateBlock(intptr_t *newhandle, int32_t newbytes, char *newlockptr)
void cacheAgeEntries(void) void cacheAgeEntries(void)
{ {
#ifndef DEBUG_ALLOCACHE_AS_MALLOC #ifndef DEBUG_ALLOCACHE_AS_MALLOC
static int32_t agecount; static int agecount;
if (agecount >= cacnum) if (agecount >= cacnum)
agecount = cacnum-1; agecount = cacnum-1;
native_t cnt = (cacnum>>4); int cnt = min(MAXCACHEOBJECTS >> 5, cacnum-1);
if (agecount < 0 || !cnt) while(cnt--)
return;
for (; cnt>=0; cnt--)
{ {
// If we have pointer to lock char and it's in [2 .. 199], decrease. // If we have pointer to lock char and it's in [2 .. 199], decrease.
if (cac[agecount].lock && (((*cac[agecount].lock)-2)&255) < 198) if (cac[agecount].lock)
(*cac[agecount].lock)--; {
if ((((*cac[agecount].lock)-2)&255) < 198)
(*cac[agecount].lock)--;
else if (*cac[agecount].lock >= 200)
cnt++;
}
if (--agecount < 0) if (--agecount < 0)
agecount = cacnum-1; agecount = cacnum-1;