1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2026-10-23 21:49:05 +03:00

Remove windows ifdefs

This commit is contained in:
Leonid Fedorov
2023-03-02 15:59:42 +00:00
parent 123c345b40
commit 56f2346083
328 changed files with 9 additions and 19602 deletions

View File

@@ -20,13 +20,6 @@
*
*****************************************************************************/
#ifdef _MSC_VER
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#include <process.h>
#include <psapi.h>
#endif
#include <sys/types.h>
#include <fstream>
#include <iostream>
@@ -101,21 +94,7 @@ size_t MonitorProcMem::rss() const
{
uint64_t rss;
#if defined(_MSC_VER)
HANDLE hProcess;
PROCESS_MEMORY_COUNTERS pmc;
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, fPid);
if (NULL == hProcess)
return 0;
if (GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc)))
rss = pmc.WorkingSetSize;
else
rss = 0;
CloseHandle(hProcess);
#elif defined(__FreeBSD__)
#if defined(__FreeBSD__)
ostringstream cmd;
cmd << "ps -a -o rss -p " << getpid() << " | tail +2";
FILE* cmdPipe;
@@ -158,9 +137,6 @@ void MonitorProcMem::pause_() const
while (1)
{
#ifdef _MSC_VER
Sleep(req.tv_sec * 1000);
#else
if (nanosleep(&req, &rem) != 0)
{
@@ -171,7 +147,6 @@ void MonitorProcMem::pause_() const
}
}
#endif
break;
}
}

View File

