2 ==============================================================================
\r
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
\r
5 Copyright 2004-11 by Raw Material Software Ltd.
\r
7 ------------------------------------------------------------------------------
\r
9 JUCE can be redistributed and/or modified under the terms of the GNU General
\r
10 Public License (Version 2), as published by the Free Software Foundation.
\r
11 A copy of the license is included in the JUCE distribution, or can be found
\r
12 online at www.gnu.org/licenses.
\r
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
\r
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
\r
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
\r
18 ------------------------------------------------------------------------------
\r
20 To release a closed-source product which uses JUCE, commercial licenses are
\r
21 available: visit www.rawmaterialsoftware.com/juce for more information.
\r
23 ==============================================================================
\r
26 // (This file gets included by juce_mac_NativeCode.mm, rather than being
\r
27 // compiled on its own).
\r
28 #if JUCE_INCLUDED_FILE
\r
30 namespace SystemStatsHelpers
\r
33 void doCPUID (uint32& a, uint32& b, uint32& c, uint32& d, uint32 type)
\r
35 uint32 la = a, lb = b, lc = c, ld = d;
\r
37 asm ("mov %%ebx, %%esi \n\t"
\r
40 : "=a" (la), "=S" (lb), "=c" (lc), "=d" (ld) : "a" (type)
\r
42 , "b" (lb), "c" (lc), "d" (ld)
\r
46 a = la; b = lb; c = lc; d = ld;
\r
51 //==============================================================================
\r
52 SystemStats::CPUFlags::CPUFlags()
\r
55 uint32 familyModel = 0, extFeatures = 0, features = 0, dummy = 0;
\r
56 SystemStatsHelpers::doCPUID (familyModel, extFeatures, dummy, features, 1);
\r
58 hasMMX = (features & (1 << 23)) != 0;
\r
59 hasSSE = (features & (1 << 25)) != 0;
\r
60 hasSSE2 = (features & (1 << 26)) != 0;
\r
61 has3DNow = (extFeatures & (1 << 31)) != 0;
\r
69 #if JUCE_IOS || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
\r
70 numCpus = (int) [[NSProcessInfo processInfo] activeProcessorCount];
\r
72 numCpus = (int) MPProcessors();
\r
77 struct SharedAppInitialiser
\r
79 SharedAppInitialiser()
\r
81 JUCE_AUTORELEASEPOOL
\r
82 [NSApplication sharedApplication];
\r
85 getrlimit (RLIMIT_NOFILE, &lim);
\r
86 lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
\r
87 setrlimit (RLIMIT_NOFILE, &lim);
\r
91 static SharedAppInitialiser sharedAppInitialiser;
\r
94 //==============================================================================
\r
95 SystemStats::OperatingSystemType SystemStats::getOperatingSystemType()
\r
100 String SystemStats::getOperatingSystemName()
\r
105 String s ("Mac OSX ");
\r
108 struct utsname uts;
\r
109 if (uname (&uts) >= 0)
\r
116 int PlatformUtilities::getOSXMinorVersionNumber()
\r
118 SInt32 versionMinor = 0;
\r
119 OSErr err = Gestalt (gestaltSystemVersionMinor, &versionMinor);
\r
121 jassert (err == noErr);
\r
122 return (int) versionMinor;
\r
126 bool SystemStats::isOperatingSystem64Bit()
\r
133 return PlatformUtilities::getOSXMinorVersionNumber() >= 6;
\r
137 int SystemStats::getMemorySizeInMegabytes()
\r
140 size_t memSize = sizeof (mem);
\r
141 int mib[] = { CTL_HW, HW_MEMSIZE };
\r
142 sysctl (mib, 2, &mem, &memSize, 0, 0);
\r
143 return (int) (mem / (1024 * 1024));
\r
146 String SystemStats::getCpuVendor()
\r
150 uint32 vendor[4] = { 0 };
\r
152 SystemStatsHelpers::doCPUID (dummy, vendor[0], vendor[2], vendor[1], 0);
\r
154 return String (reinterpret_cast <const char*> (vendor), 12);
\r
156 return String::empty;
\r
160 int SystemStats::getCpuSpeedInMegaherz()
\r
162 uint64 speedHz = 0;
\r
163 size_t speedSize = sizeof (speedHz);
\r
164 int mib[] = { CTL_HW, HW_CPU_FREQ };
\r
165 sysctl (mib, 2, &speedHz, &speedSize, 0, 0);
\r
167 #if JUCE_BIG_ENDIAN
\r
168 if (speedSize == 4)
\r
172 return (int) (speedHz / 1000000);
\r
175 //==============================================================================
\r
176 String SystemStats::getLogonName()
\r
178 return nsStringToJuce (NSUserName());
\r
181 String SystemStats::getFullUserName()
\r
183 return nsStringToJuce (NSFullUserName());
\r
186 String SystemStats::getComputerName()
\r
188 char name [256] = { 0 };
\r
189 if (gethostname (name, sizeof (name) - 1) == 0)
\r
190 return String (name).upToLastOccurrenceOf (".local", false, true);
\r
192 return String::empty;
\r
195 //==============================================================================
\r
196 class HiResCounterHandler
\r
199 HiResCounterHandler()
\r
201 mach_timebase_info_data_t timebase;
\r
202 (void) mach_timebase_info (&timebase);
\r
203 highResTimerFrequency = (timebase.denom * (int64) 1000000000) / timebase.numer;
\r
204 numerator = timebase.numer;
\r
205 denominator = timebase.denom * (int64) 1000000;
\r
206 highResTimerToMillisecRatio = numerator / (double) denominator;
\r
209 inline uint32 millisecondsSinceStartup() const noexcept
\r
211 return (uint32) ((mach_absolute_time() * numerator) / denominator);
\r
214 inline double getMillisecondCounterHiRes() const noexcept
\r
216 return mach_absolute_time() * highResTimerToMillisecRatio;
\r
219 int64 highResTimerFrequency;
\r
222 int64 numerator, denominator;
\r
223 double highResTimerToMillisecRatio;
\r
226 static HiResCounterHandler hiResCounterHandler;
\r
228 uint32 juce_millisecondsSinceStartup() noexcept { return hiResCounterHandler.millisecondsSinceStartup(); }
\r
229 double Time::getMillisecondCounterHiRes() noexcept { return hiResCounterHandler.getMillisecondCounterHiRes(); }
\r
230 int64 Time::getHighResolutionTicksPerSecond() noexcept { return hiResCounterHandler.highResTimerFrequency; }
\r
231 int64 Time::getHighResolutionTicks() noexcept { return (int64) mach_absolute_time(); }
\r
233 bool Time::setSystemTimeToThisTime() const
\r
239 //==============================================================================
\r
240 int SystemStats::getPageSize()
\r
242 return (int) NSPageSize();
\r
245 void PlatformUtilities::fpuReset()
\r