folly/MPMCQueue sizeGuess should return a signed int

Summary:
Like size(), sizeGuess() is allowed to return a negative value,
so it should be ssize_t instead of uint64_t.

Test Plan: fbmake, wait for contbuild

Reviewed By: tudorb@fb.com

FB internal diff: D893075
Multi-Producer, Multi-Consumer pipeline

Summary:
A bunch of MPMCQueues linked together. Stage i produces exactly Ki (default 1)
outputs for each input. Ordering is preserved, even though stages might
produce (intermediate or final) results in parallel and in any order; we do
this by abusing the enqueueing mechanism in MPMCQueue. (Read the code for
details)

Test Plan: test added, more tests to be written before commit

Reviewed By: ngbronson@fb.com

FB internal diff: D892388
fix folly compilation on FreeBSD

Summary:
- fix folly compilation on FreeBSD

Github Author: Martin Matuska <martin@matuska.org>

Test Plan: - compiled

Reviewed By: tudorb@fb.com

FB internal diff: D896747
fix folly Range compilation on FreeBSD

Summary: - memrchr is GNU + Linux specific, it turns out

Test Plan: - compiled on FreeBSD, contbuild

Reviewed By: delong.j@fb.com

FB internal diff: D900935
Use std::equal<> as qfind default comparator

Summary:
qfind(haystack, needle) is templated, but used a non-templated
default comparator that cast everything to char.  This works find for
8-bit types, but not for others such as the uint32_t Ranges we are
using.  Replace the default comparator with std::equal<> to use a
working comparator for whatever type is being searched.

Test Plan:
Compiles, unit tests (including a new one that fails with the
old code) pass.  Not sure how to test other users of this, or measure
performance impact. :(

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D906311
Fix build break for Clang builds.

Summary:
Complains about

```
In file included from crypto/lib/cpp/CryptoException.cpp:1:
In file included from crypto/lib/cpp/CryptoException.h:5:
In file included from ./folly/Conv.h:30:
./folly/Range.h:573:19: error: redefinition of default argument
Comp eq = Comp()) {
^    ~~~~~~
./folly/Range.h:55:26: note: previous definition is here
Comp eq = Comp());
^    ~~~~~~
```

Redefinition of default arguments is not allowed in C++.

Test Plan:
```
fbconfig --clang admarket/adpublisher && fbmake dbg
```

contbuild, etc.

Reviewed By: lucian@fb.com

FB internal diff: D910800
Cycle

Summary: For repeating a generator's values endlessly.

Test Plan: Unit tests

Reviewed By: kittipat@fb.com

FB internal diff: D911178
Make ThreadLocalPtr behave sanely around fork()

Summary:
Threads and fork still don't mix, but we shouldn't help you shoot yourself in
the foot if you decide to do it.

Test Plan: test added

Reviewed By: mshneer@fb.com

FB internal diff: D911224
Update build for Ubuntu 12.10. 12.04 seems to no longer compile

Summary: Dave Watson put this in github a few months ago.

Test Plan: None

Reviewed By: delong.j@fb.com

FB internal diff: D912681
Batch

Summary: Convert stream of elements to stream of fixed-sized vectors.

Test Plan: unit tests

Reviewed By: tjackson@fb.com

FB internal diff: D912290
make folly/Bits.h clang-compatible

Summary: In clang (as of 3.2) intrinsics aren't `constexpr`.

Test Plan:
fbconfig folly/test:bits_test && fbmake opt -j32
fbconfig --clang folly/test:bits_test && fbmake opt -j32

Reviewed By: lucian@fb.com

FB internal diff: D910310
Fixing Until, Take

Summary:
`apply()` returns false if and only if the handler it was //directly//
passed returned false. `Take` didn't do this right, and `Until` was just broken.

Test Plan: More thorough unit tests.

Reviewed By: kittipat@fb.com

FB internal diff: D913185
dereference

Summary:
For dealing with sequences of pointers. Works with pointer wrappers,
and filters out nullptrs, see tests.

Test Plan: Unit tests

Reviewed By: tulloch@fb.com

FB internal diff: D914069
removed superfluous declarations from header files

Summary:
Clang doesn't like the same member of a class being defined more than once,
or default argument values being defined more than once. This diff removes some
instances.

@override-unit-failures

Test Plan: Compiled the code with Clang and GCC

Reviewed By: andrewjcg@fb.com

FB internal diff: D913226
Revert "[clang support] removed superfluous declarations from header files"

Summary: This reverts commit 49b197dfd02443e958906bac45059cea460e4e10.

Test Plan: contbuild

Reviewed By: akhilravidas@fb.com

FB internal diff: D915386

@override-unit-failures
IOBuf compression

Summary: davejwatson: you asked

Test Plan: test added

Reviewed By: davejwatson@fb.com

FB internal diff: D917336
folly: avoid use of has_trivial_destructor in FBVector.h

Summary:
This is required for gcc-4.8.x.
Use boost::has_trivial_destructor, not std::has_trivial_destructor.
The latter was never standard, and the now-std name (and the only one
supported in gcc-4.8.0) is std::is_trivially_destructible.

Test Plan:
fbmake runtests and then
run_unit_tests.sh with -r and again with -d

Reviewed By: njormrod@fb.com

FB internal diff: D923359

@override-unit-failures
folly/Conv.h: remove unused local typedef

Test Plan: compiled using gcc-4.8

Reviewed By: meyering@fb.com

FB internal diff: D923895
folly: attribute-aligned-arg must now be constant (not enum)

Summary:
With gcc-4.8.[01], the argument to __attribute__((__aligned__(...)))
must be a literal;  using an enum member evokes this:

./folly/MPMCQueue.h:341:63: error: requested alignment is not an \
integer constant
size_t capacity_ FOLLY_ON_NEXT_CACHE_LINE;

Changing the enum member to this made no difference:

static constexpr size_t kFalseSharingRange = 64;

Test Plan: compile tao and run test suite

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D926221

@override-unit-failures
Fix a ThreadLocal bug: hold the meta lock when resizing the element vector

Summary:
There appears to be a race here.  leizha reported issues with
a heavily recycled AtomicHashMap (ThreadCachedInt inside).  It looks
like what's happening is this:

- Thread A: ~ThreadCachedInt from an AHM
- meta lock is taken, and the ThreadElement list is iterated
- all entries are zerod, and the id is marked free
- then releases the lock
- Thread B: someone is calling get() on an unrelated id
- hit reserve: rallocm on the pointer or unsynchronized memcpy from
the element vector
- waits on the lock
- when it gets the lock, it stores back the value that it read that
was zero'd by A.

Later, someone reuses the id from the freelist, and reuses the
previously freed pointer, and eventually double-freeing it.  (nullptr
is the signifier for "this thread doesn't have an instance of the
threadlocal yet").

Test Plan:
leizha's test case doesn't segv after this diff---it was
reliably breaking with corruption in malloc before it.  I'm working on
making that test case into a unit test to add to this diff, but I'm
putting it up early in case there's something wrong with the theory
above or in case someone has an idea for a better fix.

Reviewed By: tudorb@fb.com

FB internal diff: D928534