Commit 3673c2eb authored by Felix Handte's avatar Felix Handte Committed by Facebook Github Bot

Fix Zstd-less Build with Macro Guards

Summary:
D18890515 broke folly builds when zstd isn't present. (My bad!!)

This should fix it.

Reviewed By: lukaspiatkowski

Differential Revision: D19029293

fbshipit-source-id: 2ede5a8402e60af61a294c9db35ca15dffdf4c49
parent f296a1d0
......@@ -548,11 +548,10 @@ bool hasCodec(CodecType type);
bool hasStreamCodec(CodecType type);
/**
* Added here so users of folly can figure out whether the singletons are
* usable, and therefore whether to even try to include the header.
*
* 1 means that the header exists and ZSTD_CCtx and ZSTD_DCtx pools are defined.
* Added here so users of folly can figure out whether the header
* folly/compression/CompressionContextPoolSingletons.h is present, and
* therefore whether it can be included.
*/
#define FOLLY_COMPRESSION_HAS_CONTEXT_POOL_SINGLETONS 1
#define FOLLY_COMPRESSION_HAS_CONTEXT_POOL_SINGLETONS
} // namespace io
} // namespace folly
......@@ -20,6 +20,7 @@ namespace folly {
namespace compression {
namespace contexts {
#if FOLLY_HAVE_LIBZSTD
namespace {
// These objects have no static dependencies and therefore no SIOF issues.
ZSTD_CCtx_Pool zstd_cctx_pool_singleton;
......@@ -57,6 +58,8 @@ ZSTD_CCtx_Pool::Ref getNULL_ZSTD_CCtx() {
ZSTD_DCtx_Pool::Ref getNULL_ZSTD_DCtx() {
return zstd_dctx_pool_singleton.getNull();
}
#endif // FOLLY_HAVE_LIBZSTD
} // namespace contexts
} // namespace compression
} // namespace folly
......@@ -16,14 +16,26 @@
#pragma once
#include <folly/folly-config.h>
#if FOLLY_HAVE_LIBZSTD
#include <zstd.h>
#endif
#include <folly/compression/CompressionCoreLocalContextPool.h>
// When this header is present, folly/compression/Compression.h defines
// FOLLY_COMPRESSION_HAS_CONTEXT_POOL_SINGLETONS.
namespace folly {
namespace compression {
namespace contexts {
#if FOLLY_HAVE_LIBZSTD
// Additional feature test macro for zstd singletons.
#define FOLLY_COMPRESSION_HAS_ZSTD_CONTEXT_POOL_SINGLETONS
struct ZSTD_CCtx_Creator {
ZSTD_CCtx* operator()() const noexcept;
};
......@@ -59,6 +71,8 @@ ZSTD_CCtx_Pool::Ref getNULL_ZSTD_CCtx();
ZSTD_DCtx_Pool::Ref getNULL_ZSTD_DCtx();
#endif // FOLLY_HAVE_LIBZSTD
} // namespace contexts
} // namespace compression
} // namespace folly
......@@ -260,6 +260,8 @@ TEST_F(CompressionCoreLocalContextPoolTest, testMultithread) {
EXPECT_LE(numFoos.load(), numThreads);
}
#ifdef FOLLY_COMPRESSION_HAS_ZSTD_CONTEXT_POOL_SINGLETONS
TEST(CompressionContextPoolSingletonsTest, testSingletons) {
EXPECT_NE(contexts::getZSTD_CCtx(), nullptr);
EXPECT_NE(contexts::getZSTD_DCtx(), nullptr);
......@@ -269,5 +271,8 @@ TEST(CompressionContextPoolSingletonsTest, testSingletonsNull) {
EXPECT_EQ(contexts::getNULL_ZSTD_CCtx(), nullptr);
EXPECT_EQ(contexts::getNULL_ZSTD_DCtx(), nullptr);
}
#endif // FOLLY_COMPRESSION_HAS_ZSTD_CONTEXT_POOL_SINGLETONS
} // namespace compression
} // namespace folly
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