[sys] Add a function to lock a region of memory

Locked memory is needed for real-time threads (which the sound mixer is
when using JACK).
This commit is contained in:
Bill Currie 2022-06-04 12:24:53 +09:00
parent 5fd9098e05
commit 0c65d294ed
2 changed files with 14 additions and 0 deletions

View file

@ -130,6 +130,7 @@ void Sys_PageIn (void *ptr, size_t size);
size_t Sys_PageSize (void); size_t Sys_PageSize (void);
void *Sys_Alloc (size_t size); void *Sys_Alloc (size_t size);
void Sys_Free (void *mem, size_t size); void Sys_Free (void *mem, size_t size);
int Sys_LockMemory (void *mem, size_t size);
int Sys_ProcessorCount (void); int Sys_ProcessorCount (void);

View file

@ -758,6 +758,19 @@ Sys_Free (void *mem, size_t size)
#endif #endif
} }
VISIBLE int
Sys_LockMemory (void *mem, size_t size)
{
size_t page_size = Sys_PageSize ();
size_t page_mask = page_size - 1;
size = (size + page_mask) & ~page_mask;
#ifdef _WIN32
return VirtualLock (mem, size) != 0;
#else
return mlock (mem, size) == 0;
#endif
}
VISIBLE int VISIBLE int
Sys_ProcessorCount (void) Sys_ProcessorCount (void)
{ {