swr/rast: Better ExecCmd (i.e. system()) implmentation
[mesa.git] / src / gallium / drivers / swr / rasterizer / common / os.h
index ef00a255d316c8a1dec7e8924a13aac37ad25c9a..5cfd12ff72a788cd50cc56ca6f4810fdd7c7aba5 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
-* Copyright (C) 2014-2015 Intel Corporation.   All Rights Reserved.
+* Copyright (C) 2014-2017 Intel Corporation.   All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
@@ -30,6 +30,7 @@
 #if (defined(FORCE_WINDOWS) || defined(_WIN32)) && !defined(FORCE_LINUX)
 
 #define SWR_API __cdecl
+#define SWR_VISIBLE  __declspec(dllexport)
 
 #ifndef NOMINMAX
 #define NOMINMAX
@@ -91,6 +92,7 @@ static inline void AlignedFree(void* p)
 #elif defined(__APPLE__) || defined(FORCE_LINUX) || defined(__linux__) || defined(__gnu_linux__)
 
 #define SWR_API
+#define SWR_VISIBLE __attribute__((visibility("default")))
 
 #include <stdlib.h>
 #include <string.h>
@@ -171,6 +173,12 @@ void _mm256_storeu2_m128i(__m128i *hi, __m128i *lo, __m256i a)
     _mm_storeu_si128((__m128i*)lo, _mm256_castsi256_si128(a));
     _mm_storeu_si128((__m128i*)hi, _mm256_extractf128_si256(a, 0x1));
 }
+
+// gcc prior to 4.9 doesn't have _mm*_undefined_*
+#if (__GNUC__) && (GCC_VERSION < 409000)
+#define _mm_undefined_si128 _mm_setzero_si128
+#define _mm256_undefined_ps _mm256_setzero_ps
+#endif
 #endif
 
 inline
@@ -202,7 +210,7 @@ unsigned char _BitScanReverse(unsigned int *Index, unsigned int Mask)
 }
 
 inline
-void *AlignedMalloc(unsigned int size, unsigned int alignment)
+void *AlignedMalloc(size_t size, size_t alignment)
 {
     void *ret;
     if (posix_memalign(&ret, alignment, size))
@@ -212,12 +220,6 @@ void *AlignedMalloc(unsigned int size, unsigned int alignment)
     return ret;
 }
 
-inline
-unsigned char _bittest(const LONG *a, LONG b)
-{
-    return ((*(unsigned *)(a) & (1 << b)) != 0);
-}
-
 static inline
 void AlignedFree(void* p)
 {
@@ -229,10 +231,6 @@ void AlignedFree(void* p)
 #define sprintf_s sprintf
 #define strcpy_s(dst,size,src) strncpy(dst,src,size)
 #define GetCurrentProcessId getpid
-pid_t gettid(void);
-#define GetCurrentThreadId gettid
-
-#define CreateDirectory(name, pSecurity) mkdir(name, 0777)
 
 #define InterlockedCompareExchange(Dest, Exchange, Comparand) __sync_val_compare_and_swap(Dest, Comparand, Exchange)
 #define InterlockedExchangeAdd(Addend, Value) __sync_fetch_and_add(Addend, Value)
@@ -246,6 +244,7 @@ pid_t gettid(void);
 #define PRAGMA_WARNING_PUSH_DISABLE(...)
 #define PRAGMA_WARNING_POP()
 
+#define ZeroMemory(dst, size) memset(dst, 0, size)
 #else
 
 #error Unsupported OS/system.
@@ -273,4 +272,21 @@ typedef MEGABYTE    GIGABYTE[1024];
 #define ATTR_UNUSED
 #endif
 
+#define SWR_FUNC(_retType, _funcName, /* args */...)   \
+   typedef _retType (SWR_API * PFN##_funcName)(__VA_ARGS__); \
+  _retType SWR_API _funcName(__VA_ARGS__);
+
+// Defined in os.cpp
+void SWR_API SetCurrentThreadName(const char* pThreadName);
+void SWR_API CreateDirectoryPath(const std::string& path);
+
+/// Execute Command (block until finished)
+/// @returns process exit value
+int SWR_API  ExecCmd(
+    const std::string&  cmd,                        ///< (In) Command line string
+    const char*         pOptEnvStrings = nullptr,   ///< (Optional In) Environment block for new process
+    std::string*        pOptStdOut = nullptr,       ///< (Optional Out) Standard Output text
+    std::string*        pOptStdErr = nullptr,       ///< (Optional Out) Standard Error text
+    const std::string*  pOptStdIn = nullptr);       ///< (Optional In) Standard Input text
+
 #endif//__SWR_OS_H__