annotate system/System.h @ 970:bfe724787abf

Remove redundant code (from coverity scan)
author Chris Cannam
date Wed, 03 Sep 2014 11:07:12 +0100
parents 1d439494604c
children cc27f35aa75c
rev   line source
Chris@150 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@150 2
Chris@150 3 /*
Chris@150 4 Sonic Visualiser
Chris@150 5 An audio file viewer and annotation editor.
Chris@150 6 Centre for Digital Music, Queen Mary, University of London.
Chris@202 7 This file copyright 2006 Chris Cannam and QMUL.
Chris@150 8
Chris@150 9 This program is free software; you can redistribute it and/or
Chris@150 10 modify it under the terms of the GNU General Public License as
Chris@150 11 published by the Free Software Foundation; either version 2 of the
Chris@150 12 License, or (at your option) any later version. See the file
Chris@150 13 COPYING included with this distribution for more information.
Chris@150 14 */
Chris@150 15
Chris@150 16 #ifndef _SYSTEM_H_
Chris@150 17 #define _SYSTEM_H_
Chris@150 18
Chris@687 19 #include "base/Debug.h"
Chris@687 20
Chris@150 21 #ifdef _WIN32
Chris@150 22
Chris@150 23 #include <windows.h>
Chris@150 24 #include <malloc.h>
Chris@150 25 #include <process.h>
Chris@606 26 #include <math.h>
Chris@150 27
Chris@150 28 #define MLOCK(a,b) 1
Chris@150 29 #define MUNLOCK(a,b) 1
Chris@150 30 #define MUNLOCK_SAMPLEBLOCK(a) 1
Chris@368 31 #define MUNLOCKALL() 1
Chris@150 32
Chris@835 33 extern void SystemMemoryBarrier();
Chris@835 34 #define MBARRIER() SystemMemoryBarrier()
Chris@835 35
Chris@150 36 #define DLOPEN(a,b) LoadLibrary((a).toStdWString().c_str())
Chris@150 37 #define DLSYM(a,b) GetProcAddress((HINSTANCE)(a),(b))
Chris@223 38 #define DLCLOSE(a) (!FreeLibrary((HINSTANCE)(a)))
Chris@150 39 #define DLERROR() ""
Chris@150 40
Chris@150 41 #define PLUGIN_GLOB "*.dll"
Chris@223 42 #define PATH_SEPARATOR ';'
Chris@186 43
Chris@219 44 // The default Vamp plugin path is obtained from a function in the
Chris@219 45 // Vamp SDK (Vamp::PluginHostAdapter::getPluginPath).
Chris@186 46
Chris@219 47 // At the time of writing, at least, the vast majority of LADSPA
Chris@219 48 // plugins on Windows hosts will have been put there for use in
Chris@219 49 // Audacity. It's a bit of a shame that Audacity uses its own Program
Chris@219 50 // Files directory for plugins that any host may want to use... maybe
Chris@219 51 // they were just following the example of VSTs, which are usually
Chris@219 52 // found in Steinberg's Program Files directory. Anyway, we can
Chris@219 53 // greatly increase our chances of picking up some LADSPA plugins by
Chris@219 54 // default if we include the Audacity plugin location as well as an
Chris@219 55 // (imho) more sensible place.
Chris@219 56
Chris@223 57 #define DEFAULT_LADSPA_PATH "%ProgramFiles%\\LADSPA Plugins;%ProgramFiles%\\Audacity\\Plug-Ins"
Chris@186 58 #define DEFAULT_DSSI_PATH "%ProgramFiles%\\DSSI Plugins"
Chris@150 59
Chris@150 60 #define getpid _getpid
Chris@150 61
Chris@150 62 extern "C" {
Chris@765 63 /* usleep is now in mingw
Chris@150 64 void usleep(unsigned long usec);
Chris@765 65 */
Chris@501 66 int gettimeofday(struct timeval *p, void *tz);
Chris@150 67 }
Chris@150 68
Chris@765 69 #define ISNAN std::isnan
Chris@765 70 #define ISINF std::isinf
Chris@606 71
Chris@150 72 #else
Chris@150 73
Chris@150 74 #include <sys/mman.h>
Chris@150 75 #include <dlfcn.h>
Chris@602 76 #include <stdio.h> // for perror
Chris@606 77 #include <cmath>
Chris@150 78
Chris@150 79 #define MLOCK(a,b) ::mlock((a),(b))
Chris@150 80 #define MUNLOCK(a,b) (::munlock((a),(b)) ? (::perror("munlock failed"), 0) : 0)
Chris@150 81 #define MUNLOCK_SAMPLEBLOCK(a) do { if (!(a).empty()) { const float &b = *(a).begin(); MUNLOCK(&b, (a).capacity() * sizeof(float)); } } while(0);
Chris@232 82 //#define MLOCK(a,b) 1
Chris@232 83 //#define MUNLOCK(a,b) 1
Chris@232 84 //#define MUNLOCK_SAMPLEBLOCK(a) 1
Chris@150 85
Chris@150 86 #define DLOPEN(a,b) dlopen((a).toStdString().c_str(),(b))
Chris@150 87 #define DLSYM(a,b) dlsym((a),(b))
Chris@150 88 #define DLCLOSE(a) dlclose((a))
Chris@150 89 #define DLERROR() dlerror()
Chris@150 90
Chris@606 91 #include <cmath>
Chris@606 92 #define ISNAN std::isnan
Chris@606 93 #define ISINF std::isinf
Chris@606 94
Chris@150 95 #ifdef __APPLE__
Chris@150 96
Chris@255 97 #define PLUGIN_GLOB "*.dylib *.so"
Chris@223 98 #define PATH_SEPARATOR ':'
Chris@186 99
Chris@186 100 #define DEFAULT_LADSPA_PATH "$HOME/Library/Audio/Plug-Ins/LADSPA:/Library/Audio/Plug-Ins/LADSPA"
Chris@186 101 #define DEFAULT_DSSI_PATH "$HOME/Library/Audio/Plug-Ins/DSSI:/Library/Audio/Plug-Ins/DSSI"
Chris@150 102
Chris@368 103 #define MUNLOCKALL() 1
Chris@368 104
Chris@835 105 #include <libkern/OSAtomic.h>
Chris@835 106 #define MBARRIER() OSMemoryBarrier()
Chris@835 107
Chris@150 108 #else
Chris@150 109
Chris@606 110 #ifdef sun
Chris@606 111 #undef MLOCK
Chris@606 112 #undef MUNLOCK
Chris@606 113 #define MLOCK(a,b) ::mlock((char *)a,b)
Chris@606 114 #define MUNLOCK(a,b) ::munlock((char *)a,b)
Chris@606 115 #ifdef __SUNPRO_CC
Chris@606 116 #undef ISNAN
Chris@606 117 #undef ISINF
Chris@606 118 #define ISNAN(x) ((x)!=(x))
Chris@606 119 #define ISINF(x) 0
Chris@606 120 #endif
Chris@606 121 #endif
Chris@606 122
Chris@150 123 #define PLUGIN_GLOB "*.so"
Chris@223 124 #define PATH_SEPARATOR ':'
Chris@186 125
Chris@186 126 #define DEFAULT_LADSPA_PATH "$HOME/ladspa:$HOME/.ladspa:/usr/local/lib/ladspa:/usr/lib/ladspa"
Chris@186 127 #define DEFAULT_DSSI_PATH "$HOME/dssi:$HOME/.dssi:/usr/local/lib/dssi:/usr/lib/dssi"
Chris@150 128
Chris@368 129 #define MUNLOCKALL() ::munlockall()
Chris@368 130
Chris@835 131 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
Chris@835 132 #define MBARRIER() __sync_synchronize()
Chris@835 133 #else
Chris@835 134 extern void SystemMemoryBarrier();
Chris@835 135 #define MBARRIER() SystemMemoryBarrier()
Chris@835 136 #endif
Chris@835 137
Chris@835 138 #endif /* ! __APPLE__ */
Chris@150 139
Chris@150 140 #endif /* ! _WIN32 */
Chris@150 141
Chris@150 142 enum ProcessStatus { ProcessRunning, ProcessNotRunning, UnknownProcessStatus };
Chris@150 143 extern ProcessStatus GetProcessStatus(int pid);
Chris@150 144
Chris@168 145 // Return a vague approximation to the number of free megabytes of real memory.
Chris@168 146 // Return -1 if unknown.
Chris@170 147 extern void GetRealMemoryMBAvailable(int &available, int &total);
Chris@168 148
Chris@168 149 // Return a vague approximation to the number of free megabytes of disc space
Chris@168 150 // on the partition containing the given path. Return -1 if unknown.
Chris@168 151 extern int GetDiscSpaceMBAvailable(const char *path);
Chris@168 152
Chris@303 153 extern void StoreStartupLocale();
Chris@303 154 extern void RestoreStartupLocale();
Chris@303 155
Chris@150 156 #include <cmath>
Chris@150 157
Chris@150 158 extern double mod(double x, double y);
Chris@150 159 extern float modf(float x, float y);
Chris@150 160
Chris@150 161 extern double princarg(double a);
Chris@150 162 extern float princargf(float a);
Chris@150 163
Chris@573 164 #ifdef USE_POW_NO_F
Chris@573 165 #define powf pow
Chris@573 166 #endif
Chris@573 167
Chris@150 168 #endif /* ! _SYSTEM_H_ */
Chris@150 169
Chris@150 170