Commit ab983012 by Ben Clayton

Make memoryPageSize() functions thread-safe.

These used a static for caching the computation, but didn't use a static initializer. This meant there was a race between the check for zero and the assignment. Bug: b/153803432 Change-Id: Id5b91050ced0b8d4811eb32ffed24885816ade7a Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/43909Tested-by: 's avatarBen Clayton <bclayton@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Kokoro-Result: kokoro <noreply+kokoro@google.com>
parent 4d23aa35
...@@ -199,18 +199,15 @@ zx_vm_option_t permissionsToZxVmOptions(int permissions) ...@@ -199,18 +199,15 @@ zx_vm_option_t permissionsToZxVmOptions(int permissions)
size_t memoryPageSize() size_t memoryPageSize()
{ {
static int pageSize = 0; static int pageSize = [] {
if(pageSize == 0)
{
#if defined(_WIN32) #if defined(_WIN32)
SYSTEM_INFO systemInfo; SYSTEM_INFO systemInfo;
GetSystemInfo(&systemInfo); GetSystemInfo(&systemInfo);
pageSize = systemInfo.dwPageSize; return systemInfo.dwPageSize;
#else #else
pageSize = sysconf(_SC_PAGESIZE); return sysconf(_SC_PAGESIZE);
#endif #endif
} }();
return pageSize; return pageSize;
} }
......
...@@ -91,18 +91,15 @@ void *allocateRaw(size_t bytes, size_t alignment) ...@@ -91,18 +91,15 @@ void *allocateRaw(size_t bytes, size_t alignment)
size_t memoryPageSize() size_t memoryPageSize()
{ {
static int pageSize = 0; static int pageSize = [] {
if(pageSize == 0)
{
#if defined(_WIN32) #if defined(_WIN32)
SYSTEM_INFO systemInfo; SYSTEM_INFO systemInfo;
GetSystemInfo(&systemInfo); GetSystemInfo(&systemInfo);
pageSize = systemInfo.dwPageSize; return systemInfo.dwPageSize;
#else #else
pageSize = sysconf(_SC_PAGESIZE); return sysconf(_SC_PAGESIZE);
#endif #endif
} }();
return pageSize; return pageSize;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment