FBString conservative additions

Summary:
Now that fbstring is conservative by default (D1373308), we can remove
the mutability of the data members and the call to c_str() in operator[].

Test Plan: fbconfig -r folly && fbmake runtests

Reviewed By: lucian@fb.com

Subscribers: folly@lists, sdwilsh, njormrod

FB internal diff: D1382644
Make fbstring libgcc-safe

Summary:
Some libgcc-incompatible code has been added to fbstring.
Removed/reorganized it so that we can drop fbstring right into libgcc.

Test Plan:
fbconfig -r folly && fbmake runtests

Copied FBString.h into libgcc's basic_fbstring.h, with no modifications.
Successfully tp2_build libgcc/4.8.1. Adjusted symlink, then fbmake clean
&& fbconfig -r folly && fbmake dbg. The fbmake dbg failed with an
assertion error, which is consistent with @lucian's observations in
D1373725; the important part is that the error was at runtime, so the
compile-time changes of this diff looks good.

Reviewed By: lucian@fb.com

Subscribers: folly@lists, sdwilsh, njormrod, lucian

FB internal diff: D1382873
Expose EVLOOP_NONBLOCK

Summary:
This diff allows users to loop through EventBase without blocking if there are
not any events to process.

This is useful for sending and receiving requests on network, where users just
want to try if there are any events and do not want to block if not.

https://phabricator.fb.com/D1373887 is an example where we find this feature
useful, otherwise we have to add an empty callback before loop.
event_base_.runInLoop([] {});
event_base_.loopOnce();

@davejwatson, @fugalh, @simpkins, @stepan: Could you please take a look at the
proposed changes and let me know if there is any better ways of doing this.

Thank you!

Test Plan:
I think this would not break anything, but we might want to do some performance
profiling if needed.

Reviewed By: hans@fb.com

Subscribers: simpkins, davejwatson, fugalh, stepan, folly@lists

FB internal diff: D1383401
Add ThreadName.h to folly's Makefile.am

Summary:
fbthrift depends on <folly/ThreadName.h>, which isn't currently
getting installed as part of the autotools build.  Add it to Makefile.am

Test Plan:
Made this change to folly, re-autogen/configure/install, and
then was able to successfully compile fbthrift's compiler

Reviewed By: davejwatson@fb.com

Subscribers: doug, folly@lists

FB internal diff: D1397084
Make randomNumberSeed read from /dev/urandom

Summary: Because @lesha asked "why not" and I couldn't give him an answer.

Test Plan: random_test

Reviewed By: bmaurer@fb.com

Subscribers: bmaurer, folly@lists, jhj, kma, lesha, sdoroshenko, soren

FB internal diff: D1394401
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
Scheduler interface of Executor

Summary: and ManualExecutor implementation

Test Plan: unit tests, contbuild

Reviewed By: davejwatson@fb.com

Subscribers: bmatheny, folly@lists, net-systems@, fugalh, exa, marccelani, jsedgwick

FB internal diff: D1392999

Tasks: 4548494
Fix for folly open source build on Ubuntu 12.04

Summary: On 12.04, there's both /usr/lib/libiberty.a and /usr/lib/libiberty_pic.a, and _pic is the one we want to build a Folly shared library.

Test Plan: build on Ubuntu 12.04

Reviewed By: meyering@fb.com

FB internal diff: D1402194
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
Oops, fix README

Reviewed By: meyering@fb.com
Test Plan: no
(folly) QueuedImmediateExecutor

Summary: Add the `QueuedImmediateExecutor` which behaves like `InlineExecutor` but with different (and usually better) ordering semantics for nested calls.
@override-unit-failures

Test Plan: unit tests

Reviewed By: davejwatson@fb.com

Subscribers: folly@lists, net-systems@, fugalh, exa

FB internal diff: D1364904

Tasks: 3789661
Fix bizarre optimization

Summary:
I have no idea why the compiler is gettings its britches in a bunch because a unit test has a predictable output. Really, gcc?!

But whatever, avoiding inlining by putting it in the cpp file solves it.

Test Plan: fbmake runtests_opt

Reviewed By: davejwatson@fb.com

Subscribers: net-systems@, fugalh, exa

FB internal diff: D1405811

Tasks: 4591823
nuke executeWith

Summary: Removing this crufty API. The only callsite for `executeWith` was `Later::via` so I just folded it in there.

Test Plan:
unit tests
contbuild

Reviewed By: hannesr@fb.com

Subscribers: net-systems@, fugalh, exa

FB internal diff: D1406592

Tasks: 4480567
(wangle) s/continuation/callback

Summary: The word "continuation" is too ambiguous. Prefer callback (except where we are actually talking about CSP continuations in the README).

Test Plan: Still builds. Nothing external is or should be calling `setContinuation`. But I'll wait for contbuild anyway.

Reviewed By: hannesr@fb.com

Subscribers: net-systems@, fugalh, exa

FB internal diff: D1406753

Tasks: 4480567
(wangle) noexcept move constructor

Summary: to make lint happy

Test Plan: builds

Reviewed By: hannesr@fb.com

Subscribers: net-systems@, fugalh, exa

FB internal diff: D1406766

Tasks: 4480567
Fix use-after-free in futexWaitUntilImpl

Summary: Handle wake-ups correctly in futexWaitUntilImpl.

Test Plan:
-- ran all folly unit tests
-- ran TimeoutWorkQueue test under tao/queues

Reviewed By: ngbronson@fb.com, meyering@fb.com

FB internal diff: D1406845

Tasks: 4494871
folly: futexWaitUntilImpl: avoid abort triggered via tao/queues tests

Summary:
* folly/test/DeterministicSchedule.cpp (folly): Tao/queues tests exposed
an unhandled case in this code: when (futex->data == expected) happens,
we would call futexErrnoToFutexResult with a futexErrno value of 0,
which would cause an abort (unhandled valued in switch).
Here's a stack trace from the abort: https://phabricator.fb.com/P12558008
showing the invalid futexErrno value in frame #4.

Test Plan:
fbconfig -r --platform-all=gcc-4.8.1-glibc-2.17 --sanitize=address tao/queues:TimeoutWorkQueueTests
_bin/tao/queues/WorkQueueTests -fbunit_test_regexp '^mt\_stress\_deterministic$'

Reviewed By: mssarang@fb.com

FB internal diff: D1404572

Tasks: 4494871
(wangle) Return a Later from Future::via

Summary: Stroke of brilliance, Hannes.

Test Plan:
unit tests, including a new one
Looked through `fbgs 'via('` and all the extant `via`s are attached to `Later`s already so it shouldn't break anything. But check contbuild before commit.

Reviewed By: hannesr@fb.com

Subscribers: net-systems@, fugalh, exa

FB internal diff: D1406976

Tasks: 4480567
Fix folly on OSX and BSD in prep for FastCGI on HHVM

Summary:
A recent change in folly/MemoryMapping.cpp uses MAP_ANONYMOUS, which is
named MAP_ANON on OSX/BSD.

We need folly and third-party changes in order to land a pull request for HHVM
that starts to get FastCGI running on OSX.

See the checklist of the HHVM pull request here: https://github.com/facebook/hhvm/pull/2944#issuecomment-47281003

Closes #67

GitHub Author: Daniel Sloof <goapsychadelic@gmail.com>

@override-unit-failures

Test Plan: fbmake runtests 100%

Reviewed By: pt@fb.com, njormrod@fb.com

FB internal diff: D1407393
Be explicit about what we're passing to Endian::big

Summary:
This prevents a linker error on OSX:
```
Undefined symbols for architecture x86_64:
"folly::detail::EndianIntBase::swap(unsigned long)",
referenced from:
__GLOBAL__sub_I_MacAddress.cpp in libfolly.a(MacAddress.cpp.o)
ld: symbol(s) not found for architecture x86_64
```

We need folly and third-party changes in order to land a pull request for HHVM
that starts to get FastCGI running on OSX.

See the checklist of the HHVM pull request here: https://github.com/facebook/hhvm/pull/2944#issuecomment-47281003

Closes #68

GitHub Author: Daniel Sloof <goapsychadelic@gmail.com>

@override-unit-failures

Test Plan: fbmake runtests 100%

Reviewed By: pt@fb.com, njormrod@fb.com

FB internal diff: D1407426