folly.git
9 years agoBump version to 22:0 v0.22.0
Viswanath Sivakumar [Tue, 13 Jan 2015 19:02:44 +0000 (11:02 -0800)]
Bump version to 22:0

9 years ago(folly) osx bootstrap script
Hans Fugal [Tue, 6 Jan 2015 00:21:50 +0000 (16:21 -0800)]
(folly) osx bootstrap script

Summary:
This is a bootstrap script for building folly on osx. I attempted to make it Just Work™ for anyone who uses Homebrew (http://brew.sh/) but even if it doesn't work out of the box it should be instructive for the motivated developer on OSX.

Facebook:
In #5134151 Wangle used to not build, because something was using a futex. But that seems to have been rectified (or the build problems are hiding in headers that aren't used in the libfolly build).

I'll also update https://our.intern.facebook.com/intern/wiki/Folly/BuildingOnMac to point people to this script instead.

Test Plan:
Tested on my laptop which is running Yosemite (10.10.1)
Build, then inspect `otool -L .libs/*dylib`

Reviewed By: davejwatson@fb.com

Subscribers: folly-diffs@, exa

FB internal diff: D1765248

Tasks: 5134151

Signature: t1:1765248:1420500905:bc5da97a0446f502cb2badc85c9004ff0a62027a

9 years agoAdd libgtest to Makefile to unbreak OSS build
Viswanath Sivakumar [Tue, 13 Jan 2015 18:57:03 +0000 (10:57 -0800)]
Add libgtest to Makefile to unbreak OSS build

Summary:
SpookyHashTest now needs libgtestmain to be linked
(https://phabricator.fb.com/D1775555).

https://ci-builds.fb.com/job/folly/1570/console

Test Plan:
Don't have Ubuntu setup, but this should fix it. Will kick off jenkins
build.

Reviewed By: andrewjcg@fb.com

Subscribers: folly-diffs@

FB internal diff: D1779604

Signature: t1:1779604:1421174608:de865529d728e943288b52c0d63ebb712eda094f

Blame Revision: D1775555

9 years agomove Futures from folly::wangle to folly
James Sedgwick [Mon, 12 Jan 2015 14:48:32 +0000 (06:48 -0800)]
move Futures from folly::wangle to folly

Summary: Namespace change. Next up is to extract the Executors into folly/executors/

Test Plan: wait for contbuild

Reviewed By: davejwatson@fb.com

Subscribers: jsedgwick, trunkagent, fbcode-common-diffs@, chaoyc, search-fbcode-diffs@, lars, davejwatson, ruibalp, hero-diffs@, zeus-diffs@, andrewcox, vikas, mcduff, cold-storage-diffs@, unicorn-diffs@, ldbrandy, targeting-diff-backend@, netego-diffs@, abirchall, fugalh, adamsyta, atlas2-eng@, chenzhimin, mpawlowski, alandau, bmatheny, adityab, everstore-dev@, zhuohuang, mwa, jgehring, prometheus-diffs@, smarlow, akr, bnitka, jcoens, benj, laser-diffs@, zhguo, jying, darshan, micha, apodsiadlo, alikhtarov, fuegen, dzhulgakov, jeremyfein, mshneer, folly-diffs@, wch, lins, tingy, hannesr, maxwellsayles

FB internal diff: D1772779

Tasks: 5960242

Signature: t1:1772779:1420751149:bc0b9220be25f1d46d9cef3fdeaa9c3681217aff

9 years agofolly: make remaining TARGETS files auto converitble to BUCK files
Andrew Gallagher [Sat, 10 Jan 2015 03:25:31 +0000 (19:25 -0800)]
folly: make remaining TARGETS files auto converitble to BUCK files

Summary: Also add the `@buckify` tag to keep these automatically synced.

Test Plan: built and tested with buck and fbconfig/fbmake

Reviewed By: robbert@fb.com

Subscribers: trunkagent, sdwilsh, fugalh, folly-diffs@, jsedgwick

FB internal diff: D1775555

Signature: t1:1775555:1420840948:e9a2e86379be71b7d953fa53a727e51d2541b011

9 years agofolly: Bits: make bitsPerBlock 64 bit back
Lucian Grijincu [Sat, 10 Jan 2015 01:18:36 +0000 (17:18 -0800)]
folly: Bits: make bitsPerBlock 64 bit back

Summary: D1770613 made bitsPerBlock 32 bit. Sadpanda.

Test Plan: _bin/unicorn/diskindex4/test/doc_map_test --gtest_filter=DocMap/DocMapTest.Deleted/23

Reviewed By: meyering@fb.com

Subscribers: net-systems@, folly-diffs@

FB internal diff: D1776343

Tasks: 5968993

Signature: t1:1776343:1420852923:f35166dd9023a701ff16467710131f821810215a

Blame Revision: D1770613

9 years agofolly/dynamic-inl.h: avoid -Wsign-compare error
Jim Meyering [Wed, 7 Jan 2015 16:16:07 +0000 (08:16 -0800)]
folly/dynamic-inl.h: avoid -Wsign-compare error

Summary:
* folly/dynamic-inl.h (format): Add an explicit
int-to-size_t cast (that is ok because we've just ensured
it is non-negative) to avoid this error from gcc-4.9:

folly/dynamic-inl.h:953:29: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo

Reviewed By: delong.j@fb.com

Subscribers: trunkagent, folly-diffs@

FB internal diff: D1773242

Tasks: 5941250

Signature: t1:1773242:1420822301:b1e3c065cd25728c77957ce9e1f52e884ba8693b

9 years agofolly: ProducerConsumerQueue: avoid many -Wsign-compare errors
Jim Meyering [Wed, 7 Jan 2015 21:45:19 +0000 (13:45 -0800)]
folly: ProducerConsumerQueue: avoid many -Wsign-compare errors

Summary:
There were many templates instantiated with signed types.
Changing them to unsigned avoids the compilation failures
noted below.  However, we'll have to watch arc-diff-spawned
tests for new failures, just in case.

This is by far the largest undecomposable patch of those
I've written for this task so far.  It is possible that
some subset of these changes accomplishes the same goal,
but once I managed to get a successful compilation, I have
only re-reviewed it once and did not try to shrink it.

Test Plan:
Without these changes, we would get the following 32 errors from gcc-4.9:
https://phabricator.fb.com/P19692642
With them, (and all of the other patches attached to the parent task,
all of fbcode compiles and passes its tests (modulo preexisting
failures and aborts).

Reviewed By: delong.j@fb.com

Subscribers: trunkagent, folly-diffs@

FB internal diff: D1773461

Tasks: 5941250

Signature: t1:1773461:1420821964:61635f3a2efc95e8d4457c36e7a5ee3a0a50df23

9 years agomove wangle/futures to futures
James Sedgwick [Fri, 9 Jan 2015 16:27:02 +0000 (08:27 -0800)]
move wangle/futures to futures

Summary:
First step of moving futures out of wangle into folly

Namespace change will be another diff

This was just a straight codemod of "wangle/futures" to "futures"

Test Plan: wait for contbuild

Reviewed By: davejwatson@fb.com

Subscribers: trunkagent, fbcode-common-diffs@, chaoyc, search-fbcode-diffs@, lars, ruibalp, hero-diffs@, zeus-diffs@, vikas, mcduff, hitesh, cold-storage-diffs@, unicorn-diffs@, ldbrandy, targeting-diff-backend@, netego-diffs@, fugalh, adamsyta, atlas2-eng@, alandau, apollo-diffs@, bmatheny, adityab, everstore-dev@, zhuohuang, sweeney, mwa, jgehring, prometheus-diffs@, smarlow, akr, bnitka, jcoens, zhguo, jying, darshan, apodsiadlo, alikhtarov, fuegen, dzhulgakov, alihussains, jeremyfein, mshneer, folly-diffs@, wch, lins, tingy, maxwellsayles, hannesr

FB internal diff: D1772041

Tasks: 5960242

Signature: t1:1772041:1420739169:36126b1264c5d1747d241921d02b13e306c73fe1

9 years agofolly/Bits.h (BitIterator): avoid -Wsign-compare error
Jim Meyering [Wed, 7 Jan 2015 03:25:48 +0000 (19:25 -0800)]
folly/Bits.h (BitIterator): avoid -Wsign-compare error

Summary:
* folly/Bits.h (BitIterator) [bitOffset_]: Change type of this
member from ssize_t to "unsigned int".
(bitsPerBlock): Change return type from size_t to "unsigned int".
These changes avoid some -Wsign-compare-highlighted issues, e.g.,
folly/Bits.h:456:18: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo

I've also run "fbmake runtests", and it failed precisely the way it does
without this patch.

Reviewed By: andrei.alexandrescu@fb.com

Subscribers: trunkagent, net-systems@, folly-diffs@

FB internal diff: D1770613

Tasks: 5941250

Signature: t1:1770613:1420757397:7ee7e5de500c8991af2597a6245d12d8f286b4b7

9 years agofolly: fix many -Wsign-compare warning/errors reported by gcc-4.9
Jim Meyering [Tue, 6 Jan 2015 17:33:03 +0000 (09:33 -0800)]
folly: fix many -Wsign-compare warning/errors reported by gcc-4.9

Summary:
With the upgrade to gcc-4.9 fbcode's default is to enable
-Wsign-compare by default.  That exposes nontrivial technical debt.
This is part of that clean-up.  Some of these changes fix the problem
where there's an "int" for-loop index, yet an unsigned limit.
The fix is to use an unsigned type when the limit is also unsigned.
I usually choose size_t because of the general recommendation (when
writing portable code) to avoid size-tied types like uint32_t and
uint64_t unless you have a very good reason to require them.

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 tao/server && fbmake dbgo

Also, run this, compiling and running tests with gcc-4.8.1.
Verify that there are no more failures than without this patch:
fbmake opt -k && fbmake runtests_opt
Here's the tail of that process, (same with and without the patch):
Summary (total time 47.45s):
PASS: 1949
FAIL: 1
SKIP: 0
FATAL: 9
TIMEOUT: 0

Reviewed By: hans@fb.com

Subscribers: trunkagent, fugalh, njormrod, folly-diffs@

FB internal diff: D1766722

Tasks: 5941250

Signature: t1:1766722:1420762240:a8545648ddb4fd0b2adf0d3147a84409c0f706a8

9 years ago(folly) Account for different vsnprintf behavior on OSX in test
Hans Fugal [Thu, 8 Jan 2015 22:55:34 +0000 (14:55 -0800)]
(folly) Account for different vsnprintf behavior on OSX in test

Summary: Apparently there is some dispute about the correct thing for `snprintf(buf, len, "bogus%", "foo")` to return. OSX says 5, Linux says -1. The code in `folly/String.cpp` depends on -1 to throw the exception this test was expecting.

Test Plan: make check on OSX

Reviewed By: chip@fb.com

Subscribers: exa, folly-diffs@

FB internal diff: D1770970

Tasks: 5936226

Signature: t1:1770970:1420680750:bafae2aa8327a52013e68af64a163323244ca03b

9 years ago(folly) make check on OSX Yosemite (10.10)
Hans Fugal [Thu, 8 Jan 2015 22:49:01 +0000 (14:49 -0800)]
(folly) make check on OSX Yosemite (10.10)

Summary:
This switches from gcc-4.9 provided by Homebrew to the default g++ (clang) from Yosemite.

$ g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix

Absolute path for double-conversion, so make in `test/` works.

gtest-1.7.0 (Using 1.6.0 causes compilation errors in Yosemite)

Various portability fixes.

Enhancements/fixes to `configure.ac` and associated source code for better portability.

Test Plan:
It builds and runs (yay)
Two tests fail, not sure whether that's specific to osx. Will investigate and make any fixes in a follow-up diff

Reviewed By: pgriess@fb.com

Subscribers: trunkagent, folly-diffs@, exa

FB internal diff: D1768669

Tasks: 5936226

Signature: t1:1768669:1420728580:dd6919c21e0edf30788e523b16e3a5b923e2d7f0

9 years agoavoid std::_Hash_impl
Hans Fugal [Thu, 8 Jan 2015 22:46:26 +0000 (14:46 -0800)]
avoid std::_Hash_impl

Summary:
Default Yosemite clang has no `std::_Hash_impl`, which is an internal implementation detail anyway.

@davejwatson you might have a different suggestion about how to implement this without that function, or how to test if it exists and do this only if it doesn't. This is probably not the most efficient approach, since it copies the string.

Test Plan:
builds
inspection
fbgs doesn't turn up many results (only recent wangle ssl code really) so I don't think this will be a big perf regression if we just go with it. But if I'm wrong, we can gate it on `#if __APPLE__` or something.

Reviewed By: davejwatson@fb.com

Subscribers: folly-diffs@, fugalh, exa, davejwatson

FB internal diff: D1767052

Signature: t1:1767052:1420738784:e219ebff7aec8682b24c15a03b47077e1559c1ab

9 years agoMini-refactoring prompted by https://phabricator.fb.com/D1770460
Andrei Alexandrescu [Thu, 8 Jan 2015 18:59:51 +0000 (10:59 -0800)]
Mini-refactoring prompted by https://phabricator.fb.com/D1770460

Summary: I got obliged into this one :o).

Test Plan: runtests

Reviewed By: meyering@fb.com

Subscribers: njormrod, folly-diffs@

FB internal diff: D1772328

Signature: t1:1772328:1420744114:2b81e46d77800d247293cb667bbef86e9d6d4755

9 years agofolly/stats/Histogram-defs.h: avoid -Wsign-compare error
Jim Meyering [Wed, 7 Jan 2015 19:11:07 +0000 (11:11 -0800)]
folly/stats/Histogram-defs.h: avoid -Wsign-compare error

Summary:
* folly/stats/Histogram-defs.h (HistogramBuckets): Take the unusual
approach of converting "numBuckets" to signed, because we cannot
cast "max-min" (a known positive value) to an unsigned type --
we don't have an unsigned variant of ValueType.
This avoids the following error from gcc-4.9:

folly/stats/Histogram-defs.h:41:31: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo

Reviewed By: ldbrandy@fb.com

Subscribers: trunkagent, net-systems@, folly-diffs@

FB internal diff: D1770129

Tasks: 5941250

Signature: t1:1770129:1420745311:c447e59f1730abafdf0b962e70f0886ae1d48db1

9 years agofolly/.../FileUtilDetail.h: avoid -Wsign-compare warnings
Jim Meyering [Tue, 6 Jan 2015 17:24:30 +0000 (09:24 -0800)]
folly/.../FileUtilDetail.h: avoid -Wsign-compare warnings

Summary:
* folly/detail/FileUtilDetail.h (wrapvFull): Change type of result
variable from ssize_t to size_t: this required changing r == -1 to
r == (size_t)-1.

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo
Also run fbmake runtests, and confirm that the results are
the same with and without this change.

Reviewed By: lucian@fb.com

Subscribers: folly-diffs@

FB internal diff: D1772171

Tasks: 5941250

Signature: t1:1772171:1420743142:1f9e02006e2d77a0c9451bae7965fb28617d95d6

9 years agofolly/wangle/futures/Future-inl.h: avoid -Wsign-compare errors
Jim Meyering [Tue, 6 Jan 2015 23:46:38 +0000 (15:46 -0800)]
folly/wangle/futures/Future-inl.h: avoid -Wsign-compare errors

Summary:
* folly/wangle/futures/Future-inl.h (whenAll): Do not compare
signed (std::distance) with unsigned(size_t): add an assertion
to eliminate the possibility of negative, then assign to a new
size_t "n".

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo

Reviewed By: jsedgwick@fb.com

Subscribers: trunkagent, fugalh, folly-diffs@

FB internal diff: D1770668

Tasks: 5941250

Signature: t1:1770668:1420736965:fc722657a2ec523052fd96c33d65d5ca24aae61c

9 years agofolly/FBString.h: avoid -Wsign-compare error
Jim Meyering [Wed, 7 Jan 2015 16:02:21 +0000 (08:02 -0800)]
folly/FBString.h: avoid -Wsign-compare error

Summary:
* folly/FBString.h (operator>>): Since istream.width() is signed,
handle the case of a negative width. This avoids risk that "n"
will be less than 0 when compared against unsigned "extracted".
However, to suppress the following warning, we must also explicitly
convert "n" to size_t before comparing:

folly/FBString.h:2326:22: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo

Reviewed By: andrei.alexandrescu@fb.com

Subscribers: trunkagent, net-systems@, njormrod, folly-diffs@

FB internal diff: D1770460

Tasks: 5941250

Signature: t1:1770460:1420679684:b262eb31e6511b6311bebf0fbc29099471648b36

9 years agostop returning move(...) when unnecessary
James Sedgwick [Thu, 8 Jan 2015 16:42:04 +0000 (08:42 -0800)]
stop returning move(...) when unnecessary

Summary: as discussed in another diff, this might help with NRVO

Test Plan: unit

Reviewed By: hans@fb.com

Subscribers: trunkagent, fugalh, folly-diffs@

FB internal diff: D1764921

Signature: t1:1764921:1420677311:c6b63d7bf04c0e17283117b3edef798c288e5fbb

9 years agofix shadowed variables
James Sedgwick [Thu, 8 Jan 2015 16:12:39 +0000 (08:12 -0800)]
fix shadowed variables

Summary: as above, fixes builds

Test Plan: compiled thrift + mcrouter

Reviewed By: seanc@fb.com

Subscribers: seanc, fugalh, folly-diffs@

FB internal diff: D1771910

Signature: t1:1771910:1420733490:7f33e57a5853395cab786e5d35d4c15c75a15c5a

9 years agodoxygen comments for Try
James Sedgwick [Thu, 8 Jan 2015 15:51:15 +0000 (07:51 -0800)]
doxygen comments for Try

Summary:
One header at a time, starting with the small fry

I'm allowed to drink while I do this right? Good, because I don't think I ever had a choice.

Test Plan: generated doxygen and looked decent http://home.fburl.com/~jsedgwick/html/classfolly_1_1wangle_1_1Try.html

Reviewed By: davejwatson@fb.com

Subscribers: trunkagent, fugalh, njormrod, folly-diffs@

FB internal diff: D1677730

Tasks: 5480262

Signature: t1:1677730:1415899240:bdd03569a82be1c8def8c13786eae39b4a2a2f94

9 years agoexception_ptr -> exception_wrapper migration
James Sedgwick [Thu, 8 Jan 2015 15:48:23 +0000 (07:48 -0800)]
exception_ptr -> exception_wrapper migration

Summary:
integrate exception_wrapper everywhere, and deprecate public methods that take ptrs directly to discourage their use
note that this will break for throwing non-exceptions, which is probably fine

this change opens the door to interesting optimizations for those interested, e.g. Future::then<Exn1, Exn2>(/* func throwing Exn1 and Exn2 */) that autowraps the given types into the resultant future

new benchmark:
```
throwAndCatch                                               23.69us   42.21K
throwAndCatchWrapped                             119.53%    19.82us   50.45K
throwWrappedAndCatchWrapped                      350.16%     6.77us  147.80K
```

Test Plan: existing unit tests, suspected potential perf wins confirmed by benchmark, will wait for windtunnel to see other wins/regressions

Reviewed By: hans@fb.com

Subscribers: search-fbcode-diffs@, apodsiadlo, alikhtarov, andrii, trunkagent, fugalh, njormrod, folly-diffs@, bmatheny

FB internal diff: D1644912

Signature: t1:1644912:1420731849:3dc658dc03bfd6e75d61158808c7dad96092ecfb

9 years agofolly/String-inl.h (humanify): avoid -Wsign-compare error
Jim Meyering [Wed, 7 Jan 2015 16:05:04 +0000 (08:05 -0800)]
folly/String-inl.h (humanify): avoid -Wsign-compare error

Summary:
* folly/String-inl.h (humanify): Count with a signed type.
Otherwise, gcc-4.9 fails with e.g.,
folly/String-inl.h:596:33: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
folly/String-inl.h:601:32: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo

Reviewed By: philipp@fb.com

Subscribers: trunkagent, folly-diffs@

FB internal diff: D1770451

Tasks: 5941250

Signature: t1:1770451:1420704354:c841ca453a5586fbf474535ca26cef17f95427dd

9 years agofolly/AtomicHashArray: use an unsigned type for each of two counters
Jim Meyering [Tue, 6 Jan 2015 20:40:30 +0000 (12:40 -0800)]
folly/AtomicHashArray: use an unsigned type for each of two counters

Summary:
* folly/AtomicHashArray.h (numEntries_, numPendingEntries_):
Use an unsigned type for each of these.  They count things, can
never go below 0, and are compared to unsigned values.
Otherwise, gcc-4.9 would emit this:
folly/AtomicHashArray-inl.h:153:38: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo

Reviewed By: philipp@fb.com

Subscribers: trunkagent, folly-diffs@

FB internal diff: D1770695

Tasks: 5941250

Signature: t1:1770695:1420683354:bfa4775bc2f8aab74e34772308a5c8b1779243b8

9 years agofolly/AtomicHashMap-inl.h: avoid -Wsign-compare warning/error (easy)
Jim Meyering [Tue, 6 Jan 2015 20:45:11 +0000 (12:45 -0800)]
folly/AtomicHashMap-inl.h: avoid -Wsign-compare warning/error (easy)

Summary:
* folly/AtomicHashMap-inl.h (insertInternal): Do not declare
nextMapIdx to be signed ("int"), since we compare it against
variables of unsigned type.  Otherwise, gcc-4.9 would give this
diagnostic:
folly/AtomicHashMap-inl.h:99:18: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
complaining about this comparison:
if (nextMapIdx >= kNumSubMaps_ ||

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo

Reviewed By: philipp@fb.com

Subscribers: folly-diffs@

FB internal diff: D1770683

Tasks: 5941250

Signature: t1:1770683:1420683505:4452c7cb4f14f098be089601be906884036348ed

9 years agoHistogram and Timeseries vs gcc-4.9 and -Wsign-compare
Jim Meyering [Tue, 6 Jan 2015 18:00:14 +0000 (10:00 -0800)]
Histogram and Timeseries vs gcc-4.9 and -Wsign-compare

Summary:
Address multiple -Werror=sign-compare issues exposed when building
tao with gcc-4.9.
In most of these changes I've changed the type of the index in
a for-loop from int to size_t.  The important thing is to use
an unsigned type when the limit is also unsigned.  I choose size_t
because the general recommendation (when writing portable code)
to avoid size-tied types like uint32_t and uint64_t unless you
have a very good reason to require them.

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 tao/server && fbmake dbgo

Reviewed By: andrei.alexandrescu@fb.com

Subscribers: trunkagent, net-systems@, folly-diffs@

FB internal diff: D1766651

Tasks: 5941250

Signature: t1:1766651:1420594537:56ef53ca233e1649469db9570942c1d5dd47cf6d

9 years agofolly/test/ForeachTest.cpp: avoid -Wsign-compare error
Jim Meyering [Wed, 7 Jan 2015 04:54:29 +0000 (20:54 -0800)]
folly/test/ForeachTest.cpp: avoid -Wsign-compare error

Summary:
* folly/test/ForeachTest.cpp: Change a "1" to "1U", so it matches
the signedness of the size_t upper bound.
Otherwise, gcc-4.9 fails with e.g.,
folly/Foreach.h:194:16: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo

Reviewed By: andrei.alexandrescu@fb.com

Subscribers: folly-diffs@

FB internal diff: D1770603

Tasks: 5941250

Signature: t1:1770603:1420679246:56ef62ac7fa4413a4ad6310c3381a12bdc59e64c

9 years agofolly/stats/BucketedTimeSeries-defs.h: avoid -Wsign-compare error
Jim Meyering [Wed, 7 Jan 2015 17:30:43 +0000 (09:30 -0800)]
folly/stats/BucketedTimeSeries-defs.h: avoid -Wsign-compare error

Summary:
* folly/stats/BucketedTimeSeries-defs.h (BucketedTimeSeries):
Assume that maxDuration is never negative, and cast the signed
duration_.count() to size_t, to avoid this error from gcc-4.9:

folly/stats/BucketedTimeSeries-defs.h:38:18: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo

Reviewed By: andrei.alexandrescu@fb.com

Subscribers: trunkagent, net-systems@, folly-diffs@

FB internal diff: D1770171

Tasks: 5941250

Signature: t1:1770171:1420669115:61e6b8d3248f88b25736322c7066af015209fba5

9 years agofolly/Format-inl.h: use the correct type for fwrite return value (easy)
Jim Meyering [Wed, 7 Jan 2015 16:09:26 +0000 (08:09 -0800)]
folly/Format-inl.h: use the correct type for fwrite return value (easy)

Summary:
* folly/Format-inl.h (folly): fwrite returns size_t, not ssize_t.
Fixing this avoids the following diagnostic from gcc-4.9:
folly/Format-inl.h:299:11: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo

Reviewed By: philipp@fb.com

Subscribers: trunkagent, net-systems@, folly-diffs@

FB internal diff: D1770155

Tasks: 5941250

Signature: t1:1770155:1420668733:62593231d35f5874521dba575f23b68891b2a4f9

9 years agofolly/Format-inl.h: avoid -Wsign-compare error
Jim Meyering [Wed, 7 Jan 2015 16:13:57 +0000 (08:13 -0800)]
folly/Format-inl.h: avoid -Wsign-compare error

Summary:
* folly/Format-inl.h (IndexableTraitsSeq::at): Add an explicit
int-to-size_t cast (ok here, since we've just confirmed
that the value is not negative) to avoid this error from gcc-4.9:

folly/Format-inl.h:947:29: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo

Reviewed By: tjackson@fb.com

Subscribers: trunkagent, net-systems@, folly-diffs@

FB internal diff: D1770193

Tasks: 5941250

Signature: t1:1770193:1420670569:83ac19c2ca8cd408d7c86d7dce49e2d4b418941a

9 years agofolly/test/SpinLockTest.cpp: avoid -Wsign-compare error (trivial)
Jim Meyering [Wed, 7 Jan 2015 05:15:27 +0000 (21:15 -0800)]
folly/test/SpinLockTest.cpp: avoid -Wsign-compare error (trivial)

Summary:
* folly/test/SpinLockTest.cpp (trylockTestThread):
Change parameter type from int to size_t, to fix these:
folly/test/SpinLockTest.cpp:67:25: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
folly/test/SpinLockTest.cpp:82:60: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo

Reviewed By: philipp@fb.com

Subscribers: net-systems@, folly-diffs@

FB internal diff: D1770564

Tasks: 5941250

Signature: t1:1770564:1420674373:fa3020398e2df66590eb71f798419b6f555d07c4

9 years agoFix CPUObserver test
Dave Watson [Wed, 7 Jan 2015 22:55:17 +0000 (14:55 -0800)]
Fix CPUObserver test

Summary: CPUObserver observe events happen in different threads than the IOThreadPool ones.

Test Plan: fbconfig folly/wangle/concurrent/test && fbmake runtests --stress-runs 48

Reviewed By: jsedgwick@fb.com

Subscribers: doug, fugalh, folly-diffs@

FB internal diff: D1769345

Tasks: 5948465

Signature: t1:1769345:1420654316:196121ca30c905497a0acade05b9d877c98f6eeb

9 years agofolly/wangle/bootstrap/ServerBootstrap.h: avoid -Wsign-compare error (trivial)
Jim Meyering [Wed, 7 Jan 2015 21:40:41 +0000 (13:40 -0800)]
folly/wangle/bootstrap/ServerBootstrap.h: avoid -Wsign-compare error (trivial)

Summary:
* folly/wangle/bootstrap/ServerBootstrap.h:
Change type of a for-loop index from int to size_t.

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo

Reviewed By: jsedgwick@fb.com

Subscribers: fugalh, folly-diffs@

FB internal diff: D1770091

Tasks: 5941250

Signature: t1:1770091:1420667597:fbe9a5ba56a0e34e0480c82c8fb61128406ded95

9 years agoAHM ASAN test adjustment
Nicholas Ormrod [Wed, 7 Jan 2015 17:31:31 +0000 (09:31 -0800)]
AHM ASAN test adjustment

Summary:
The AHA-insert-race test case (a) does a LOT of iterations, and
(b) allocated and deallocates a lot of memory on each iteration.

The long iterations, by themselves, take 8s, and should be reduced.
Further, ASAN errors on these tests, since it needs to hold on to memory
for a bit of time and ends up OOMing.

Test Plan:
fbconfig -r 'folly' '--platform-all=gcc-4.8.1-glibc-2.17-fb' '--sanitize=address'
fbmake runtests Ahm.atomic_hash_array_insert_race

Reviewed By: robbert@fb.com

Subscribers: sdwilsh, folly-diffs@

FB internal diff: D1767334

Tasks: 5941888

Signature: t1:1767334:1420612386:4d6f4067b30d1cb7d20bcfeb0f31fac1339ead20

9 years agofolly/small_vector.h: avoid -Wsign-compare error
Jim Meyering [Tue, 6 Jan 2015 23:32:33 +0000 (15:32 -0800)]
folly/small_vector.h: avoid -Wsign-compare error

Summary:
* folly/small_vector.h (moveToUninitialized): Do not mix
signed and unsigned for-loop index/limit.  Instead, eliminate
the intermediate "count" altogether and iterate as long as
"first" is not equal to "last". Otherwise, gcc-4.9 fails with e.g.,
folly/small_vector.h:115:18: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo

Reviewed By: soren@fb.com

Subscribers: trunkagent, folly-diffs@

FB internal diff: D1767844

Tasks: 5941250

Signature: t1:1767844:1420601608:987fd7f7d44197ed9919910c9b559b37fbe421b6

9 years agofolly/FBVector.h: avoid -Wsign-compare error (simple)
Jim Meyering [Wed, 7 Jan 2015 01:21:42 +0000 (17:21 -0800)]
folly/FBVector.h: avoid -Wsign-compare error (simple)

Summary:
* folly/FBVector.h (make_window): Declare "tail" to be
explicitly of the same type as "n".  Otherwise, we'd
use the type of std::distance, which is unsigned, and
then compare that against "n" of type "size_type", which
is unsigned, and we'd get this from gcc-4.9:
folly/FBVector.h:1276:14: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo

Reviewed By: philipp@fb.com, andrei.alexandrescu@fb.com

Subscribers: trunkagent, njormrod, folly-diffs@

FB internal diff: D1768346

Tasks: 5941250

Signature: t1:1768346:1420594452:654dac805bb46f7c6a38b4e4102e4004720d6835

9 years agofolly/test/RangeTest.cpp: avoid -Wsign-compare error (trivial)
Jim Meyering [Wed, 7 Jan 2015 01:08:20 +0000 (17:08 -0800)]
folly/test/RangeTest.cpp: avoid -Wsign-compare error (trivial)

Summary:
* folly/test/RangeTest.cpp (NeedleFinderTest): Declare for-loop
index to be of type size_t.  OTherwise, gcc-4.9 fails:
folly/test/RangeTest.cpp:910:23: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo

Reviewed By: philipp@fb.com

Subscribers: folly-diffs@

FB internal diff: D1768279

Tasks: 5941250

Signature: t1:1768279:1420593237:246040eebd40e313bdb19799bb11d6639f1481de

9 years agofolly/experimental/test/BitsBenchmark.cpp: avoid -Wsign-compare error
Jim Meyering [Tue, 6 Jan 2015 23:29:48 +0000 (15:29 -0800)]
folly/experimental/test/BitsBenchmark.cpp: avoid -Wsign-compare error

Summary:
* folly/experimental/test/BitsBenchmark.cpp (benchmarkSet):
Another s/int/size_t/ change to type of for-loop index, to match
the type of the loop's upper bound.

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo

Reviewed By: davejwatson@fb.com

Subscribers: folly-diffs@

FB internal diff: D1767853

Tasks: 5941250

Signature: t1:1767853:1420587945:f32a0ef33f6c5fa75598ecb114a243f83b31e550

9 years agofolly/wangle/channel/ChannelPipeline.h: avoid -Wsign-compare errors (trivial)
Jim Meyering [Tue, 6 Jan 2015 23:15:46 +0000 (15:15 -0800)]
folly/wangle/channel/ChannelPipeline.h: avoid -Wsign-compare errors (trivial)

Summary:
* folly/wangle/channel/ChannelPipeline.h: Declare for-loop indices
to be of type size_t(not int), to match size of upper bound.
Otherwise, gcc-4.9 fails with e.g.,
folly/wangle/channel/ChannelPipeline.h:126:23: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo

Reviewed By: davejwatson@fb.com

Subscribers: fugalh, folly-diffs@

FB internal diff: D1767783

Tasks: 5941250

Signature: t1:1767783:1420587925:d662b75e6a62ebd5bacdde28ad6e1da22ef777ac

9 years agofolly/gen/Parallel-inl.h: trivial -Wsign-compare fix
Jim Meyering [Tue, 6 Jan 2015 22:28:49 +0000 (14:28 -0800)]
folly/gen/Parallel-inl.h: trivial -Wsign-compare fix

Summary:
[just like https://phabricator.fb.com/D1767160 --
I don't know why I didn't see this the first time]
* folly/gen/Parallel-inl.h (folly): Use a for-loop index of type
size_t (not "int") to match type of upper bound.
Otherwise, gcc-4.9 fails with this:
folly/gen/Parallel-inl.h:242:27: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo

Reviewed By: philipp@fb.com

Subscribers: folly-diffs@

FB internal diff: D1767520

Signature: t1:1767520:1420583501:121f7212f78774adb6ca7cf67cbab83bf604cbbe

9 years agofolly/gen/Parallel-inl.h: trivial -Wsign-compare fix
Jim Meyering [Tue, 6 Jan 2015 20:48:38 +0000 (12:48 -0800)]
folly/gen/Parallel-inl.h: trivial -Wsign-compare fix

Summary:
* folly/gen/Parallel-inl.h (folly): Use a for-loop index of type
size_t (not "int") to match type of upper bound.
Otherwise, gcc-4.9 fails with this:
folly/gen/Parallel-inl.h:242:27: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo

Reviewed By: davejwatson@fb.com

Subscribers: folly-diffs@

FB internal diff: D1767160

Tasks: 5941250

Signature: t1:1767160:1420577886:6acfb7f6d50ed715dcf4058841aeabc39fa99cbc

9 years agoFix HHWheelTimer compilation bug in libc++ build
Peter Griess [Tue, 6 Jan 2015 20:30:32 +0000 (12:30 -0800)]
Fix HHWheelTimer compilation bug in libc++ build

Summary:
- Manually swap bucket_ entries in HHWheelTimer to work around a bug in
libc++

Test Plan:
- fbconfig -r folly/io/async && fbmake runtests --extended-tests
- Sync to OS X and build there

Reviewed By: davejwatson@fb.com

Subscribers: trunkagent, doug, seanc, folly-diffs@

FB internal diff: D1766601

Signature: t1:1766601:1420566916:24a2911e997ee04f0934884bdf7b82345cb2b752

9 years agojoin
Hans Fugal [Tue, 6 Jan 2015 20:22:52 +0000 (12:22 -0800)]
join

Summary:
Fixes T5922800
(I think)

Test Plan:
TBH I don't know why detaching a temporary thread variable might cause the program to abort but this seems to be the most likely cause so I'm making this change and we'll see in a day or two if it fixes it.

The test still passes and doesn't hang

Reviewed By: davejwatson@fb.com

Subscribers: fugalh, exa, folly-diffs@

FB internal diff: D1764374

Tasks: 5922800

Signature: t1:1764374:1420485233:2e4c81776ef6b6bdae18fbf2e99f0deea37b7879

9 years agofolly/Format-inl.h: fix gcc-4.9-exposed shadowing warning/error (trivial)
Jim Meyering [Tue, 6 Jan 2015 17:58:36 +0000 (09:58 -0800)]
folly/Format-inl.h: fix gcc-4.9-exposed shadowing warning/error (trivial)

Summary:
* folly/Format-inl.h (BaseFormatter): Move decls of P and END down
past the shadowed decls.  Otherwise, gcc-4.9 would emit this:
./folly/Format-inl.h:209:10: error: declaration of 'p' shadows a previous local [-Werror=shadow-local]
./folly/Format-inl.h:202:8: error: shadowed declaration is here [-Werror=shadow-local]
./folly/Format-inl.h:210:10: error: declaration of 'end' shadows a previous local [-Werror=shadow-local]
./folly/Format-inl.h:203:8: error: shadowed declaration is here [-Werror=shadow-local]

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 tao/server && fbmake dbgo

Reviewed By: andrewjcg@fb.com

Subscribers: trunkagent, net-systems@, folly-diffs@

FB internal diff: D1766673

Tasks: 5941250

Signature: t1:1766673:1420569376:22c5c3a012715e479b27ba6f0bde1a3b079a3be3

9 years agoThread Observer
Dave Watson [Tue, 6 Jan 2015 18:36:31 +0000 (10:36 -0800)]
Thread Observer

Summary: Observer methods, so users of IOThreadPoolExecutor can do stuff when threads are added/removed.  As a use case, previously the thrift server only used the threads already started when it started up, and assumed iothreadpool was never resized.

Test Plan: Added several unittests

Reviewed By: jsedgwick@fb.com

Subscribers: trunkagent, doug, fugalh, alandau, bmatheny, mshneer, folly-diffs@

FB internal diff: D1753861

Signature: t1:1753861:1420236825:54cbdfee0efb3b97dea35faba29c134f2b10a480

9 years agofolly/Range.cpp: avoid -Werror=sign-compare error with gcc-4.9
Jim Meyering [Tue, 6 Jan 2015 00:53:50 +0000 (16:53 -0800)]
folly/Range.cpp: avoid -Werror=sign-compare error with gcc-4.9

Summary:
* folly/Range.cpp (scanHaystackBlock): This method mistakenly
declared its "idx" (aka blockStartIdx) parameter to have signed type.
It is logically an unsigned type and is compared only with other
variables of unsigned type, so make it unsigned.
Here's the diagnostic:
folly/Range.cpp:202:44: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
folly/Range.cpp: In instantiation of 'size_t folly::detail::scanHaystackBlock(folly::StringPiece, folly::StringPiece, int64_t) [with bool HAYSTACK_ALIGNED = true; size_t = long unsigned int; folly::StringPiece = folly::Range<const char*>; int64_t = long int]':

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 tao/server && fbmake dbgo

Reviewed By: robbert@fb.com, philipp@fb.com

Subscribers: folly-diffs@

FB internal diff: D1765590

Signature: t1:1765590:1420506036:7cbe2c454ad1f018a1c0aa5112a38bed1b2ac673

9 years agofix 4.9 build
James Sedgwick [Tue, 6 Jan 2015 00:44:36 +0000 (16:44 -0800)]
fix 4.9 build

Summary:
see https://www.facebook.com/groups/738749156173702/permalink/798168656898418/

I suppressed "comparison between signed and unsigned integer expressions" warnings for this first pass because there a whole lot (dozens) of those. Do we suppress those with 4.8 or something? Never seen the warnings before.

I can't find anything in boost 1.57 docs/changelog indicating why implicit conversion of boost::optional<bool> -> bool doesn't compile anymore, but it doesn't.

Test Plan: fbconfig -r --platform-all gcc-4.9-glibc-2.20 --extra-cxxflags="-Wno-sign-compare" folly && fbmake opt && fbmake runtests_opt

Reviewed By: rhysparry@fb.com

Subscribers: trunkagent, fugalh, folly-diffs@

FB internal diff: D1765093

Signature: t1:1765093:1420500411:062acf841641c7f4142c9b48e8daa45327de6822

9 years ago(folly) osx bootstrap script
Hans Fugal [Tue, 6 Jan 2015 00:21:50 +0000 (16:21 -0800)]
(folly) osx bootstrap script

Summary:
This is a bootstrap script for building folly on osx. I attempted to make it Just Work™ for anyone who uses Homebrew (http://brew.sh/) but even if it doesn't work out of the box it should be instructive for the motivated developer on OSX.

Facebook:
In #5134151 Wangle used to not build, because something was using a futex. But that seems to have been rectified (or the build problems are hiding in headers that aren't used in the libfolly build).

I'll also update https://our.intern.facebook.com/intern/wiki/Folly/BuildingOnMac to point people to this script instead.

Test Plan:
Tested on my laptop which is running Yosemite (10.10.1)
Build, then inspect `otool -L .libs/*dylib`

Reviewed By: davejwatson@fb.com

Subscribers: folly-diffs@, exa

FB internal diff: D1765248

Tasks: 5134151

Signature: t1:1765248:1420500905:bc5da97a0446f502cb2badc85c9004ff0a62027a

9 years agofix bootstrap test on older kernels
Dave Watson [Mon, 5 Jan 2015 22:45:12 +0000 (14:45 -0800)]
fix bootstrap test on older kernels

Summary: another unittest that doesn't work without reuseport support, add a check

Test Plan: ran it on sandcastle187.prn2, works

Reviewed By: njormrod@fb.com

Subscribers: doug, fugalh, folly-diffs@

FB internal diff: D1764395

Tasks: 5931982

Signature: t1:1764395:1420490666:658aef148ebca9484534a0cebb228570e28f1002

9 years agofolly: AsyncServerSocket::getAddress: prefer IPv6
Sergey Doroshenko [Mon, 5 Jan 2015 19:00:41 +0000 (11:00 -0800)]
folly: AsyncServerSocket::getAddress: prefer IPv6

Summary:
Can't connect from ipv6-only cluster to ipv4/ipv6 service which uses different ports.

Facebook:
A lot of tests start a service, get its port, and try to connect to 127.0.0.1:port, which breaks
after this diff since the port corresponds to IPv6 address, not IPv4. Fixing this by changing
127.0.0.1 to ::1 in places found by sandcastle.

```
fbconfig servicerouter/aggregator/tests servicerouter/client/cpp/test common/fb303/cpp/test thrift/lib/cpp2/test unicorn/hotswap/test common/client_mgmt thrift/test servicerouter/client/swig/tests unicorn/async/test servicerouter/selection/tests
```

Test Plan:
```
$ ./fastcopy_server --dir . &
$ netstat -atnlp | grep LISTEN | grep fastcopy
tcp        0      0 0.0.0.0:65478               0.0.0.0:*                   LISTEN      9348/./fastcopy_ser
tcp        0      0 :::52793                    :::*                        LISTEN      9348/./fastcopy_ser
```

Reviewed By: philipp@fb.com

Subscribers: trunkagent, vkatich, fbcode-common-diffs@, chaoyc, search-fbcode-diffs@, davejwatson, andrewcox, mcduff, hitesh, unicorn-diffs@, alandau, mshneer, folly-diffs@, bmatheny, ps, soren

FB internal diff: D1760372

Tasks: 58688185886688

Signature: t1:1760372:1419992695:e7d254b2b8f730baefc169effa236b8daa9d846d

9 years agoFix use of SSL session TransportInfo after txn is detached
Viswanath Sivakumar [Mon, 5 Jan 2015 18:46:07 +0000 (10:46 -0800)]
Fix use of SSL session TransportInfo after txn is detached

Summary:
De-couple TransportInfo fields from SSL session structs to avoid
dangling pointers.

Facebook:
We sometimes lazily copy TransportInfo in handler after
detachClientTransaction for logging. If the socket is closed, then this
creates dangling pointers to some SSL structs. This is an attempt to fix
that.

This is similar to what @ajitb did in
https://phabricator.fb.com/D1666951 which had to be abandoned because of
memory overhead. Here, instead of copying the relevant fields per
transaction, we are only doing it once per session (shared_ptr), so the
memory overhead should be negligible.

Test Plan: Unit tests pass. Will canary

Reviewed By: afrind@fb.com

Subscribers: fugalh, bmatheny, ssl-diffs@, folly-diffs@, ajitb

FB internal diff: D1757318

Tasks: 58656515879508

Signature: t1:1757318:1420482488:9f5144b499eb2086cf2a80243328db5715b48f88

9 years agoReplace singleton names with type tags
Andrii Grynenko [Wed, 17 Dec 2014 04:33:44 +0000 (20:33 -0800)]
Replace singleton names with type tags

Summary: This change simplifies Singleton API (methods don't need to accept name) and the actual implementation. It also makes it similar to folly::ThreadLocalPtr. Additionally misspelled singleton name becomes compilation error, not runtime error. Some users were actually naming singletons, when that was neccessary, this should also be fixed.

Test Plan: unit tests for all touched projects

Reviewed By: chip@fb.com

Subscribers: trunkagent, fugalh, jsedgwick, fbcode-common-diffs@, mcduff, hitesh, mshneer, folly-diffs@

FB internal diff: D1744978

Signature: t1:1744978:1419282587:bd29dd8a70d7572530ac371a96a21764229bc397

9 years agofix __cxa_throw signature
Philip Pronin [Tue, 30 Dec 2014 10:20:41 +0000 (02:20 -0800)]
fix __cxa_throw signature

Summary: `__cxa_throw` signature didn't match C++ ABI (see 2.4.3 in http://refspecs.linuxfoundation.org/abi-eh-1.22.html), gcc 4.9 was complaining.

Test Plan: fbconfig -r folly && fbmake opt -j32

Reviewed By: soren@fb.com

Subscribers: folly-diffs@

FB internal diff: D1760492

Tasks: 5908365

Signature: t1:1760492:1420251038:6d04683f96ac889ff348ca0485420c975819b90b

9 years agoadd a UT for Wangle::Future for circular dependency
Nick Tchervenski [Tue, 30 Dec 2014 20:32:06 +0000 (12:32 -0800)]
add a UT for Wangle::Future for circular dependency

Summary:
Making sure Wangle can handle circular dependencies.
There was an actual code issue in September that cause a crash in Atlas
Adserver due to this. The issue has been since fixed and Adserver's code
has been changed to avoid such circular dependency. We're adding a unit
test for this case.

Unit test is added as per our conversation on the Wangle group: https://www.facebook.com/groups/715931878455430/permalink/770180369697247/

Test Plan:
Add the same test on a code base from Sep 20th, observe that it fails:
https://phabricator.fb.com/P19352007

Run the unit test on latest code base - it succeeds

Reviewed By: hans@fb.com

Subscribers: atlas2-eng@, fugalh, folly-diffs@, leizhao, mchughj, kit, mpechuk

FB internal diff: D1761006

Tasks: 5384229

Signature: t1:1761006:1420238204:74ffb3fe8b88a25a23ade8e0990e69d405ea7f1e

9 years agoFuture::within
Hans Fugal [Fri, 2 Jan 2015 22:36:42 +0000 (14:36 -0800)]
Future::within

Summary: For when you have a future that you want to complete within a duration, else raise a `TimedOut` exception.

Test Plan: new unit tests

Reviewed By: jsedgwick@fb.com

Subscribers: trunkagent, fugalh, exa, folly-diffs@

FB internal diff: D1756580

Tasks: 4548494

Signature: t1:1756580:1420215704:862f68816fc3a9d05a77077c439bec002aa29cf3

9 years agoImprove unit test output and logging to diagnose build breaks
Chip Turner [Wed, 31 Dec 2014 03:03:54 +0000 (19:03 -0800)]
Improve unit test output and logging to diagnose build breaks

Summary:
I can't repro the very frequent breakage we get from the unit
test framework, and it would be helpful to get the proper error messages
from it, so this adjusts the logging and changes a CHECK to an EXPECT to
get more data when the failure occurs.

Test Plan: runtests

Reviewed By: hans@fb.com

Subscribers: lins, anca, folly-diffs@

FB internal diff: D1761800

Tasks: 5870141

Signature: t1:1761800:1420226753:27a66fb0ce47cd57529e5fd0518550fb649c9eb5

9 years agoBump version to 21:0
Ajit Banerjee [Wed, 7 Jan 2015 20:24:42 +0000 (12:24 -0800)]
Bump version to 21:0

9 years agosome fixes for clang-3.5 compatibility
Bob Haarman [Tue, 30 Dec 2014 22:45:28 +0000 (14:45 -0800)]
some fixes for clang-3.5 compatibility

Summary:
Clang 3.5 performs more rigorous static analysis than compilers we've previously used, and accordingly comes up with some additional warnings. This diff fixes some of the issues clang-3.5 warns about.

Facebook:

Test Plan:
# after pulling in changes that allow clang-3.5 to be used
fbconfig --clang --with-project-version clang:3.5 -r common/memory && fbmake runtests_opt
fbconfig --clang --with-project-version clang:3.5 -r common/strings && fbmake runtests_opt
fbconfig --clang --with-project-version clang:3.5 folly/test && fbmake runtests_opt

Tests for common/strings and folly/test pass. common/memory has one test failure, which also occurs with clang-3.4, while eliminating a couple of test failures that clang-3.4 had.

Reviewed By: meyering@fb.com

Subscribers: fbcode-common-diffs@, sdwilsh, mathieubaudet, folly-diffs@

FB internal diff: D1761101

Signature: t1:1761101:1419976252:ff60166dc8986e1239f88012b5e552a7d204aede

9 years agoDon't use FOLLY_TLS on Android
Sean Cannella [Tue, 30 Dec 2014 18:01:11 +0000 (10:01 -0800)]
Don't use FOLLY_TLS on Android

Summary:
emutls as far as StaticMeta needs to use it is broken on
Android as well due to unspecified pthread_key cleanup order between the
emulated __thread and our manual uses of it. Use the alternative that we
use on __APPLE__ there as well.

Test Plan: compiled and ran consuming code on Android

Reviewed By: dancol@fb.com

Subscribers: fma, shikong, kmdent, benyluo, ranjeeth, subodh, folly-diffs@

FB internal diff: D1760569

Tasks: 52657545907613

Signature: t1:1760569:1419955865:afe8f35dadda85393492ac9331e9f62a74f4fdad

9 years agoAllow conversion from a type T to itself
Sarang Masti [Mon, 29 Dec 2014 22:39:03 +0000 (14:39 -0800)]
Allow conversion from a type T to itself

Summary: same as title

Test Plan: - fbconfig -r folly && fbmake runtests

Reviewed By: andrei.alexandrescu@fb.com

Subscribers: folly-diffs@

FB internal diff: D1754577

Signature: t1:1754577:1419618119:4c1a59cd19b23de9a9f6574341944e5e80530d62

9 years agoSharedThreadPool unittest
Dave Watson [Mon, 29 Dec 2014 20:18:39 +0000 (12:18 -0800)]
SharedThreadPool unittest

Summary: Add a test to check that the accept IOPool can be the same as the IO worker thread pool

Test Plan: unittest

Reviewed By: jsedgwick@fb.com

Subscribers: doug, fugalh, njormrod, folly-diffs@

FB internal diff: D1710628

Signature: t1:1710628:1417469919:6d81a9426b61e9f1b804114f895ed541e547110f

9 years agoAdd convenience functions to serialize to / deserialize from string
Keith Adams [Mon, 29 Dec 2014 18:46:01 +0000 (10:46 -0800)]
Add convenience functions to serialize to / deserialize from string

Summary: kma asked

Test Plan: tests added

Reviewed By: andrei.bajenov@fb.com

Subscribers: alandau, bmatheny, mshneer, folly-diffs@

FB internal diff: D1756731

Signature: t1:1756731:1419442987:afdccce166ef1f1e609d8894ea587915f6fea8e7

9 years agoBump version to 20:0
Dave Watson [Mon, 29 Dec 2014 18:40:59 +0000 (10:40 -0800)]
Bump version to 20:0

9 years agoKill fbthrift dep
Dave Watson [Mon, 29 Dec 2014 17:58:29 +0000 (09:58 -0800)]
Kill fbthrift dep

Summary:
(almost) all the necessary code has been moved to folly.  A couple last functions in SSLUtils, moved them to SSLContext

I think this is enough so that open source mcrouter doesn't need an fbthrift dep anymore - although stuff in mcrouter/facebook still uses thrift.

Test Plan:
fbconfig -r mcrouter; fbmake runtests_dev

contbuild will probably show some other projects to fix up for SSLUtils

Reviewed By: alikhtarov@fb.com

Subscribers: doug, ps, alandau, bmatheny, alikhtarov, mshneer, folly-diffs@

FB internal diff: D1747133

Signature: t1:1747133:1418946064:1c30a60e43f017213e5514d462f267f91761abbe

9 years agoFix case of ThreadWheelTimekeeper.cpp in Makefile.am
Hans Fugal [Sat, 27 Dec 2014 00:55:29 +0000 (16:55 -0800)]
Fix case of ThreadWheelTimekeeper.cpp in Makefile.am

Test Plan: jenkins

Reviewed By: ajitb@fb.com

Subscribers: exa, folly-diffs@

FB internal diff: D1758358

Tasks: 5880251

Signature: t1:1758358:1419640865:c9e9ea5922a602c44042c358777067e025800e6e

9 years ago(wangle) fix Makefile.am
Hans Fugal [Sat, 27 Dec 2014 00:27:44 +0000 (16:27 -0800)]
(wangle) fix Makefile.am

Summary: Add some forgotten header and cpp files to `Makefile.am` for OSS build of folly.

Test Plan: jenkins

Reviewed By: ajitb@fb.com

Subscribers: exa, folly-diffs@

FB internal diff: D1758318

Tasks: 5880251

Signature: t1:1758318:1419639812:47f527fdb2b3d2c49e7557b4176c6ab2478091ae

9 years ago(wangle) Timeouts basic
Hans Fugal [Fri, 26 Dec 2014 23:18:11 +0000 (15:18 -0800)]
(wangle) Timeouts basic

Summary:
Add basic timeout functionality. This adds `futures::sleep` which makes an async Future that finishes after the given duration, and `Future::get` which blocks on the result and takes an optional timeout.

Introducing the folly::wangle::futures namespace (soon to be just folly::futures) which will hold our wangle utility functions, the things that live in the Future object in Twitter's scala code. We'll probably move when* and wait-ish methods in here too, and perhaps alias makeFuture-ish methods too, though James has me mostly convinced not to deprecate them at the folly::wangle level (because they're basically Future constructors and Future lives at folly::wangle)

`Future::delayed` after Twitter's helper of the same name

Test Plan: new and old unit tests

Reviewed By: davejwatson@fb.com

Subscribers: trunkagent, fugalh, exa, folly-diffs@

FB internal diff: D1748894

Tasks: 4548494

Signature: t1:1748894:1419363496:1f4a62ec8455989c1fcce845695ace1d01c101c8

9 years agoHHWheelTimer::cancelAll
Hans Fugal [Fri, 26 Dec 2014 23:18:08 +0000 (15:18 -0800)]
HHWheelTimer::cancelAll

Summary: Provide a way to massacre outstanding timers.

Test Plan: new test, and using in wangle (different diff)

Reviewed By: davejwatson@fb.com

Subscribers: jsedgwick, exa, folly-diffs@

FB internal diff: D1753866

Tasks: 4548494

Signature: t1:1753866:1419361846:58ff6ca4d01b0d546495b032b454c8bf0fdb0277

9 years agomake futexWaitUntil tolerant of invalid time_point-s
Nathan Bronson [Wed, 24 Dec 2014 04:46:39 +0000 (20:46 -0800)]
make futexWaitUntil tolerant of invalid time_point-s

Summary:
futexWaitUntil could generate an invalid timespec when presented
with a time_point from before the epoch, which resulted in an EINVAL from
the futex syscall.  Debug builds crashed on this unexpected return value,
while release builds soldiered on.  This path happened to be exercised
by the unit test.  This diff fixes the unintentional deadline overflow
in the test, adds explicit testing of overflow behavior, and makes
futexWaitUntil handle invalid time_points in a sensible manner.

Test Plan:
1. new unit tests
2. fbmake runtests_dbg

Reviewed By: mssarang@fb.com

Subscribers: strager, njormrod, folly-diffs@

FB internal diff: D1747972

Tasks: 5853949

Signature: t1:1747972:1419382193:862c193a13428d96acb33c85f962f59203661f40

9 years agoRevert "folly: AsyncServerSocket::getAddress: prefer IPv6"
Tao Chen [Tue, 23 Dec 2014 22:49:20 +0000 (14:49 -0800)]
Revert "folly: AsyncServerSocket::getAddress: prefer IPv6"

Summary: This reverts commit fc83e983e2376bccc80dc4b21890e3a41dbc211f.

Test Plan: none

Reviewed By: lucian@fb.com, robot9@fb.com

Subscribers: ps, bmatheny, folly-diffs@

FB internal diff: D1756753

Tasks: 58838945886688

Signature: t1:1756753:1419374764:977160379cfa49530babb38022b9d4cc80573a7d

9 years agoAllow unregistering connect callback in AsyncSocket
Viswanath Sivakumar [Tue, 23 Dec 2014 20:16:48 +0000 (12:16 -0800)]
Allow unregistering connect callback in AsyncSocket

Summary:
Sometimes when the socket is destroyed from a destructor, we wouldn't
want further callbacks on shutdown. We can unregister the readCallback_
by calling setReadCB(nullptr), but if the state is CONNECTING, we can
still get connectErr() callback. I found an ASAN trace (https://phabricator.fb.com/P18837265)
that turned out to be because of this inability to cancel this callback.
This provides a way to unregister the connect callback as well.

Test Plan: fbconfig -r folly && fbmake runtests

Reviewed By: afrind@fb.com

Subscribers: folly-diffs@

FB internal diff: D1751778

Tasks: 5852935

Signature: t1:1751778:1419363638:26967c2d4fc5819e4d65ae706d217a954dfd784f

9 years agoFix incorrect 'test' statement in unit test
Chip Turner [Tue, 23 Dec 2014 18:40:17 +0000 (10:40 -0800)]
Fix incorrect 'test' statement in unit test

Summary:
The 'test' command uses one equal sign for string equality, not
two.  bash apparently is okay with two, but zsh isn't, causing this test
to pass if your shell was bash and fail if it was zsh.  The test now
passes with bash, bash in sh mode, zsh, and even dash.

Test Plan:
runtests, also, these pass (zsh failed before):

SHELL=/bin/bash _build/dbg/folly/test/subprocess_test
SHELL=/bin/sh _build/dbg/folly/test/subprocess_test
SHELL=/bin/zsh _build/dbg/folly/test/subprocess_test
SHELL=/bin/dash _build/dbg/folly/test/subprocess_test

Reviewed By: njormrod@fb.com

Subscribers: lins, anca, folly-diffs@

FB internal diff: D1756090

Signature: t1:1756090:1419360674:8576e61a6e0ee102612c5eae0e1fbd79cc397bfa

9 years agoFix Dwarf path handling to fix broken test
Chip Turner [Tue, 23 Dec 2014 18:19:39 +0000 (10:19 -0800)]
Fix Dwarf path handling to fix broken test

Summary:
Simplify the logic slightly to better handle joining paths.
This makes DwarfTest.cpp pass.

Test Plan: runtests

Reviewed By: njormrod@fb.com

Subscribers: lins, anca, folly-diffs@

FB internal diff: D1756036

Tasks: 5871014

Signature: t1:1756036:1419359254:123cc508b8836ea0b1485abe361b1c158538aa08

9 years agofolly::AtomicHashMap: fixed race between erase() and find()
Mike Kolupaev [Tue, 23 Dec 2014 12:28:32 +0000 (04:28 -0800)]
folly::AtomicHashMap: fixed race between erase() and find()

Summary: advancePastEmpty() was called for all created iterators. It only makes sense for begin(). For find() it's harmful: find() shouldn't return an iterator to the next element if the key was removed. I suspect that the same race condition was possible for insert(), but I haven't tried to reproduce it.

Test Plan: Added a test for it. It fails without these changes.

Reviewed By: delong.j@fb.com

Subscribers: folly-diffs@, lovro

FB internal diff: D1751280

Tasks: 5841499

Signature: t1:1751280:1419107193:71311ff68d92d0a4dcf1941dacdfdc23c25255cc

9 years agofolly: AsyncServerSocket::getAddress: prefer IPv6
Lucian Grijincu [Tue, 23 Dec 2014 10:19:34 +0000 (02:19 -0800)]
folly: AsyncServerSocket::getAddress: prefer IPv6

Summary: Can't connect from ipv6-only cluster to ipv4/ipv6 service which uses different ports.

Test Plan:
```
./fastcopy_server --dir . &

# netstat -atnlp | grep LISTEN | grep fastc
tcp        0      0 0.0.0.0:65478               0.0.0.0:*                   LISTEN      9348/./fastcopy_ser
tcp        0      0 :::52793                    :::*                        LISTEN      9348/./fastcopy_ser
```

Reviewed By: philipp@fb.com, sdoroshenko@fb.com

Subscribers: ps, bmatheny, folly-diffs@

FB internal diff: D1752846

Tasks: 5868818

Signature: t1:1752846:1419043494:7cc0646882249f17258ade5ce7ae5619b13148a0

9 years agoBring fbstring::operator+ to date with C++11
Andrei Alexandrescu [Wed, 17 Dec 2014 21:16:07 +0000 (13:16 -0800)]
Bring fbstring::operator+ to date with C++11

Summary: Some overloads, particularly with rvalue references, were missing. Also this fixes https://our.intern.facebook.com/intern/tasks/?t=5849579

Test Plan: unittests

Reviewed By: simpkins@fb.com

Subscribers: trunkagent, las, net-systems@, njormrod, folly-diffs@

FB internal diff: D1746319

Tasks: 5849579

Signature: t1:1746319:1418875228:febb965cf52710a5e76b7c1cce5aec601086ad90

9 years agoAllow conversion from StringPiece to StringPiece
Sarang Masti [Sat, 20 Dec 2014 00:44:37 +0000 (16:44 -0800)]
Allow conversion from StringPiece to StringPiece

Summary: Allow conversion from folly::StringPiece to folly::StringPiece

Test Plan: - fbconfig -r folly && fbmake runtests

Reviewed By: mpawlowski@fb.com

Subscribers: folly-diffs@

FB internal diff: D1752609

Signature: t1:1752609:1419037172:04846f658901306b53fb60c9eafbdf0f4d4d7005

9 years agoPrint linux TID while crashing
Kai Wang [Sat, 20 Dec 2014 06:24:54 +0000 (22:24 -0800)]
Print linux TID while crashing

Summary:
For servers using GLOG, all thread ID are get from gettid system call. So it
is very useful if we print this ID so during debugging I can find the log
of crashing thread.

I'm not sure who should review this diff. Just found you guys from previous
diffs touched this file :)

Test Plan:
See the crash log.
*** Aborted at 1419029404 (Unix time, try 'date -d @1419029404') ***
*** Signal 11 (SIGSEGV) (0x18) received by PID 18852 (pthread TID 0x7f52a1fff700) (linux TID 27908), stack trace: ***

Reviewed By: tudorb@fb.com

Subscribers: seanc, folly-diffs@

FB internal diff: D1752301

Signature: t1:1752301:1419032887:e43c2ace6914e54812149a8b8e84eaffaf42a09c

9 years agoVarious Dwarf::Path fixes
Andrew Gallagher [Sat, 20 Dec 2014 05:56:23 +0000 (21:56 -0800)]
Various Dwarf::Path fixes

Summary:
- Allow both `baseDir` and `subDir` to be empty.  This can happen
if DW_AT_comp_dir is `.` and gets simplified to the empty string.
(The DWARF standard doesn't appear to disallow relative dirs here,
but I couldn't find anthing definitive).
- Fix `./` prefix  stripping to avoid making paths like `.///hello` absolute.
- Fix `/` suffix stripping to avoid making the root dir reference (`/`) empty.
- Do `baseDir` and `subDir` swapping after simplification.

Test Plan: Added unittests.

Reviewed By: njormrod@fb.com

Subscribers: trunkagent, sdwilsh, folly-diffs@

FB internal diff: D1747978

Signature: t1:1747978:1419014942:87f14cb31b8c19b524d7a95b14d63cf5661a8634

9 years agoAdd comment explaining that RWTicketSpinLock<..., true> is not reentrant
Tudor Bosman [Sat, 20 Dec 2014 02:33:14 +0000 (18:33 -0800)]
Add comment explaining that RWTicketSpinLock<..., true> is not reentrant

Test Plan: no, it's a comment

Reviewed By: zanfur@fb.com

Subscribers: folly-diffs@

FB internal diff: D1752850

Tasks: 5823969

Signature: t1:1752850:1419043661:673c68c0daad28b3fde9709e767b528b0dec8ad1

9 years agoFixed folly::AtomicHashMap::iterator not advancing past empty submaps
Mike Kolupaev [Fri, 19 Dec 2014 20:17:41 +0000 (12:17 -0800)]
Fixed folly::AtomicHashMap::iterator not advancing past empty submaps

Summary: A potential "real life" scenario that maybe can hit this bug is if we erase almost all elements and then iterate over the whole map.

Test Plan: Added a test for it.

Reviewed By: mwilliams@fb.com

Subscribers: folly-diffs@, lovro

FB internal diff: D1751455

Tasks: 5866368

Signature: t1:1751455:1419016611:b44c41d348f54397844460cb38002ad0d9704972

9 years agoRemove unnecessary constraint from Range subpiece constructor
Giuseppe Ottaviano [Fri, 19 Dec 2014 17:50:57 +0000 (09:50 -0800)]
Remove unnecessary constraint from Range subpiece constructor

Summary:
D1746899 enforced the constraint (previously in a comment) on the
constructor `Range(const Range&, size_t, size_t)` that `Iter` is a
`const char*`. There is however no reason for this constraint.

This patch generalizes and simplifies the constructor, and since it
has the same semantics as `subpiece`, the latter is implemented in
terms of the constructor.

Test Plan:
fbconfig -r folly && fbmake runtests_opt

Reviewed By: soren@fb.com

Subscribers: trunkagent, folly-diffs@

FB internal diff: D1747958

Signature: t1:1747958:1418930360:fcd6beeda34e64ec8a34b9491a57674ae2265596

9 years agoMove TAsyncTransport to folly as AsyncTransportWrapper
Dave Watson [Fri, 19 Dec 2014 17:24:38 +0000 (09:24 -0800)]
Move TAsyncTransport to folly as AsyncTransportWrapper

Summary:
This temporary class will be useful to cut dependencies on thrift
while (roughly) maintaining the old interface.

Fixup various test classes that depend on the interface.  Next diff will be to cut fbthrift dep in proxygen/mcrouter

Test Plan: unit tests, jenkins

Reviewed By: hans@fb.com

Subscribers: fbcode-common-diffs@, andrewcox, alandau, bmatheny, alikhtarov, mshneer, trunkagent, doug, njormrod, folly-diffs@, davejwatson

FB internal diff: D1696094

Signature: t1:1696094:1418762312:6028815cce2845ac5f8e754132a038fabf5fd957

9 years agoonError callbacks
James Sedgwick [Fri, 19 Dec 2014 00:11:50 +0000 (16:11 -0800)]
onError callbacks

Summary:
We've discussed these a bunch and here they are. I stole a bunch of Hannes' magic from https://www.facebook.com/groups/715931878455430/permalink/772854686096482/ to make this easier

Test Plan: added lots of unit tests

Reviewed By: hans@fb.com

Subscribers: fugalh, folly-diffs@, hannesr

FB internal diff: D1748418

Signature: t1:1748418:1418945606:e14c7d6a31245e222bc6a0d259d0e2b9ddd5a830

9 years agoBump version to 19:0
JoelMarcey [Thu, 18 Dec 2014 20:29:54 +0000 (12:29 -0800)]
Bump version to 19:0

9 years agocodemod: merge folly/wangle and folly/experimental/wangle
James Sedgwick [Thu, 18 Dec 2014 20:20:26 +0000 (12:20 -0800)]
codemod: merge folly/wangle and folly/experimental/wangle

Summary:
Various TARGETS could definitely use some rearranging but I'd rather wait until we're cut over to the new repo

Test Plan: wait for contbuild

Reviewed By: davejwatson@fb.com

Subscribers: ptarjan, joelm, trunkagent, hphp-diffs@, ps, fbcode-common-diffs@, fugalh, alandau, bmatheny, everstore-dev@, mwa, jgehring, fuegen, mshneer, folly-diffs@, hannesr

FB internal diff: D1740858

Tasks: 5802833

Signature: t1:1740858:1418752569:4d7d9c5b955e4d9fab4b322cf08a3d285e3db7ce

9 years agofix make test
Dave Watson [Thu, 18 Dec 2014 19:13:55 +0000 (11:13 -0800)]
fix make test

Summary: autotools is fun.  rule name has to match

Test Plan: No contbuild for this, only a jenkins hourly build: https://ci-builds.fb.com/job/folly/

Reviewed By: noamler@fb.com

Subscribers: doug, net-systems@, folly-diffs@

FB internal diff: D1747221

Signature: t1:1747221:1418929497:a29320b5e21a657fe7e0221d2bea8b332626627b

9 years agoremove Cpp2WorkerFactory
Dave Watson [Thu, 18 Dec 2014 17:48:05 +0000 (09:48 -0800)]
remove Cpp2WorkerFactory

Summary:
In preparation for a global IOThreadPoolExecutor - we can't override the workerFactory if we are using a global one.

Instead, add a new getEventBases() to IOTHreadPoolExecutro and just run code on each eventBase.  For shutdown, explicitly add a stop(), instead of doing the work after loop() as exited

Cpp2Worker required minor changes to be able to use EventBaseManager's eventbase vs. their own

Test Plan: fbconfig -r thrift/lib/cpp2; fbmake runtests

Reviewed By: jsedgwick@fb.com

Subscribers: trunkagent, andrewcox, doug, fugalh, alandau, bmatheny, mshneer, folly-diffs@

FB internal diff: D1734795

Signature: t1:1734795:1418759367:b45f419e5cbc482a64a5873d9e00e3bcb071db5a

9 years agoDisable implicit conversions from std::string for non-char* Range
Giuseppe Ottaviano [Thu, 18 Dec 2014 02:19:00 +0000 (18:19 -0800)]
Disable implicit conversions from std::string for non-char* Range

Summary:
`Range<Iter>` has an implicit constructors from strings for any
`Iter`, however such constructors are invalid (compilation fails)
if `Iter` is not `[const] char *`.

This can be an issue for overload resolution: for example

struct IsString {
bool operator()(folly::Range<int*>) { return false; }
bool operator()(folly::StringPiece) { return true; }
};

IsString()(std::string());

fails to compile because the overload is ambiguous, even if the
conversion to `ByteRange` is invalid.

This patch disables all the invalid constructors from
`[const] char*`, `std::string`, and `fbstring`.

Test Plan:
fbconfig -r folly && fbmake runtests_opt

Reviewed By: philipp@fb.com

Subscribers: folly-diffs@

FB internal diff: D1746899

Signature: t1:1746899:1418868361:50784c4993df0bd96eeb62c09c659d5e53964d9b

9 years agostabilize IOFuturePool test
James Sedgwick [Wed, 17 Dec 2014 23:57:16 +0000 (15:57 -0800)]
stabilize IOFuturePool test

Summary: see attached task. concurrency is hard.

Test Plan: stress ran the hell out of it, induced failures before, can't after

Reviewed By: hans@fb.com

Subscribers: fugalh, folly-diffs@

FB internal diff: D1746879

Tasks: 5589311

Signature: t1:1746879:1418860467:0ec3f51a398eee8a836532770682a4c58758ce93

9 years agofix the open source build
Adam Simpkins [Wed, 17 Dec 2014 18:31:50 +0000 (10:31 -0800)]
fix the open source build

Summary: Fix the path to detail/SpinLockImpl.h in Makefile.am

Test Plan: Will confirm the Jenkins builds pass for fbthrift and proxygen.

Reviewed By: davejwatson@fb.com

Subscribers: doug, net-systems@, exa, folly-diffs@

FB internal diff: D1745795

Signature: t1:1745795:1418841636:8a861275a62b018a8181541c7d70ba0890d7129f

9 years agofix bug with elf object left with file open upon error causing Entered fatal signal...
Laurent Demailly [Wed, 17 Dec 2014 01:56:51 +0000 (17:56 -0800)]
fix bug with elf object left with file open upon error causing Entered fatal signal handler recursively later

Summary: fix bug with elf object left with file open upon error causing Entered fatal signal handler recursively later

Test Plan: run publisher at the limit

Reviewed By: tudorb@fb.com

Subscribers: trunkagent, chip, folly-diffs@

FB internal diff: D1743052

Tasks: 5752190

Signature: t1:1743052:1418780889:ad2ee0e6999cf417c2b9fd1ef6bc82d2086774a1

9 years agoSpinLock improvements
Adam Simpkins [Fri, 12 Dec 2014 02:22:37 +0000 (18:22 -0800)]
SpinLock improvements

Summary:
This makes several improvements to the SpinLock code:

- Add a SpinLock implementation using pthread_spinlock_t.  On non-x86_64
platforms this is preferred over the pthread_mutex_t implementation
when available.

- For the pthread implementations, throw std::system_error on error,
rather than completely aborting the program using glog's CHECK()
macros.

- Update the pthread_mutex_t implementation to call
pthread_mutex_destroy() on destruction.

- Always unit test all implementations that can be compiled on the
current build platform, even though only a single implementation will
be selected as folly::SpinLock.  This way x86_64 builds will still
unit test the pthread-based implementations.

Test Plan: Ran the unit tests.

Reviewed By: seanc@fb.com

Subscribers: trunkagent, doug, net-systems@, exa, folly-diffs@

FB internal diff: D1735770

Signature: t1:1735770:1418445953:b238aa8fb835a8d55e6e98e20c4615ae1938b98f

9 years agoremove PortableSpinLock.h
Adam Simpkins [Thu, 11 Dec 2014 21:40:27 +0000 (13:40 -0800)]
remove PortableSpinLock.h

Summary:
Remove the PortableSpinLock header file now that all call sites have
been migrated to the new SpinLock name.

Test Plan: Built and ran unit tests for folly, thrift, and proxygen.

Reviewed By: seanc@fb.com

Subscribers: trunkagent, doug, net-systems@, exa, folly-diffs@

FB internal diff: D1734685

Signature: t1:1734685:1418335405:e834f64d7282393e942a1de3638f4cf67410eaab

9 years agoupdate call sites to use SpinLock
Adam Simpkins [Thu, 11 Dec 2014 21:23:05 +0000 (13:23 -0800)]
update call sites to use SpinLock

Summary:
Update call sites to use the new folly::SpinLock name, instead of
folly::io::PortableSpinLock.

Test Plan: Built and ran the folly unit tests.

Reviewed By: davejwatson@fb.com

Subscribers: doug, net-systems@, exa, folly-diffs@

FB internal diff: D1734647

Signature: t1:1734647:1418334925:1bbcffccd06907224de2a102f8d4bfbe1bd62fd1

9 years agorename io::PortableSpinLock to SpinLock
Adam Simpkins [Thu, 11 Dec 2014 20:23:34 +0000 (12:23 -0800)]
rename io::PortableSpinLock to SpinLock

Summary:
folly::io::PortableSpinLock seems generally useful outside of the io
code.  This moves it into the base folly namespace, and renames it from
PortableSpinLock to just SpinLock.

For most users, the main difference between MicroSpinLock and SpinLock
is that SpinLock provides a constructor that does the right thing, while
MicroSpinLock has to be explicitly initialized.

Test Plan:
Added some new unit tests, and tested both the MicroSpinLock and
pthread_spinlock_t implementations.  I didn't test the Mac OS version,
although that code remains unchanged.

Reviewed By: seanc@fb.com

Subscribers: trunkagent, doug, net-systems@, exa, folly-diffs@

FB internal diff: D1734632

Signature: t1:1734632:1418394033:99f6fbe73b485a1d631a2ef7d1b39ea6f49ecb0b

9 years agoget_fast/get_weak_fast API for folly::Singleton
Andrii Grynenko [Tue, 16 Dec 2014 04:36:43 +0000 (20:36 -0800)]
get_fast/get_weak_fast API for folly::Singleton

Summary: This adds API which makes folly::Singleton as performant as Meyers/static-object singletons.

Test Plan:
unit test + benchmark

============================================================================
folly/experimental/test/SingletonTest.cpp       relative  time/iter  iters/s
============================================================================
NormalSingleton                                            333.32ps    3.00G
MeyersSingleton                                  100.00%   333.33ps    3.00G
FollySingletonSlow                                 0.35%    94.36ns   10.60M
FollySingletonFast                                99.43%   335.24ps    2.98G
FollySingletonFastWeak                             0.62%    53.74ns   18.61M
============================================================================

Reviewed By: alikhtarov@fb.com

Subscribers: trunkagent, folly-diffs@

FB internal diff: D1741961

Signature: t1:1741961:1418765462:d9806f1bf5275bfbe2c4c53a41b735bda93753fe

9 years agoAdd specific multi-bind to AsyncServerSocket
Cameron Pickett [Tue, 16 Dec 2014 21:02:26 +0000 (13:02 -0800)]
Add specific multi-bind to AsyncServerSocket

Summary:
Add a bind api similar to binding by port across all interfaces.
However, this bind will only attempt to bind sockets to the supplied
IP addresses. I'd like to add this to aid in moving TURN to IPv6.

TURN will use two specified addresses, one for IPv4, and one for IPv6, to
handle incoming connections from clients. In order to avoid duplicating
workers, we'd like to take advantage of the multi-socket implementation
of AsyncServerSocket. However, we don't want to bind to all interfaces,
especially for port 443.

Test Plan:
Plan to test by adapting TurnTcpListener to use this new API. See that
1. using one address still works as expected,
2. using zero addesses will cause exception
3. using multiple addresses works as expected

Will write unit tests if needed

Reviewed By: davejwatson@fb.com

Subscribers: hannesr, trunkagent, net-systems@, folly-diffs@, naizhi

FB internal diff: D1729442

Tasks: 3633642

Signature: t1:1729442:1418752467:22a60da4ec9009ea0b7fe28a8a436a179e0449aa

9 years agofix Futex when steady_clock and system_clock precisions differ
Nathan Bronson [Tue, 16 Dec 2014 18:34:47 +0000 (10:34 -0800)]
fix Futex when steady_clock and system_clock precisions differ

Summary:
To handle the strange relationship between steady_clock and
system_clock (on some platforms these represent only one type, on some
platforms they are separate) Futex::futexWaitUntil converts the deadline
to a duration and back.  On Xcode 6 system_clock is measured in
microseconds and steady_clock in nanoseconds, resulting in a compilation
failure.  This diff fixes it.

Test Plan:
1. compile snippet manually using Xcode
2. new unit test that causes the same implicit conversion failure in a slightly different way

Reviewed By: mssarang@fb.com

Subscribers: trunkagent, folly-diffs@

FB internal diff: D1740903

Tasks: 5831196

Signature: t1:1740903:1418754770:32c999abf1dc87415ffebf45083a903abbded9f2