summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-07-23 17:24:12 +0100
committerCarl Hetherington <cth@carlh.net>2013-07-23 17:24:12 +0100
commit38cedccdb55e35c8f6b835cfb7405ab2160889e0 (patch)
treee8f6d5989644339ee50aad69c52e4894668c45ab /src/lib
parent5a454b3e7b36b41440424929d67400641bbb8d68 (diff)
Merge Windows CPU code from master.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/cross.cc46
-rw-r--r--src/lib/cross.h2
-rw-r--r--src/lib/film.cc3
3 files changed, 37 insertions, 14 deletions
diff --git a/src/lib/cross.cc b/src/lib/cross.cc
index 4e3739f57..5ecbedf6e 100644
--- a/src/lib/cross.cc
+++ b/src/lib/cross.cc
@@ -39,6 +39,7 @@ using std::pair;
using std::list;
using std::ifstream;
using std::string;
+using std::wstring;
using std::make_pair;
using boost::shared_ptr;
@@ -53,12 +54,11 @@ dcpomatic_sleep (int s)
#endif
}
-/** @return A pair containing CPU model name and the number of processors */
-pair<string, int>
+/** @return A string of CPU information (model name etc.) */
+string
cpu_info ()
{
- pair<string, int> info;
- info.second = 0;
+ string info;
#ifdef DCPOMATIC_LINUX
ifstream f ("/proc/cpuinfo");
@@ -68,24 +68,48 @@ cpu_info ()
if (boost::algorithm::starts_with (l, "model name")) {
string::size_type const c = l.find (':');
if (c != string::npos) {
- info.first = l.substr (c + 2);
+ info = l.substr (c + 2);
}
- } else if (boost::algorithm::starts_with (l, "processor")) {
- ++info.second;
}
}
#endif
#ifdef DCPOMATIC_OSX
- size_t N = sizeof (info.second);
- sysctlbyname ("hw.ncpu", &info.second, &N, 0, 0);
char buffer[64];
- N = sizeof (buffer);
+ size_t N = sizeof (buffer);
if (sysctlbyname ("machdep.cpu.brand_string", buffer, &N, 0, 0) == 0) {
- info.first = buffer;
+ info = buffer;
}
#endif
+#ifdef DCPOMATIC_WINDOWS
+ HKEY key;
+ if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_READ, &key) != ERROR_SUCCESS) {
+ return info;
+ }
+
+ DWORD type;
+ DWORD data;
+ if (RegQueryValueEx (key, L"ProcessorNameString", 0, &type, 0, &data) != ERROR_SUCCESS) {
+ return info;
+ }
+
+ if (type != REG_SZ) {
+ return info;
+ }
+
+ wstring value (data / sizeof (wchar_t), L'\0');
+ if (RegQueryValueEx (key, L"ProcessorNameString", 0, 0, reinterpret_cast<LPBYTE> (&value[0]), &data) != ERROR_SUCCESS) {
+ RegCloseKey (key);
+ return info;
+ }
+
+ info = string (value.begin(), value.end());
+
+ RegCloseKey (key);
+
+#endif
+
return info;
}
diff --git a/src/lib/cross.h b/src/lib/cross.h
index a00fee679..58fa821c7 100644
--- a/src/lib/cross.h
+++ b/src/lib/cross.h
@@ -26,6 +26,6 @@
class Log;
void dcpomatic_sleep (int);
-extern std::pair<std::string, int> cpu_info ();
+extern std::string cpu_info ();
extern void run_ffprobe (boost::filesystem::path, boost::filesystem::path, boost::shared_ptr<Log>);
extern std::list<std::pair<std::string, std::string> > mount_info ();
diff --git a/src/lib/film.cc b/src/lib/film.cc
index b8a26501e..fc06bb058 100644
--- a/src/lib/film.cc
+++ b/src/lib/film.cc
@@ -242,8 +242,7 @@ Film::make_dcp ()
#else
log()->log ("libdcp built in optimised mode.");
#endif
- pair<string, int> const c = cpu_info ();
- log()->log (String::compose ("CPU: %1, %2 processors", c.first, c.second));
+ log()->log (String::compose ("CPU: %1, %2 processors", cpu_info(), boost::thread::hardware_concurrency ()));
list<pair<string, string> > const m = mount_info ();
for (list<pair<string, string> >::const_iterator i = m.begin(); i != m.end(); ++i) {
log()->log (String::compose ("Mount: %1 %2", i->first, i->second));