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 = \
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 \
......
......@@ -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")
......
......@@ -16,13 +16,25 @@
#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
......
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