Renamed the internal os macros to avoid a name clash in Shlwapi.h where OS_WINDOWS is defined to 0.

This commit is contained in:
Anton Danielsson 2015-10-05 13:58:35 +02:00
parent 02440964e8
commit ba141ac0d9
7 changed files with 29 additions and 29 deletions

View File

@ -15,7 +15,7 @@
#include "benchmark/benchmark.h" #include "benchmark/benchmark.h"
#include "internal_macros.h" #include "internal_macros.h"
#ifndef OS_WINDOWS #ifndef BENCHMARK_OS_WINDOWS
#include <sys/time.h> #include <sys/time.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <unistd.h> #include <unistd.h>

View File

@ -19,7 +19,7 @@
#include "commandlineflags.h" #include "commandlineflags.h"
#include "internal_macros.h" #include "internal_macros.h"
#ifdef OS_WINDOWS #ifdef BENCHMARK_OS_WINDOWS
#include <Windows.h> #include <Windows.h>
#endif #endif
@ -27,14 +27,14 @@ DECLARE_bool(color_print);
namespace benchmark { namespace benchmark {
namespace { namespace {
#ifdef OS_WINDOWS #ifdef BENCHMARK_OS_WINDOWS
typedef WORD PlatformColorCode; typedef WORD PlatformColorCode;
#else #else
typedef const char* PlatformColorCode; typedef const char* PlatformColorCode;
#endif #endif
PlatformColorCode GetPlatformColorCode(LogColor color) { PlatformColorCode GetPlatformColorCode(LogColor color) {
#ifdef OS_WINDOWS #ifdef BENCHMARK_OS_WINDOWS
switch (color) { switch (color) {
case COLOR_RED: case COLOR_RED:
return FOREGROUND_RED; return FOREGROUND_RED;
@ -85,7 +85,7 @@ void ColorPrintf(LogColor color, const char* fmt, ...) {
return; return;
} }
#ifdef OS_WINDOWS #ifdef BENCHMARK_OS_WINDOWS
const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE); const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
// Gets the current text color. // Gets the current text color.

View File

@ -41,7 +41,7 @@ extern "C" uint64_t __rdtsc();
#pragma intrinsic(__rdtsc) #pragma intrinsic(__rdtsc)
#endif #endif
#ifndef OS_WINDOWS #ifndef BENCHMARK_OS_WINDOWS
#include <sys/time.h> #include <sys/time.h>
#endif #endif

View File

@ -16,17 +16,17 @@
#endif #endif
#if defined(__CYGWIN__) #if defined(__CYGWIN__)
# define OS_CYGWIN 1 # define BENCHMARK_OS_CYGWIN 1
#elif defined(_WIN32) #elif defined(_WIN32)
# define OS_WINDOWS 1 # define BENCHMARK_OS_WINDOWS 1
#elif defined(__APPLE__) #elif defined(__APPLE__)
// TODO(ericwf) This doesn't actually check that it is a Mac OSX system. Just // TODO(ericwf) This doesn't actually check that it is a Mac OSX system. Just
// that it is an apple system. // that it is an apple system.
# define OS_MACOSX 1 # define BENCHMARK_OS_MACOSX 1
#elif defined(__FreeBSD__) #elif defined(__FreeBSD__)
# define OS_FREEBSD 1 # define BENCHMARK_OS_FREEBSD 1
#elif defined(__linux__) #elif defined(__linux__)
# define OS_LINUX 1 # define BENCHMARK_OS_LINUX 1
#endif #endif
#if defined(__clang__) #if defined(__clang__)

View File

@ -19,12 +19,12 @@
#include "internal_macros.h" #include "internal_macros.h"
#ifdef OS_WINDOWS #ifdef BENCHMARK_OS_WINDOWS
#include <Windows.h> #include <Windows.h>
#endif #endif
namespace benchmark { namespace benchmark {
#ifdef OS_WINDOWS #ifdef BENCHMARK_OS_WINDOWS
// Window's Sleep takes milliseconds argument. // Window's Sleep takes milliseconds argument.
void SleepForMilliseconds(int milliseconds) { Sleep(milliseconds); } void SleepForMilliseconds(int milliseconds) { Sleep(milliseconds); }
void SleepForSeconds(double seconds) { void SleepForSeconds(double seconds) {

View File

@ -15,7 +15,7 @@
#include "sysinfo.h" #include "sysinfo.h"
#include "internal_macros.h" #include "internal_macros.h"
#ifdef OS_WINDOWS #ifdef BENCHMARK_OS_WINDOWS
#include <Shlwapi.h> #include <Shlwapi.h>
#include <Windows.h> #include <Windows.h>
#else #else
@ -51,7 +51,7 @@ double cpuinfo_cycles_per_second = 1.0;
int cpuinfo_num_cpus = 1; // Conservative guess int cpuinfo_num_cpus = 1; // Conservative guess
std::mutex cputimens_mutex; std::mutex cputimens_mutex;
#if !defined OS_MACOSX #if !defined BENCHMARK_OS_MACOSX
const int64_t estimate_time_ms = 1000; const int64_t estimate_time_ms = 1000;
// Helper function estimates cycles/sec by observing cycles elapsed during // Helper function estimates cycles/sec by observing cycles elapsed during
@ -63,7 +63,7 @@ int64_t EstimateCyclesPerSecond() {
} }
#endif #endif
#if defined OS_LINUX || defined OS_CYGWIN #if defined BENCHMARK_OS_LINUX || defined BENCHMARK_OS_CYGWIN
// Helper function for reading an int from a file. Returns true if successful // Helper function for reading an int from a file. Returns true if successful
// and the memory location pointed to by value is set to the value read. // and the memory location pointed to by value is set to the value read.
bool ReadIntFromFile(const char* file, long* value) { bool ReadIntFromFile(const char* file, long* value) {
@ -86,7 +86,7 @@ bool ReadIntFromFile(const char* file, long* value) {
#endif #endif
void InitializeSystemInfo() { void InitializeSystemInfo() {
#if defined OS_LINUX || defined OS_CYGWIN #if defined BENCHMARK_OS_LINUX || defined BENCHMARK_OS_CYGWIN
char line[1024]; char line[1024];
char* err; char* err;
long freq; long freq;
@ -204,7 +204,7 @@ void InitializeSystemInfo() {
cpuinfo_num_cpus = num_cpus; cpuinfo_num_cpus = num_cpus;
} }
#elif defined OS_FREEBSD #elif defined BENCHMARK_OS_FREEBSD
// For this sysctl to work, the machine must be configured without // For this sysctl to work, the machine must be configured without
// SMP, APIC, or APM support. hz should be 64-bit in freebsd 7.0 // SMP, APIC, or APM support. hz should be 64-bit in freebsd 7.0
// and later. Before that, it's a 32-bit quantity (and gives the // and later. Before that, it's a 32-bit quantity (and gives the
@ -232,7 +232,7 @@ void InitializeSystemInfo() {
} }
// TODO: also figure out cpuinfo_num_cpus // TODO: also figure out cpuinfo_num_cpus
#elif defined OS_WINDOWS #elif defined BENCHMARK_OS_WINDOWS
// In NT, read MHz from the registry. If we fail to do so or we're in win9x // In NT, read MHz from the registry. If we fail to do so or we're in win9x
// then make a crude estimate. // then make a crude estimate.
OSVERSIONINFO os; OSVERSIONINFO os;
@ -248,7 +248,7 @@ void InitializeSystemInfo() {
cpuinfo_cycles_per_second = EstimateCyclesPerSecond(); cpuinfo_cycles_per_second = EstimateCyclesPerSecond();
// TODO: also figure out cpuinfo_num_cpus // TODO: also figure out cpuinfo_num_cpus
#elif defined OS_MACOSX #elif defined BENCHMARK_OS_MACOSX
// returning "mach time units" per second. the current number of elapsed // returning "mach time units" per second. the current number of elapsed
// mach time units can be found by calling uint64 mach_absolute_time(); // mach time units can be found by calling uint64 mach_absolute_time();
// while not as precise as actual CPU cycles, it is accurate in the face // while not as precise as actual CPU cycles, it is accurate in the face
@ -281,7 +281,7 @@ void InitializeSystemInfo() {
// getrusage() based implementation of MyCPUUsage // getrusage() based implementation of MyCPUUsage
static double MyCPUUsageRUsage() { static double MyCPUUsageRUsage() {
#ifndef OS_WINDOWS #ifndef BENCHMARK_OS_WINDOWS
struct rusage ru; struct rusage ru;
if (getrusage(RUSAGE_SELF, &ru) == 0) { if (getrusage(RUSAGE_SELF, &ru) == 0) {
return (static_cast<double>(ru.ru_utime.tv_sec) + return (static_cast<double>(ru.ru_utime.tv_sec) +
@ -309,7 +309,7 @@ static double MyCPUUsageRUsage() {
#endif // OS_WINDOWS #endif // OS_WINDOWS
} }
#ifndef OS_WINDOWS #ifndef BENCHMARK_OS_WINDOWS
static bool MyCPUUsageCPUTimeNsLocked(double* cputime) { static bool MyCPUUsageCPUTimeNsLocked(double* cputime) {
static int cputime_fd = -1; static int cputime_fd = -1;
if (cputime_fd == -1) { if (cputime_fd == -1) {
@ -338,7 +338,7 @@ static bool MyCPUUsageCPUTimeNsLocked(double* cputime) {
#endif // OS_WINDOWS #endif // OS_WINDOWS
double MyCPUUsage() { double MyCPUUsage() {
#ifndef OS_WINDOWS #ifndef BENCHMARK_OS_WINDOWS
{ {
std::lock_guard<std::mutex> l(cputimens_mutex); std::lock_guard<std::mutex> l(cputimens_mutex);
static bool use_cputime_ns = true; static bool use_cputime_ns = true;
@ -357,7 +357,7 @@ double MyCPUUsage() {
} }
double ChildrenCPUUsage() { double ChildrenCPUUsage() {
#ifndef OS_WINDOWS #ifndef BENCHMARK_OS_WINDOWS
struct rusage ru; struct rusage ru;
if (getrusage(RUSAGE_CHILDREN, &ru) == 0) { if (getrusage(RUSAGE_CHILDREN, &ru) == 0) {
return (static_cast<double>(ru.ru_utime.tv_sec) + return (static_cast<double>(ru.ru_utime.tv_sec) +
@ -394,7 +394,7 @@ int NumCPUs(void) {
: nullptr) : nullptr)
bool CpuScalingEnabled() { bool CpuScalingEnabled() {
#ifndef OS_WINDOWS #ifndef BENCHMARK_OS_WINDOWS
// On Linux, the CPUfreq subsystem exposes CPU information as files on the // On Linux, the CPUfreq subsystem exposes CPU information as files on the
// local file system. If reading the exported files fails, then we may not be // local file system. If reading the exported files fails, then we may not be
// running on Linux, so we silently ignore all the read errors. // running on Linux, so we silently ignore all the read errors.

View File

@ -16,7 +16,7 @@
#include "internal_macros.h" #include "internal_macros.h"
#include "walltime.h" #include "walltime.h"
#if defined(OS_WINDOWS) #if defined(BENCHMARK_OS_WINDOWS)
#include <time.h> #include <time.h>
#include <winsock.h> // for timeval #include <winsock.h> // for timeval
#else #else
@ -93,7 +93,7 @@ private:
WallTime Slow() const { WallTime Slow() const {
struct timeval tv; struct timeval tv;
#if defined(OS_WINDOWS) #if defined(BENCHMARK_OS_WINDOWS)
FILETIME file_time; FILETIME file_time;
SYSTEMTIME system_time; SYSTEMTIME system_time;
ULARGE_INTEGER ularge; ULARGE_INTEGER ularge;
@ -231,7 +231,7 @@ std::string DateTimeString(bool local) {
std::size_t written; std::size_t written;
if (local) { if (local) {
#if defined(OS_WINDOWS) #if defined(BENCHMARK_OS_WINDOWS)
written = std::strftime(storage, sizeof(storage), "%x %X", ::localtime(&now)); written = std::strftime(storage, sizeof(storage), "%x %X", ::localtime(&now));
#else #else
std::tm timeinfo; std::tm timeinfo;
@ -240,7 +240,7 @@ std::string DateTimeString(bool local) {
written = std::strftime(storage, sizeof(storage), "%F %T", &timeinfo); written = std::strftime(storage, sizeof(storage), "%F %T", &timeinfo);
#endif #endif
} else { } else {
#if defined(OS_WINDOWS) #if defined(BENCHMARK_OS_WINDOWS)
written = std::strftime(storage, sizeof(storage), "%x %X", ::gmtime(&now)); written = std::strftime(storage, sizeof(storage), "%x %X", ::gmtime(&now));
#else #else
std::tm timeinfo; std::tm timeinfo;