folly OSS fixes: add ThreadName.h and compression
authorTudor Bosman <tudorb@fb.com>
Sat, 21 Jun 2014 02:10:12 +0000 (19:10 -0700)
committerAnton Likhtarov <alikhtarov@fb.com>
Thu, 26 Jun 2014 02:27:43 +0000 (19:27 -0700)
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
folly/configure.ac
folly/io/Compression.cpp

index 5162f8f2aada517fb0ec90fa536027c27a1374a9..5f5f13e452fc8b096a131c359e8cc2861d568f95 100644 (file)
@@ -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 \
index 6bb5c165db54a2948f1a974b7fc282d196994e02..2b973ac796cd9f0fa864a6cf5b5bd2cfbd7d3108 100644 (file)
@@ -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")
 
index 11c9557382a425cc941fa120aeeb5445cf442935..02b54a4280ef056b057a30a4edecda8bdc28363d 100644 (file)
 
 #include "folly/io/Compression.h"
 
+#if FOLLY_HAVE_LIBLZ4
 #include <lz4.h>
 #include <lz4hc.h>
+#endif
+
 #include <glog/logging.h>
+
+#if FOLLY_HAVE_LIBSNAPPY
 #include <snappy.h>
 #include <snappy-sinksource.h>
+#endif
+
+#if FOLLY_HAVE_LIBZ
 #include <zlib.h>
+#endif
+
+#if FOLLY_HAVE_LIBLZMA
 #include <lzma.h>
+#endif
 
 #include "folly/Conv.h"
 #include "folly/Memory.h"
@@ -129,6 +141,26 @@ std::unique_ptr<IOBuf> 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<IOBuf> LZ4Codec::doCompress(const IOBuf* data) {
   std::unique_ptr<IOBuf> clone;
   if (data->isChained()) {
@@ -272,6 +286,10 @@ std::unique_ptr<IOBuf> LZ4Codec::doUncompress(
   return out;
 }
 
+#endif  // FOLLY_HAVE_LIBLZ4
+
+#if FOLLY_HAVE_LIBSNAPPY
+
 /**
  * Snappy compression
  */
@@ -391,6 +409,9 @@ std::unique_ptr<IOBuf> 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<IOBuf> ZlibCodec::doCompress(const IOBuf* data) {
   z_stream stream;
   stream.zalloc = nullptr;
@@ -625,6 +645,10 @@ std::unique_ptr<IOBuf> ZlibCodec::doUncompress(const IOBuf* data,
   return out;
 }
 
+#endif  // FOLLY_HAVE_LIBZ
+
+#if FOLLY_HAVE_LIBLZMA
+
 /**
  * LZMA2 compression
  */
@@ -861,6 +885,7 @@ std::unique_ptr<IOBuf> LZMA2Codec::doUncompress(const IOBuf* data,
   return out;
 }
 
+#endif  // FOLLY_HAVE_LIBLZMA
 
 typedef std::unique_ptr<Codec> (*CodecFactory)(int, CodecType);
 
@@ -868,12 +893,38 @@ CodecFactory gCodecFactories[
     static_cast<size_t>(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