/*
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2015 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* limitations under the License.
*/
-#include "folly/detail/CacheLocality.h"
+#include <folly/detail/CacheLocality.h>
+#ifndef _MSC_VER
#define _GNU_SOURCE 1 // for RTLD_NOLOAD
#include <dlfcn.h>
+#endif
#include <fstream>
-#include "folly/Conv.h"
-#include "folly/Exception.h"
-#include "folly/FileUtil.h"
-#include "folly/Format.h"
-#include "folly/ScopeGuard.h"
+#include <folly/Conv.h>
+#include <folly/Exception.h>
+#include <folly/FileUtil.h>
+#include <folly/Format.h>
+#include <folly/ScopeGuard.h>
namespace folly { namespace detail {
/// Returns the best real CacheLocality information available
static CacheLocality getSystemLocalityInfo() {
+#ifdef __linux__
try {
return CacheLocality::readFromSysfs();
} catch (...) {
// keep trying
}
+#endif
long numCpus = sysconf(_SC_NPROCESSORS_CONF);
if (numCpus <= 0) {
/// Returns the first decimal number in the string, or throws an exception
/// if the string does not start with a number terminated by ',', '-',
/// '\n', or eos.
-static ssize_t parseLeadingNumber(const std::string& line) {
+static size_t parseLeadingNumber(const std::string& line) {
auto raw = line.c_str();
char *end;
- unsigned val = strtoul(raw, &end, 10);
- if (end == raw || (*end != ',' && *end != '-' && *end != '\n')) {
+ unsigned long val = strtoul(raw, &end, 10);
+ if (end == raw || (*end != ',' && *end != '-' && *end != '\n' && *end != 0)) {
throw std::runtime_error(to<std::string>(
"error parsing list '", line, "'").c_str());
}
// to each other than entries that are far away. For striping we want
// the inverse map, since we are starting with the cpu
std::vector<size_t> indexes(cpus.size());
- for (int i = 0; i < cpus.size(); ++i) {
+ for (size_t i = 0; i < cpus.size(); ++i) {
indexes[cpus[i]] = i;
}
/// Resolves the dynamically loaded symbol __vdso_getcpu, returning null
/// on failure
static Getcpu::Func loadVdsoGetcpu() {
+#ifdef _MSC_VER
+ return nullptr;
+#else
void* h = dlopen("linux-vdso.so.1", RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD);
if (h == nullptr) {
return nullptr;
}
return func;
+#endif
}
Getcpu::Func Getcpu::vdsoFunc() {
return func;
}
+#ifdef FOLLY_TLS
/////////////// SequentialThreadId
template<>
template<>
FOLLY_TLS size_t SequentialThreadId<std::atomic>::currentId(0);
+#endif
/////////////// AccessSpreader
return °enerateGetcpu;
} else {
auto best = Getcpu::vdsoFunc();
- return best ? best : &SequentialThreadId<std::atomic>::getcpu;
+ return best ? best : &FallbackGetcpuType::getcpu;
}
}