From 0ecc747362994b7bdc1ee315b6afbc7ab893a3bc Mon Sep 17 00:00:00 2001 From: Tudor Bosman Date: Fri, 20 Jun 2014 19:10:12 -0700 Subject: [PATCH] folly OSS fixes: add ThreadName.h and compression Summary: Also, optionalize dependencies on compression libraries. Test Plan: fbconfig -r folly && fbmake runtests_opt Reviewed By: meyering@fb.com Subscribers: kma, jhj, simpkins, lesha, folly@lists FB internal diff: D1396573 --- folly/Makefile.am | 2 + folly/configure.ac | 5 +++ folly/io/Compression.cpp | 89 +++++++++++++++++++++++++++++++--------- 3 files changed, 77 insertions(+), 19 deletions(-) diff --git a/folly/Makefile.am b/folly/Makefile.am index 5162f8f2..5f5f13e4 100644 --- a/folly/Makefile.am +++ b/folly/Makefile.am @@ -101,6 +101,7 @@ nobase_follyinclude_HEADERS = \ IPAddressException.h \ IndexedMemPool.h \ IntrusiveList.h \ + io/Compression.h \ io/Cursor.h \ io/IOBuf.h \ io/IOBufQueue.h \ @@ -222,6 +223,7 @@ libfolly_la_SOURCES = \ IPAddressV4.cpp \ IPAddressV6.cpp \ LifoSem.cpp \ + io/Compression.cpp \ io/IOBuf.cpp \ io/IOBufQueue.cpp \ io/RecordIO.cpp \ diff --git a/folly/configure.ac b/folly/configure.ac index 6bb5c165..2b973ac7 100644 --- a/folly/configure.ac +++ b/folly/configure.ac @@ -193,6 +193,11 @@ if test "$ac_cv_func_pthread_yield" = "no"; then AC_CHECK_FUNCS([sched_yield]) fi +AC_CHECK_HEADER([lz4.h], AC_CHECK_LIB([lz4], [main])) +AC_CHECK_HEADER([snappy.h], AC_CHECK_LIB([snappy], [main])) +AC_CHECK_HEADER([zlib.h], AC_CHECK_LIB([z], [main])) +AC_CHECK_HEADER([lzma.h], AC_CHECK_LIB([lzma], [main])) + AC_SUBST(AM_CPPFLAGS, '-I../$(top_srcdir)'" "'-I$(top_srcdir)/io'" "'-I$(top_srcdir)/test'" $BOOST_CPPFLAGS") AC_SUBST(AM_LDFLAGS, "$BOOST_LDFLAGS $BOOST_THREAD_LIB $BOOST_FILESYSTEM_LIB $BOOST_SYSTEM_LIB $BOOST_REGEX_LIB -lpthread") diff --git a/folly/io/Compression.cpp b/folly/io/Compression.cpp index 11c95573..02b54a42 100644 --- a/folly/io/Compression.cpp +++ b/folly/io/Compression.cpp @@ -16,13 +16,25 @@ #include "folly/io/Compression.h" +#if FOLLY_HAVE_LIBLZ4 #include #include +#endif + #include + +#if FOLLY_HAVE_LIBSNAPPY #include #include +#endif + +#if FOLLY_HAVE_LIBZ #include +#endif + +#if FOLLY_HAVE_LIBLZMA #include +#endif #include "folly/Conv.h" #include "folly/Memory.h" @@ -129,6 +141,26 @@ std::unique_ptr NoCompressionCodec::doUncompress( return data->clone(); } +namespace { + +void encodeVarintToIOBuf(uint64_t val, folly::IOBuf* out) { + DCHECK_GE(out->tailroom(), kMaxVarintLength64); + out->append(encodeVarint(val, out->writableTail())); +} + +uint64_t decodeVarintFromCursor(folly::io::Cursor& cursor) { + // Must have enough room in *this* buffer. + auto p = cursor.peek(); + folly::ByteRange range(p.first, p.second); + uint64_t val = decodeVarint(range); + cursor.skip(range.data() - p.first); + return val; +} + +} // namespace + +#if FOLLY_HAVE_LIBLZ4 + /** * LZ4 compression */ @@ -184,24 +216,6 @@ uint64_t LZ4Codec::doMaxUncompressedLength() const { return 1.8 * (uint64_t(1) << 30); } -namespace { - -void encodeVarintToIOBuf(uint64_t val, folly::IOBuf* out) { - DCHECK_GE(out->tailroom(), kMaxVarintLength64); - out->append(encodeVarint(val, out->writableTail())); -} - -uint64_t decodeVarintFromCursor(folly::io::Cursor& cursor) { - // Must have enough room in *this* buffer. - auto p = cursor.peek(); - folly::ByteRange range(p.first, p.second); - uint64_t val = decodeVarint(range); - cursor.skip(range.data() - p.first); - return val; -} - -} // namespace - std::unique_ptr LZ4Codec::doCompress(const IOBuf* data) { std::unique_ptr clone; if (data->isChained()) { @@ -272,6 +286,10 @@ std::unique_ptr LZ4Codec::doUncompress( return out; } +#endif // FOLLY_HAVE_LIBLZ4 + +#if FOLLY_HAVE_LIBSNAPPY + /** * Snappy compression */ @@ -391,6 +409,9 @@ std::unique_ptr SnappyCodec::doUncompress(const IOBuf* data, return out; } +#endif // FOLLY_HAVE_LIBSNAPPY + +#if FOLLY_HAVE_LIBZ /** * Zlib codec */ @@ -475,7 +496,6 @@ bool ZlibCodec::doInflate(z_stream* stream, return false; } - std::unique_ptr ZlibCodec::doCompress(const IOBuf* data) { z_stream stream; stream.zalloc = nullptr; @@ -625,6 +645,10 @@ std::unique_ptr ZlibCodec::doUncompress(const IOBuf* data, return out; } +#endif // FOLLY_HAVE_LIBZ + +#if FOLLY_HAVE_LIBLZMA + /** * LZMA2 compression */ @@ -861,6 +885,7 @@ std::unique_ptr LZMA2Codec::doUncompress(const IOBuf* data, return out; } +#endif // FOLLY_HAVE_LIBLZMA typedef std::unique_ptr (*CodecFactory)(int, CodecType); @@ -868,12 +893,38 @@ CodecFactory gCodecFactories[ static_cast(CodecType::NUM_CODEC_TYPES)] = { nullptr, // USER_DEFINED NoCompressionCodec::create, + +#if FOLLY_HAVE_LIBLZ4 LZ4Codec::create, +#else + nullptr, +#endif + +#if FOLLY_HAVE_LIBSNAPPY SnappyCodec::create, +#else + nullptr, +#endif + +#if FOLLY_HAVE_LIBZ ZlibCodec::create, +#else + nullptr, +#endif + +#if FOLLY_HAVE_LIBLZ4 LZ4Codec::create, +#else + nullptr, +#endif + +#if FOLLY_HAVE_LIBLZMA LZMA2Codec::create, LZMA2Codec::create, +#else + nullptr, + nullptr, +#endif }; } // namespace -- 2.34.1