Commit 47fa124a authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Fix visibility attributes that gcc objects to in xlog

Summary: [Folly] Fix visibility attributes that gcc objects to in xlog by moving them from lambdas to proper functions.

Reviewed By: nbronson

Differential Revision: D16578895

fbshipit-source-id: 021fd10ef01bb610dc6f20d9a9a98a5a8e11df71
parent def0359e
......@@ -113,6 +113,20 @@
}(), \
##__VA_ARGS__)
namespace folly {
namespace detail {
template <typename Tag>
FOLLY_EXPORT FOLLY_ALWAYS_INLINE bool xlogEveryNImpl(size_t n) {
static std::atomic<size_t> count{0};
auto const value = count.load(std::memory_order_relaxed);
count.store(value + 1, std::memory_order_relaxed);
return FOLLY_UNLIKELY((value % n) == 0);
}
} // namespace detail
} // namespace folly
/**
* Similar to XLOG(...) except only log a message every @param n
* invocations, approximately.
......@@ -123,19 +137,28 @@
* contention, leading to possible over-logging or under-logging
* effects.
*/
#define XLOG_EVERY_N(level, n, ...) \
XLOG_IF( \
level, \
[]() FOLLY_EXPORT -> bool { \
static std::atomic<size_t> folly_detail_xlog_count{0}; \
auto const folly_detail_xlog_count_value = \
folly_detail_xlog_count.load(std::memory_order_relaxed); \
folly_detail_xlog_count.store( \
folly_detail_xlog_count_value + 1, std::memory_order_relaxed); \
return FOLLY_UNLIKELY((folly_detail_xlog_count_value % (n)) == 0); \
}(), \
#define XLOG_EVERY_N(level, n, ...) \
XLOG_IF( \
level, \
[] { \
struct folly_detail_xlog_tag {}; \
return ::folly::detail::xlogEveryNImpl<folly_detail_xlog_tag>(n); \
}(), \
##__VA_ARGS__)
namespace folly {
namespace detail {
template <typename Tag>
FOLLY_EXPORT FOLLY_ALWAYS_INLINE bool xlogEveryNExactImpl(size_t n) {
static std::atomic<size_t> count{0};
auto const value = count.fetch_add(1, std::memory_order_relaxed);
return FOLLY_UNLIKELY((value % n) == 0);
}
} // namespace detail
} // namespace folly
/**
* Similar to XLOG(...) except only log a message every @param n
* invocations, exactly.
......@@ -148,11 +171,9 @@
#define XLOG_EVERY_N_EXACT(level, n, ...) \
XLOG_IF( \
level, \
[]() FOLLY_EXPORT -> bool { \
static std::atomic<size_t> folly_detail_xlog_count{0}; \
return FOLLY_UNLIKELY( \
(folly_detail_xlog_count.fetch_add(1, std::memory_order_relaxed) % \
(n)) == 0); \
[] { \
struct folly_detail_xlog_tag {}; \
return ::folly::detail::xlogEveryNExactImpl<folly_detail_xlog_tag>(n); \
}(), \
##__VA_ARGS__)
......@@ -161,6 +182,13 @@ namespace detail {
size_t& xlogEveryNThreadEntry(void const* const key);
template <typename Tag>
FOLLY_EXPORT FOLLY_ALWAYS_INLINE bool xlogEveryNThreadImpl(size_t n) {
static char key;
auto& count = xlogEveryNThreadEntry(&key);
return FOLLY_UNLIKELY((count++ % n) == 0);
}
} // namespace detail
} // namespace folly
......@@ -180,15 +208,14 @@ size_t& xlogEveryNThreadEntry(void const* const key);
* single thread-local map to control TLS overhead, at the cost
* of a small runtime performance hit.
*/
#define XLOG_EVERY_N_THREAD(level, n, ...) \
XLOG_IF( \
level, \
[]() FOLLY_EXPORT -> bool { \
static char folly_detail_xlog_key; \
auto& folly_detail_xlog_count = \
::folly::detail::xlogEveryNThreadEntry(&folly_detail_xlog_key); \
return FOLLY_UNLIKELY((folly_detail_xlog_count++ % (n)) == 0); \
}(), \
#define XLOG_EVERY_N_THREAD(level, n, ...) \
XLOG_IF( \
level, \
[] { \
struct folly_detail_xlog_tag {}; \
return ::folly::detail::xlogEveryNThreadImpl<folly_detail_xlog_tag>( \
n); \
}(), \
##__VA_ARGS__)
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment