Closed rhalbersma closed 8 years ago
I think I can eliminate a few of these issues. The 3 CriticalSection functions are #if'd out and not used. We don't need to port them. get_page_size() is only needed for Windows because of FILE_FLAG_NO_BUFFERING. For Linux it can return 4096.
I'm not sure about AllocationGranularity. If it is trying to mimic the behavior of VirtualAlloc then the granularity can be set to 4096.
Added solutions to the table for _InterlockedExchange
,__cpuid
, SYSTEM_INFO.dwPageSize
, and MEMORYSTATUS.dwAvailPhys
I have pushed a commit that implements this using std::atomic_flag
from <atomic>
.
Below a list of all Windows specific system calls. In parenthesis the likely replacement in terms of Standard C++ or Linux specific system calls. A checked box means that the replacement has been tested. Memory and File I/O can be tested on Windows under Visual Studio. The rest on Windows under MinGW or on Linux under g++.
Memory
VirtualAlloc
(std::aligned_alloc
)VirtualFree
(std::free
)File I/O
CreateFile
(std::fopen
)GetFileSize
(std::fseek
andstd::ftell
)SetFilePointer
(std::fseek
)ReadFile
(std::fread
)CloseHandle
(std::fclose
)Bit twiddling
_BitScanForward
(__builtin_ctz
)_BitScanReverse
(__builtin_clz
)_BitScanForward64
(__builtin_ctzll
)_BitScanReverse64
(__builtin_clzll
)__popcnt
(__builtin_popcount
)__popcnt64
(__builtin_popcountll
)Threading
InitializeCriticalSection
(not used)EnterCriticalSection
(not used)LeaveCriticalSection
(not used)_InterlockedExchange
(std::atomic_flag
(memberstest_and_set
andclear
),ATOMIC_FLAG_INIT
,std::memory_order_acquire
,std::memory_order_release
)System information
SYSTEM_INFO.dwPageSize
(sysconf(_SC_PAGESIZE)
)SYSTEM_INFO.dwAllocationGranularity
(same asdwPageSize
)MEMORYSTATUS.dwAvailPhys
(sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE)
)__cpuid
(__builtin_cpu_supports("popcnt")
)