Commit 0ecc7473 authored by Tudor Bosman's avatar Tudor Bosman Committed by Anton Likhtarov

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
parent 6019aaaa
...@@ -101,6 +101,7 @@ nobase_follyinclude_HEADERS = \ ...@@ -101,6 +101,7 @@ nobase_follyinclude_HEADERS = \
IPAddressException.h \ IPAddressException.h \
IndexedMemPool.h \ IndexedMemPool.h \
IntrusiveList.h \ IntrusiveList.h \
io/Compression.h \
io/Cursor.h \ io/Cursor.h \
io/IOBuf.h \ io/IOBuf.h \
io/IOBufQueue.h \ io/IOBufQueue.h \
...@@ -222,6 +223,7 @@ libfolly_la_SOURCES = \ ...@@ -222,6 +223,7 @@ libfolly_la_SOURCES = \
IPAddressV4.cpp \ IPAddressV4.cpp \
IPAddressV6.cpp \ IPAddressV6.cpp \
LifoSem.cpp \ LifoSem.cpp \
io/Compression.cpp \
io/IOBuf.cpp \ io/IOBuf.cpp \
io/IOBufQueue.cpp \ io/IOBufQueue.cpp \
io/RecordIO.cpp \ io/RecordIO.cpp \
......
...@@ -193,6 +193,11 @@ if test "$ac_cv_func_pthread_yield" = "no"; then ...@@ -193,6 +193,11 @@ if test "$ac_cv_func_pthread_yield" = "no"; then
AC_CHECK_FUNCS([sched_yield]) AC_CHECK_FUNCS([sched_yield])
fi 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_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") AC_SUBST(AM_LDFLAGS, "$BOOST_LDFLAGS $BOOST_THREAD_LIB $BOOST_FILESYSTEM_LIB $BOOST_SYSTEM_LIB $BOOST_REGEX_LIB -lpthread")
......
...@@ -16,13 +16,25 @@ ...@@ -16,13 +16,25 @@
#include "folly/io/Compression.h" #include "folly/io/Compression.h"
#if FOLLY_HAVE_LIBLZ4
#include <lz4.h> #include <lz4.h>
#include <lz4hc.h> #include <lz4hc.h>
#endif
#include <glog/logging.h> #include <glog/logging.h>
#if FOLLY_HAVE_LIBSNAPPY
#include <snappy.h> #include <snappy.h>
#include <snappy-sinksource.h> #include <snappy-sinksource.h>
#endif
#if FOLLY_HAVE_LIBZ
#include <zlib.h> #include <zlib.h>
#endif
#if FOLLY_HAVE_LIBLZMA
#include <lzma.h> #include <lzma.h>
#endif
#include "folly/Conv.h" #include "folly/Conv.h"
#include "folly/Memory.h" #include "folly/Memory.h"
...@@ -129,6 +141,26 @@ std::unique_ptr<IOBuf> NoCompressionCodec::doUncompress( ...@@ -129,6 +141,26 @@ std::unique_ptr<IOBuf> NoCompressionCodec::doUncompress(
return data->clone(); 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 * LZ4 compression
*/ */
...@@ -184,24 +216,6 @@ uint64_t LZ4Codec::doMaxUncompressedLength() const { ...@@ -184,24 +216,6 @@ uint64_t LZ4Codec::doMaxUncompressedLength() const {
return 1.8 * (uint64_t(1) << 30); 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> LZ4Codec::doCompress(const IOBuf* data) {
std::unique_ptr<IOBuf> clone; std::unique_ptr<IOBuf> clone;
if (data->isChained()) { if (data->isChained()) {
...@@ -272,6 +286,10 @@ std::unique_ptr<IOBuf> LZ4Codec::doUncompress( ...@@ -272,6 +286,10 @@ std::unique_ptr<IOBuf> LZ4Codec::doUncompress(
return out; return out;
} }
#endif // FOLLY_HAVE_LIBLZ4
#if FOLLY_HAVE_LIBSNAPPY
/** /**
* Snappy compression * Snappy compression
*/ */
...@@ -391,6 +409,9 @@ std::unique_ptr<IOBuf> SnappyCodec::doUncompress(const IOBuf* data, ...@@ -391,6 +409,9 @@ std::unique_ptr<IOBuf> SnappyCodec::doUncompress(const IOBuf* data,
return out; return out;
} }
#endif // FOLLY_HAVE_LIBSNAPPY
#if FOLLY_HAVE_LIBZ
/** /**
* Zlib codec * Zlib codec
*/ */
...@@ -475,7 +496,6 @@ bool ZlibCodec::doInflate(z_stream* stream, ...@@ -475,7 +496,6 @@ bool ZlibCodec::doInflate(z_stream* stream,
return false; return false;
} }
std::unique_ptr<IOBuf> ZlibCodec::doCompress(const IOBuf* data) { std::unique_ptr<IOBuf> ZlibCodec::doCompress(const IOBuf* data) {
z_stream stream; z_stream stream;
stream.zalloc = nullptr; stream.zalloc = nullptr;
...@@ -625,6 +645,10 @@ std::unique_ptr<IOBuf> ZlibCodec::doUncompress(const IOBuf* data, ...@@ -625,6 +645,10 @@ std::unique_ptr<IOBuf> ZlibCodec::doUncompress(const IOBuf* data,
return out; return out;
} }
#endif // FOLLY_HAVE_LIBZ
#if FOLLY_HAVE_LIBLZMA
/** /**
* LZMA2 compression * LZMA2 compression
*/ */
...@@ -861,6 +885,7 @@ std::unique_ptr<IOBuf> LZMA2Codec::doUncompress(const IOBuf* data, ...@@ -861,6 +885,7 @@ std::unique_ptr<IOBuf> LZMA2Codec::doUncompress(const IOBuf* data,
return out; return out;
} }
#endif // FOLLY_HAVE_LIBLZMA
typedef std::unique_ptr<Codec> (*CodecFactory)(int, CodecType); typedef std::unique_ptr<Codec> (*CodecFactory)(int, CodecType);
...@@ -868,12 +893,38 @@ CodecFactory gCodecFactories[ ...@@ -868,12 +893,38 @@ CodecFactory gCodecFactories[
static_cast<size_t>(CodecType::NUM_CODEC_TYPES)] = { static_cast<size_t>(CodecType::NUM_CODEC_TYPES)] = {
nullptr, // USER_DEFINED nullptr, // USER_DEFINED
NoCompressionCodec::create, NoCompressionCodec::create,
#if FOLLY_HAVE_LIBLZ4
LZ4Codec::create, LZ4Codec::create,
#else
nullptr,
#endif
#if FOLLY_HAVE_LIBSNAPPY
SnappyCodec::create, SnappyCodec::create,
#else
nullptr,
#endif
#if FOLLY_HAVE_LIBZ
ZlibCodec::create, ZlibCodec::create,
#else
nullptr,
#endif
#if FOLLY_HAVE_LIBLZ4
LZ4Codec::create, LZ4Codec::create,
#else
nullptr,
#endif
#if FOLLY_HAVE_LIBLZMA
LZMA2Codec::create, LZMA2Codec::create,
LZMA2Codec::create, LZMA2Codec::create,
#else
nullptr,
nullptr,
#endif
}; };
} // namespace } // namespace
......
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