@@ -20,12 +20,8 @@
#pragma once
#include <unistd.h>
#if defined(__linux__)
#include <stdint.h>
#endif
#if !defined(_MSC_VER)
#include <sched.h>
#endif
/*
This is an attempt to wrap the differneces between Windows and Linux around atomic ops.
@@ -38,90 +34,34 @@ namespace atomicops
template <typename T>
inline T atomicInc(volatile T* mem)
{
#ifdef _MSC_VER
switch (sizeof(T))
{
case 4:
default: return InterlockedIncrement(reinterpret_cast<volatile LONG*>(mem));
case 8: return InterlockedIncrement64(reinterpret_cast<volatile LONGLONG*>(mem));
}
#else
return __sync_add_and_fetch(mem, 1);
#endif
}
// decrements, but returns the pre-decrement value
template <typename T>
inline T atomicDec(volatile T* mem)
{
#ifdef _MSC_VER
switch (sizeof(T))
{
case 4:
default: return InterlockedDecrement(reinterpret_cast<volatile LONG*>(mem)) + 1;
case 8: return InterlockedDecrement64(reinterpret_cast<volatile LONGLONG*>(mem)) + 1;
}
#else
return __sync_fetch_and_add(mem, -1);
#endif
}
// Returns the resulting value (but doesn't need to yet)
template <typename T>
inline T atomicAdd(volatile T* mem, T val)
{
#ifdef _MSC_VER
switch (sizeof(T))
{
case 4:
default: InterlockedExchangeAdd(reinterpret_cast<volatile LONG*>(mem), val); break;
case 8: InterlockedExchangeAdd64(reinterpret_cast<volatile LONGLONG*>(mem), val); break;
}
return *mem;
#else
return __sync_add_and_fetch(mem, val);
#endif
}
// Returns the resulting value
template <typename T>
inline T atomicSub(volatile T* mem, T val)
{
#ifdef _MSC_VER
switch (sizeof(T))
{
case 4:
default: InterlockedExchangeAdd(reinterpret_cast<volatile LONG*>(mem), -(static_cast<LONG>(val))); break;
case 8:
InterlockedExchangeAdd64(reinterpret_cast<volatile LONGLONG*>(mem), -(static_cast<LONGLONG>(val)));
break;
}
return *mem;
#else
return __sync_sub_and_fetch(mem, val);
#endif
}
// Implements a memory barrier
inline void atomicMb()
{
#ifdef _MSC_VER
MemoryBarrier();
#else
__sync_synchronize();
#endif
}
// Returns true iff the CAS took place, that is
@@ -134,52 +74,22 @@ inline void atomicMb()
template <typename T>
inline bool atomicCAS(volatile T* mem, T comp, T swap)
{
#ifdef _MSC_VER
switch (sizeof(T))
{
case 4:
default:
// The function returns the initial value of the mem parameter
return (InterlockedCompareExchange(reinterpret_cast<volatile LONG*>(mem), swap, comp) == comp);
case 8:
return (InterlockedCompareExchange64(reinterpret_cast<volatile LONGLONG*>(mem), swap, comp) == comp);
}
#else
// If the current value of *mem is comp, then write swap into *comp. Return true if the comparison is
// successful and swap was written.
return __sync_bool_compare_and_swap(mem, comp, swap);
#endif
}
// implements a zero out of a variable
template <typename T>
inline void atomicZero(volatile T* mem)
{
#ifdef _MSC_VER
switch (sizeof(T))
{
case 4:
default: InterlockedXor(reinterpret_cast<volatile LONG*>(mem), (static_cast<LONG>(*mem))); break;
case 8: InterlockedXor64(reinterpret_cast<volatile LONG*>(mem), (static_cast<LONG>(*mem))); break;
}
#else
__sync_xor_and_fetch(mem, *mem);
#endif
}
// Implements a scheduler yield
inline void atomicYield()
{
#ifdef _MSC_VER
SwitchToThread();
#else
sched_yield();
#endif
}
} // namespace atomicops

View File

@@ -147,15 +147,9 @@ uint32_t CGroupConfigurator::getNumCoresFromCGroup()
uint32_t CGroupConfigurator::getNumCoresFromProc()
{
#ifdef _MSC_VER
SYSTEM_INFO siSysInfo;
GetSystemInfo(&siSysInfo);
return siSysInfo.dwNumberOfProcessors;
#else
uint32_t nc = sysconf(_SC_NPROCESSORS_ONLN);
return nc;
#endif
}
uint32_t CGroupConfigurator::getNumCores()
@@ -207,23 +201,7 @@ uint64_t CGroupConfigurator::getTotalMemoryFromProc()
{
size_t memTot;
#if defined(_MSC_VER)
MEMORYSTATUSEX memStat;
memStat.dwLength = sizeof(memStat);
if (GlobalMemoryStatusEx(&memStat) == 0)
// FIXME: Assume 2GB?
memTot = 2 * 1024 * 1024;
else
{
#ifndef _WIN64
memStat.ullTotalPhys = std::min(memStat.ullTotalVirtual, memStat.ullTotalPhys);
#endif
// We now have the total phys mem in bytes
memTot = memStat.ullTotalPhys / 1024;
}
#elif defined(__FreeBSD__)
#if defined(__FreeBSD__)
string cmd("sysctl -a | awk '/realmem/ {print int(($2+1023)/1024);}'");
FILE* cmdPipe;
char input[80];
@@ -342,23 +320,7 @@ uint64_t CGroupConfigurator::getFreeMemoryFromProc()
uint64_t memTotal = 0;
uint64_t memAvailable = 0;
#if defined(_MSC_VER)
MEMORYSTATUSEX memStat;
memStat.dwLength = sizeof(memStat);
if (GlobalMemoryStatusEx(&memStat))
{
memAvailable = memStat.ullAvailPhys;
#ifndef _WIN64
uint64_t tmp = getTotalMemoryFromProc();
if (memFree > tmp)
memAvailable = tmp;
#endif
}
#elif defined(__FreeBSD__)
#if defined(__FreeBSD__)
// FreeBSD is not supported, no optimization.
memAvailable = 0;
#else

View File

@@ -25,7 +25,6 @@
#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 1)
#error "This is a very old GCC, and it's probably not going to work."
#endif
#elif defined(_MSC_VER)
#else
#error "This compiler is not known and it's probably not going to work."
#endif

View File

@@ -40,11 +40,7 @@
#include <atomic>
#include "spinlock.h"
#if defined(_MSC_VER) && defined(xxxFIXEDALLOCATOR_DLLEXPORT)
#define EXPORT __declspec(dllexport)
#else
#define EXPORT
#endif
namespace utils
{

View File

@@ -110,20 +110,11 @@ static Counts& counts()
#endif
// endianess
#ifdef _MSC_VER
#define ROBIN_HOOD_PRIVATE_DEFINITION_LITTLE_ENDIAN() 1
#define ROBIN_HOOD_PRIVATE_DEFINITION_BIG_ENDIAN() 0
#else
#define ROBIN_HOOD_PRIVATE_DEFINITION_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
#define ROBIN_HOOD_PRIVATE_DEFINITION_BIG_ENDIAN() (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
#endif
// inline
#ifdef _MSC_VER
#define ROBIN_HOOD_PRIVATE_DEFINITION_NOINLINE() __declspec(noinline)
#else
#define ROBIN_HOOD_PRIVATE_DEFINITION_NOINLINE() __attribute__((noinline))
#endif
// exceptions
#if !defined(__cpp_exceptions) && !defined(__EXCEPTIONS) && !defined(_CPPUNWIND)
@@ -134,21 +125,6 @@ static Counts& counts()
// count leading/trailing bits
#if !defined(ROBIN_HOOD_DISABLE_INTRINSICS)
#ifdef _MSC_VER
#if ROBIN_HOOD(BITNESS) == 32
#define ROBIN_HOOD_PRIVATE_DEFINITION_BITSCANFORWARD() _BitScanForward
#else
#define ROBIN_HOOD_PRIVATE_DEFINITION_BITSCANFORWARD() _BitScanForward64
#endif
#include <intrin.h>
#pragma intrinsic(ROBIN_HOOD(BITSCANFORWARD))
#define ROBIN_HOOD_COUNT_TRAILING_ZEROES(x) \
[](size_t mask) noexcept -> int \
{ \
unsigned long index; \
return ROBIN_HOOD(BITSCANFORWARD)(&index, mask) ? static_cast<int>(index) : ROBIN_HOOD(BITNESS); \
}(x)
#else
#if ROBIN_HOOD(BITNESS) == 32
#define ROBIN_HOOD_PRIVATE_DEFINITION_CTZ() __builtin_ctzl
#define ROBIN_HOOD_PRIVATE_DEFINITION_CLZ() __builtin_clzl
@@ -159,7 +135,6 @@ static Counts& counts()
#define ROBIN_HOOD_COUNT_LEADING_ZEROES(x) ((x) ? ROBIN_HOOD(CLZ)(x) : ROBIN_HOOD(BITNESS))
#define ROBIN_HOOD_COUNT_TRAILING_ZEROES(x) ((x) ? ROBIN_HOOD(CTZ)(x) : ROBIN_HOOD(BITNESS))
#endif
#endif
// fallthrough
#ifndef __has_cpp_attribute // For backwards compatibility
@@ -174,24 +149,11 @@ static Counts& counts()
#endif
// likely/unlikely
#ifdef _MSC_VER
#define ROBIN_HOOD_LIKELY(condition) condition
#define ROBIN_HOOD_UNLIKELY(condition) condition
#else
#define ROBIN_HOOD_LIKELY(condition) __builtin_expect(condition, 1)
#define ROBIN_HOOD_UNLIKELY(condition) __builtin_expect(condition, 0)
#endif
// detect if native wchar_t type is availiable in MSVC
#ifdef _MSC_VER
#ifdef _NATIVE_WCHAR_T_DEFINED
#define ROBIN_HOOD_PRIVATE_DEFINITION_HAS_NATIVE_WCHART() 1
#else
#define ROBIN_HOOD_PRIVATE_DEFINITION_HAS_NATIVE_WCHART() 0
#endif
#else
#define ROBIN_HOOD_PRIVATE_DEFINITION_HAS_NATIVE_WCHART() 1
#endif
#define ROBIN_HOOD_IS_TRIVIALLY_COPYABLE(...) std::is_trivially_copyable<__VA_ARGS__>::value

View File

@@ -142,18 +142,10 @@ class SimpleAllocator
fPool->deallocate(p, n * sizeof(T));
}
#ifdef _MSC_VER
// The MSVC STL library really needs this to return a big number...
size_type max_size() const throw()
{
return std::numeric_limits<size_type>::max();
}
#else
inline size_type max_size() const throw()
{
return fPool->max_size() / sizeof(T);
}
#endif
inline void construct(pointer ptr, const T& val)
{
new ((void*)ptr) T(val);

View File

@@ -21,10 +21,7 @@
#pragma once
#include <string>
#if defined(_MSC_VER)
#include <malloc.h>
#include <windows.h>
#elif defined(__FreeBSD__)
#if defined(__FreeBSD__)
//#include <cstdlib>
#else
#include <alloca.h>
@@ -44,16 +41,7 @@ const int MAX_UTF8_BYTES_PER_CHAR = 4;
// Params dest and max should have enough length to accomodate NULL
inline size_t idb_mbstowcs(wchar_t* dest, const char* src, size_t max)
{
#ifdef _MSC_VER
// 4th param (-1) denotes to convert till hit NULL char
// if 6th param max = 0, will return the required buffer size
size_t strwclen = MultiByteToWideChar(CP_UTF8, 0, src, -1, dest, (int)max);
// decrement the count of NULL; will become -1 on failure
return --strwclen;
#else
return mbstowcs(dest, src, max);
#endif
}
// BUG 5241
@@ -61,15 +49,7 @@ inline size_t idb_mbstowcs(wchar_t* dest, const char* src, size_t max)
// Params dest and max should have enough length to accomodate NULL
inline size_t idb_wcstombs(char* dest, const wchar_t* src, size_t max)
{
#ifdef _MSC_VER
// 4th param (-1) denotes to convert till hit NULL char
// if 6th param max = 0, will return the required buffer size
size_t strmblen = WideCharToMultiByte(CP_UTF8, 0, src, -1, dest, (int)max, NULL, NULL);
// decrement the count of NULL; will become -1 on failure
return --strmblen;
#else
return wcstombs(dest, src, max);
#endif
}
// convert UTF-8 string to wstring