Rejig includes for alloca in particular - more logic in sysutils, remove from individual files (include sysutils instead), also indent includes in sysutils for a bit more clarity

This commit is contained in:
Chris Cannam
2020-01-16 11:28:47 +00:00
parent f7d525d17f
commit e2b62687d6
3 changed files with 57 additions and 58 deletions

View File

@@ -37,9 +37,7 @@
#include "base/Profiler.h" #include "base/Profiler.h"
#ifndef _WIN32 #include "system/sysutils.h"
#include <alloca.h>
#endif
#include <cassert> #include <cassert>
#include <cmath> #include <cmath>

View File

@@ -33,10 +33,7 @@
#include "dsp/Resampler.h" #include "dsp/Resampler.h"
#include "base/Profiler.h" #include "base/Profiler.h"
#include "system/VectorOps.h" #include "system/VectorOps.h"
#include "system/sysutils.h"
#ifndef _WIN32
#include <alloca.h>
#endif
#include <cassert> #include <cassert>
#include <cmath> #include <cmath>

View File

@@ -25,48 +25,55 @@
#define _RUBBERBAND_SYSUTILS_H_ #define _RUBBERBAND_SYSUTILS_H_
#ifdef __MSVC__ #ifdef __MSVC__
#if _MSC_VER < 1800 # if _MSC_VER < 1800
#include "float_cast/float_cast.h" # include "float_cast/float_cast.h"
#endif # endif
#define R__ __restrict # define R__ __restrict
#endif #endif
#ifdef __clang__ #ifdef __clang__
#define R__ __restrict__ # define R__ __restrict__
#else #else
#ifdef __GNUC__ # ifdef __GNUC__
#define R__ __restrict__ # define R__ __restrict__
#endif # endif
#endif #endif
#ifndef R__ #ifndef R__
#define R__ # define R__
#endif #endif
#ifdef __MINGW32__ #if defined(__MSVC__)
#include <malloc.h> # include <malloc.h>
# include <process.h>
# define alloca _alloca
# define getpid _getpid
#else #else
#ifndef __MSVC__ # if defined(__MINGW32__)
#include <alloca.h> # include <malloc.h>
#endif # elif defined(__GNUC__)
#endif # ifndef alloca
# define alloca __builtin_alloca
#ifdef __MSVC__ # endif
#include <malloc.h> # elif defined(HAVE_ALLOCA_H)
#include <process.h> # include <alloca.h>
#define alloca _alloca # else
#define getpid _getpid # ifndef __USE_MISC
# define __USE_MISC
# endif
# include <stdlib.h>
# endif
#endif #endif
#if defined(__MSVC__) && _MSC_VER < 1700 #if defined(__MSVC__) && _MSC_VER < 1700
#define uint8_t unsigned __int8 # define uint8_t unsigned __int8
#define uint16_t unsigned __int16 # define uint16_t unsigned __int16
#define uint32_t unsigned __int32 # define uint32_t unsigned __int32
#elif defined(__MSVC__) #elif defined(__MSVC__)
#define ssize_t long # define ssize_t long
#include <stdint.h> # include <stdint.h>
#else #else
#include <stdint.h> # include <stdint.h>
#endif #endif
#include <math.h> #include <math.h>
@@ -82,24 +89,20 @@ enum ProcessStatus { ProcessRunning, ProcessNotRunning, UnknownProcessStatus };
extern ProcessStatus system_get_process_status(int pid); extern ProcessStatus system_get_process_status(int pid);
#ifdef _WIN32 #ifdef _WIN32
struct timeval { long tv_sec; long tv_usec; }; struct timeval { long tv_sec; long tv_usec; };
void gettimeofday(struct timeval *p, void *tz); void gettimeofday(struct timeval *p, void *tz);
#endif // _WIN32
#endif
#ifdef __MSVC__ #ifdef __MSVC__
void usleep(unsigned long); void usleep(unsigned long);
#endif // __MSVC__
#endif
inline double mod(double x, double y) { return x - (y * floor(x / y)); } inline double mod(double x, double y) { return x - (y * floor(x / y)); }
inline float modf(float x, float y) { return x - (y * float(floor(x / y))); } inline float modf(float x, float y) { return x - (y * float(floor(x / y))); }
#ifndef M_PI #ifndef M_PI
#define M_PI 3.14159265358979323846 #define M_PI 3.14159265358979323846
#endif #endif // M_PI
inline double princarg(double a) { return mod(a + M_PI, -2.0 * M_PI) + M_PI; } inline double princarg(double a) { return mod(a + M_PI, -2.0 * M_PI) + M_PI; }
inline float princargf(float a) { return modf(a + (float)M_PI, -2.f * (float)M_PI) + (float)M_PI; } inline float princargf(float a) { return modf(a + (float)M_PI, -2.f * (float)M_PI) + (float)M_PI; }
@@ -124,7 +127,7 @@ extern void system_memorybarrier();
#define DLCLOSE(a) FreeLibrary((HINSTANCE)(a)) #define DLCLOSE(a) FreeLibrary((HINSTANCE)(a))
#define DLERROR() "" #define DLERROR() ""
#else #else // !_WIN32
#include <sys/mman.h> #include <sys/mman.h>
#include <dlfcn.h> #include <dlfcn.h>
@@ -135,21 +138,21 @@ extern void system_memorybarrier();
#define MUNLOCK_SAMPLEBLOCK(a) do { if (!(a).empty()) { const float &b = *(a).begin(); MUNLOCK(&b, (a).capacity() * sizeof(float)); } } while(0); #define MUNLOCK_SAMPLEBLOCK(a) do { if (!(a).empty()) { const float &b = *(a).begin(); MUNLOCK(&b, (a).capacity() * sizeof(float)); } } while(0);
#ifdef __APPLE__ #ifdef __APPLE__
#if defined __MAC_10_12 # if defined __MAC_10_12
#define MBARRIER() __sync_synchronize() # define MBARRIER() __sync_synchronize()
#else # else
#include <libkern/OSAtomic.h> # include <libkern/OSAtomic.h>
#define MBARRIER() OSMemoryBarrier() # define MBARRIER() OSMemoryBarrier()
#endif # endif
#else
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
#define MBARRIER() __sync_synchronize()
#else #else
# if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
# define MBARRIER() __sync_synchronize()
# else
namespace RubberBand { namespace RubberBand {
extern void system_memorybarrier(); extern void system_memorybarrier();
} }
#define MBARRIER() ::RubberBand::system_memorybarrier() # define MBARRIER() ::RubberBand::system_memorybarrier()
#endif # endif
#endif #endif
#define DLOPEN(a,b) dlopen((a).toStdString().c_str(),(b)) #define DLOPEN(a,b) dlopen((a).toStdString().c_str(),(b))
@@ -157,11 +160,12 @@ extern void system_memorybarrier();
#define DLCLOSE(a) dlclose((a)) #define DLCLOSE(a) dlclose((a))
#define DLERROR() dlerror() #define DLERROR() dlerror()
#endif #endif // !_WIN32
#ifdef NO_THREADING #ifdef NO_THREADING
#undef MBARRIER # undef MBARRIER
#define MBARRIER() # define MBARRIER()
#endif #endif // NO_THREADING
#endif #endif