annotate system/System.h @ 1752:6d09d68165a4 by-id

Further review of ById: make IDs only available when adding a model to the ById store, not by querying the item directly. This means any id encountered in the wild must have been added to the store at some point (even if later released), which simplifies reasoning about lifecycles
author Chris Cannam
date Fri, 05 Jul 2019 15:28:07 +0100
parents bd1a2cacd1e7
children c5ee0746bdef
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@1475 7 This file copyright 2006-2018 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@1475 16 #ifndef SV_SYSTEM_H
Chris@1475 17 #define SV_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@1216 62 #if defined(_MSC_VER)
Chris@1216 63 #include <BaseTsd.h>
Chris@1216 64 typedef SSIZE_T ssize_t;
Chris@1216 65 #endif
Chris@1216 66
Chris@1232 67 #ifdef _MSC_VER
Chris@150 68 extern "C" {
Chris@150 69 void usleep(unsigned long usec);
Chris@1232 70 }
Chris@1232 71 #else
Chris@1232 72 #include <unistd.h>
Chris@1218 73 #endif
Chris@1218 74
Chris@1232 75 extern "C" {
Chris@501 76 int gettimeofday(struct timeval *p, void *tz);
Chris@150 77 }
Chris@150 78
Chris@765 79 #define ISNAN std::isnan
Chris@765 80 #define ISINF std::isinf
Chris@606 81
Chris@150 82 #else
Chris@150 83
Chris@150 84 #include <sys/mman.h>
Chris@150 85 #include <dlfcn.h>
Chris@602 86 #include <stdio.h> // for perror
Chris@606 87 #include <cmath>
Chris@1219 88 #include <unistd.h> // sleep + usleep primarily
Chris@150 89
Chris@150 90 #define MLOCK(a,b) ::mlock((a),(b))
Chris@150 91 #define MUNLOCK(a,b) (::munlock((a),(b)) ? (::perror("munlock failed"), 0) : 0)
Chris@150 92 #define MUNLOCK_SAMPLEBLOCK(a) do { if (!(a).empty()) { const float &b = *(a).begin(); MUNLOCK(&b, (a).capacity() * sizeof(float)); } } while(0);
Chris@232 93 //#define MLOCK(a,b) 1
Chris@232 94 //#define MUNLOCK(a,b) 1
Chris@232 95 //#define MUNLOCK_SAMPLEBLOCK(a) 1
Chris@150 96
Chris@150 97 #define DLOPEN(a,b) dlopen((a).toStdString().c_str(),(b))
Chris@150 98 #define DLSYM(a,b) dlsym((a),(b))
Chris@150 99 #define DLCLOSE(a) dlclose((a))
Chris@150 100 #define DLERROR() dlerror()
Chris@150 101
Chris@606 102 #include <cmath>
Chris@606 103 #define ISNAN std::isnan
Chris@606 104 #define ISINF std::isinf
Chris@606 105
Chris@150 106 #ifdef __APPLE__
Chris@150 107
Chris@255 108 #define PLUGIN_GLOB "*.dylib *.so"
Chris@223 109 #define PATH_SEPARATOR ':'
Chris@186 110
Chris@186 111 #define DEFAULT_LADSPA_PATH "$HOME/Library/Audio/Plug-Ins/LADSPA:/Library/Audio/Plug-Ins/LADSPA"
Chris@186 112 #define DEFAULT_DSSI_PATH "$HOME/Library/Audio/Plug-Ins/DSSI:/Library/Audio/Plug-Ins/DSSI"
Chris@150 113
Chris@368 114 #define MUNLOCKALL() 1
Chris@368 115
Chris@835 116 #include <libkern/OSAtomic.h>
Chris@835 117 #define MBARRIER() OSMemoryBarrier()
Chris@835 118
Chris@150 119 #else
Chris@150 120
Chris@606 121 #ifdef sun
Chris@606 122 #undef MLOCK
Chris@606 123 #undef MUNLOCK
Chris@606 124 #define MLOCK(a,b) ::mlock((char *)a,b)
Chris@606 125 #define MUNLOCK(a,b) ::munlock((char *)a,b)
Chris@606 126 #ifdef __SUNPRO_CC
Chris@606 127 #undef ISNAN
Chris@606 128 #undef ISINF
Chris@606 129 #define ISNAN(x) ((x)!=(x))
Chris@606 130 #define ISINF(x) 0
Chris@606 131 #endif
Chris@606 132 #endif
Chris@606 133
Chris@150 134 #define PLUGIN_GLOB "*.so"
Chris@223 135 #define PATH_SEPARATOR ':'
Chris@186 136
Chris@186 137 #define DEFAULT_LADSPA_PATH "$HOME/ladspa:$HOME/.ladspa:/usr/local/lib/ladspa:/usr/lib/ladspa"
Chris@186 138 #define DEFAULT_DSSI_PATH "$HOME/dssi:$HOME/.dssi:/usr/local/lib/dssi:/usr/lib/dssi"
Chris@150 139
Chris@368 140 #define MUNLOCKALL() ::munlockall()
Chris@368 141
Chris@835 142 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
Chris@835 143 #define MBARRIER() __sync_synchronize()
Chris@835 144 #else
Chris@835 145 extern void SystemMemoryBarrier();
Chris@835 146 #define MBARRIER() SystemMemoryBarrier()
Chris@835 147 #endif
Chris@835 148
Chris@835 149 #endif /* ! __APPLE__ */
Chris@150 150
Chris@150 151 #endif /* ! _WIN32 */
Chris@150 152
Chris@150 153 enum ProcessStatus { ProcessRunning, ProcessNotRunning, UnknownProcessStatus };
Chris@150 154 extern ProcessStatus GetProcessStatus(int pid);
Chris@150 155
Chris@168 156 // Return a vague approximation to the number of free megabytes of real memory.
Chris@1405 157 // Return -1 if unknown. (Hence signed args.) Note that this could be more than
Chris@1405 158 // is actually addressable, e.g. for a 32-bit process on a 64-bit system.
Chris@1038 159 extern void GetRealMemoryMBAvailable(ssize_t &available, ssize_t &total);
Chris@168 160
Chris@1038 161 // Return a vague approximation to the number of free megabytes of
Chris@1038 162 // disc space on the partition containing the given path. Return -1
Chris@1038 163 // if unknown. (Hence signed return type)
Chris@1038 164 extern ssize_t GetDiscSpaceMBAvailable(const char *path);
Chris@168 165
Chris@303 166 extern void StoreStartupLocale();
Chris@303 167 extern void RestoreStartupLocale();
Chris@303 168
Chris@150 169 #include <cmath>
Chris@150 170
Chris@1059 171 #ifndef M_PI
Chris@1059 172 #define M_PI 3.14159265358979323846
Chris@1059 173 #endif
Chris@1059 174
Chris@150 175 extern double mod(double x, double y);
Chris@150 176 extern float modf(float x, float y);
Chris@150 177
Chris@150 178 extern double princarg(double a);
Chris@150 179 extern float princargf(float a);
Chris@150 180
Chris@573 181 #ifdef USE_POW_NO_F
Chris@573 182 #define powf pow
Chris@573 183 #endif
Chris@573 184
Chris@1475 185 /** Return the value of the given environment variable by reference.
Chris@1475 186 Return true if successfully retrieved, false if unset or on error.
Chris@1475 187 Both the variable name and the returned value are UTF-8 encoded.
Chris@1475 188 */
Chris@1475 189 extern bool getEnvUtf8(std::string variable, std::string &value);
Chris@1475 190
Chris@1475 191 /** Set the value of the given environment variable.
Chris@1475 192 Return true if successfully set, false on error.
Chris@1475 193 Both the variable name and the value must be UTF-8 encoded.
Chris@1475 194 */
Chris@1475 195 extern bool putEnvUtf8(std::string variable, std::string value);
Chris@1475 196
Chris@150 197 #endif /* ! _SYSTEM_H_ */
Chris@150 198
Chris@150 199