folly.git
10 years agoFix a folly build failure under clang: MPMCQueueTest.cpp.
Yedidya Feldblum [Mon, 21 Jul 2014 21:31:09 +0000 (14:31 -0700)]
Fix a folly build failure under clang: MPMCQueueTest.cpp.

Summary:
[Folly] Fix a folly build failure under clang: MPMCQueueTest.cpp.

In clang-v3.4, there is a bug with the combination of a lambda expression inside a function template taking a template name (rather than a type name) as a template argument.

This diff, in the interest of building folly under clang-v3.4, extracts the lambda expression into a separate function so that the function template taking a template name as a template argument no longer has a lambda expression in it.

Test Plan: Build folly/test/MPMCQueueTest.cpp under clang.

Reviewed By: njormrod@fb.com

Subscribers: mathieubaudet, dougw

FB internal diff: D1446279

Tasks: 4723132

10 years agoFix a folly build failure under clang: FutexTest.cpp.
Yedidya Feldblum [Mon, 21 Jul 2014 21:10:43 +0000 (14:10 -0700)]
Fix a folly build failure under clang: FutexTest.cpp.

Summary:
[Folly] Fix a folly build failure under clang: FutexTest.cpp.

In clang-v3.4, there is a bug with the combination of a lambda expression inside a function template taking a template name (rather than a type name) as a template argument.

This diff, in the interest of building folly under clang-v3.4, extracts the lambda expression into a separate function so that the function template taking a template name as a template argument no longer has a lambda expression in it.

Test Plan: Build folly/test/FutexTest.cpp under clang.

Reviewed By: njormrod@fb.com

Subscribers: mathieubaudet, dougw

FB internal diff: D1446237

Tasks: 4723132

10 years agofix D1422343 ("make `folly::Formatter` extendible") for clang
Tyler MacDonald [Mon, 21 Jul 2014 21:08:47 +0000 (14:08 -0700)]
fix D1422343 ("make `folly::Formatter` extendible") for clang

Summary:
This is D1422343, but with a one-line change to make it clang-compatible. I authored this diff by first copying the original, then updating, so it's easy to see what I had to change.

> on advice of @tudorb, move most of `folly::Formatter` into `folly::BaseFormatter` so that we can use compile-time polymorphism to provide different types of Formatters.

Test Plan:
```
fbmake clean
fbconfig -r thrift folly cold_storage && fbmake dbg && fbmake runtests
fbmake clean
fbconfig -r hphp --clang && fbmake dbgo && fbmake runtests
```

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

Subscribers: mathieubaudet, tudorb

FB internal diff: D1440310

Tasks: 46242684667712

10 years agoFix the unaligned string toLowerAscii test
Brian Pane [Mon, 21 Jul 2014 18:26:19 +0000 (11:26 -0700)]
Fix the unaligned string toLowerAscii test

Summary:
* The test computed nonaligned inputs but then copied them into temporary
buffers to compare different implementations. The temporary buffers
were word-aligned.
* This diff keeps the temp buffers but ensures that the data in them
keeps the original input's alignment.

Test Plan:
* Ran the test case with a modified String.cpp containing an assert to
catch unaligned reads.  The assert failed, as expected, on a copy
of the code without the fix from D1434585

Reviewed By: meyering@fb.com

Subscribers: ruibalp

FB internal diff: D1435028

Tasks: 4696800

10 years agoA generic line-reading callback for communicate()
Alexey Spiridonov [Fri, 25 Apr 2014 22:21:49 +0000 (15:21 -0700)]
A generic line-reading callback for communicate()

Summary: There are a couple of places where this behavior is useful, and it's not 100% trivial to implement it from scratch. Adding it to Folly to save people code & bugs.

Test Plan: unit tests

Reviewed By: tudorb@fb.com

Subscribers: tjackson, folly@lists, tudorb

FB internal diff: D1297506

10 years agoFactor out string stream re-splitting as StreamSplitter
Alexey Spiridonov [Thu, 8 May 2014 00:43:51 +0000 (17:43 -0700)]
Factor out string stream re-splitting as StreamSplitter

Summary: This way I can reuse it in Subprocess. It also makes it easy to make a bunch of other convenient tokenization routines (e.g. delimiter-preserving folly::gen tokenizers, file tokenizers, etc, etc).

Test Plan: fbconfig folly/gen/test && fbmake runtests

Reviewed By: tjackson@fb.com

Subscribers: vkatich, tjackson

FB internal diff: D1317973

10 years agoextend folly::split
Marcin Pawlowski [Fri, 18 Jul 2014 04:50:01 +0000 (21:50 -0700)]
extend folly::split

Summary:
see task:
https://our.intern.facebook.com/intern/tasks/?t=4723861

Test Plan: unit tests

Reviewed By: marcelo.juchem@fb.com

FB internal diff: D1443223

Tasks: 4723861

10 years agoBump version to 1:0
Tudor Bosman [Mon, 21 Jul 2014 19:22:08 +0000 (12:22 -0700)]
Bump version to 1:0

10 years agomake folly::Range literal type
Philip Pronin [Thu, 17 Jul 2014 20:05:02 +0000 (13:05 -0700)]
make folly::Range literal type

Summary:
7.1.5 [dcl.constexpr] / 9 (N3337) requires type to be literal to use it
in `constexpr` object declaration (seems to be not enforced by GCC 4.8?)

Currently `folly::Range<>` fails one of the requirements:

* is an aggregate type, or has at least one constexpr constructor or
constructor template that is not a copy or move constructor,

Test Plan: fbconfig folly/test:range_test && fbmake runtests_opt -j32

Reviewed By: lucian@fb.com

Subscribers: chaoyc, search-fbcode-diffs@, unicorn-diffs@

FB internal diff: D1441646

Tasks: 4720575

10 years agoCheck for self-assignment in move assignment
Zejun Wu [Thu, 17 Jul 2014 16:49:39 +0000 (09:49 -0700)]
Check for self-assignment in move assignment

Summary:
Check for self-assignment in move assignment. Otherwise
Optional<Neko> cat = whatever;
cat = std::move(cat);
cat.hasValue(); // always returns false

Test Plan: fbmake runtests

Reviewed By: tjackson@fb.com

FB internal diff: D1440633

10 years agoreserve capacity in toAppend<StringType>(...)
Marcin Pawlowski [Tue, 15 Jul 2014 22:30:57 +0000 (15:30 -0700)]
reserve capacity in toAppend<StringType>(...)

Summary:
I modified the toAppend(args..., StringType* dest) so that
before appending it reserves enough space for data to be appended. It is
still work in progress (floats and doubles are really bad: we only do
very naive approximation of the size). On float like workload we gain
~10% perf, on strings/ints/chars we gain as much as 25% of perf.
Probably on bigger strings it will be even faster. We only modify the
case when toAppend() has more than 1 element to append as it would be
just overhead in case of one argument.

Test Plan:
with this change:

============================================================================
folly/test/ConvTest.cpp                         relative  time/iter
iters/s
============================================================================
preallocateTestNoFloat                                       1.59us 627.85K
preallocateTestFloat                                         1.09us 920.70K
----------------------------------------------------------------------------
============================================================================

without the change:

============================================================================
folly/test/ConvTest.cpp                         relative  time/iter
iters/s
============================================================================
preallocateTestNoFloat                                       2.12us 471.43K
preallocateTestFloat                                         1.22us 818.25K
----------------------------------------------------------------------------
============================================================================

Reviewed By: marcelo.juchem@fb.com

FB internal diff: D1420588

Tasks: 4632421

10 years agoadded replaceAt and replaceAll to MutableStringPiece
Marcin Pawlowski [Tue, 15 Jul 2014 22:20:29 +0000 (15:20 -0700)]
added replaceAt and replaceAll to MutableStringPiece

Summary:
To make MutableStringPiece more usable (and make the
implementation of replace* methods easier) I made sure that
all the const methods (like find) work for MutableStringPiece
in a fashion similar to how they work with StringPiece
(work with everything auto convertible to StringPiece). As
a result this change is pretty susbstatial in LOC, even
though now much happens here.

Test Plan: unit tests

Reviewed By: marcelo.juchem@fb.com

FB internal diff: D1420965

Tasks: 4632424

10 years agofolly: toLowerAscii: avoid unaligned access; also correct 3 conditions
Jim Meyering [Mon, 14 Jul 2014 23:21:07 +0000 (16:21 -0700)]
folly: toLowerAscii: avoid unaligned access; also correct 3 conditions

Summary:
* folly/String.cpp (toLowerAscii): Fix two errors: the most important
would cause unaligned accesses.  This would cause a performance loss
in general, but would also result in segfaults on ARM processes.
In addition, three conditionals were wrong, further limiting
the performance of this code: switch those "<" to "<=".

Test Plan:
Run this to exercise existing tests:
fbconfig folly/test:string_test && fbmake runtests_opt
Run this to generate timing stats (before and after this change), e.g.,
fbconfig folly/test:string_benchmark && fbmake opt
_bin/folly/test/string_benchmark > TIMING-toLower-old

These numbers show a 1.6% speed increase with this change:

--- TIMING-toLower-old  2014-07-14 16:51:12.793523778 -0700
+++ TIMING-toLower-new  2014-07-14 16:49:45.815119145 -0700
@@ -1,6 +1,6 @@
============================================================================
folly/test/StringBenchmark.cpp                  relative  time/iter  iters/s
============================================================================
-libc_tolower                                                 1.06us  941.91K
-folly_toLowerAscii                                          89.99ns   11.11M
+libc_tolower                                                 1.06us  941.90K
+folly_toLowerAscii                                          88.57ns   11.29M
============================================================================

Reviewed By: brianp@fb.com

Subscribers:

FB internal diff: D1434585

Tasks: 4696800

Blame Revision: D1421056

10 years agooops, remove stray libgtest
Tudor Bosman [Tue, 15 Jul 2014 00:49:34 +0000 (17:49 -0700)]
oops, remove stray libgtest

Reviewed By: lesha@fb.com
Test Plan: no

10 years agoUpdate folly/thrift README with tested deps for Ubuntu 13.10 and 14.04
Tudor Bosman [Mon, 14 Jul 2014 20:21:55 +0000 (13:21 -0700)]
Update folly/thrift README with tested deps for Ubuntu 13.10 and 14.04

Test Plan: no

Reviewed By: lesha@fb.com

Subscribers: alandau, jhj, kma

FB internal diff: D1434163

10 years agoAllow undefined LZ4_MAX_INPUT_SIZE
Tudor Bosman [Mon, 14 Jul 2014 20:24:27 +0000 (13:24 -0700)]
Allow undefined LZ4_MAX_INPUT_SIZE

Summary:
Because the version of lz4 that ships by default with Ubuntu 13.10 doesn't
define it (but has lz4_decompress_safe, so it's usable)

Test Plan: built on Ubuntu 13.10

Reviewed By: meyering@fb.com

Subscribers: jhj, lesha, kma

FB internal diff: D1433864

@override-unit-failures

10 years agoFix IPAddress operator==
Pavlo Kushnir [Mon, 7 Jul 2014 04:03:36 +0000 (21:03 -0700)]
Fix IPAddress operator==

Summary: IPAddress operator== throws an exception when comparing ip v6 mapped address with unitialized (default constructed) address. With this diff it returns false.

Test Plan: folly unit tests

Reviewed By: bmatheny@fb.com

FB internal diff: D1421280

10 years agoFix another race in Notification Queue
Gunjan Sharma [Thu, 10 Jul 2014 00:50:19 +0000 (17:50 -0700)]
Fix another race in Notification Queue

Summary: Consider a case we found that the queue is empty and unlocked and before our setActive(false) from SCOPE_EXIT gets called (or gets the lock) putMessageImpl got the lock. Now putMessage thinks that we donot want to add another signal but actually we do.

Test Plan:
Running mcreplay2 without running into this problem on a box.
Benchmark:

Reviewed By: davejwatson@fb.com

FB internal diff: D1428249

10 years agoEnforce max uncompressed size; use safe LZ4 decompressor, which requires a newer...
Tudor Bosman [Thu, 10 Jul 2014 19:40:18 +0000 (12:40 -0700)]
Enforce max uncompressed size; use safe LZ4 decompressor, which requires a newer version of LZ4

Test Plan: folly/io/test, whatever contbuild dreams up for hphp

Reviewed By: meyering@fb.com

Subscribers: meyering, hphp-diffs@, ps, jhj, kma, sainbar, lesha

FB internal diff: D1429372

@override-unit-failures

10 years agoSmall changes for cygwin build
Elizabeth Smith [Thu, 10 Jul 2014 22:52:22 +0000 (15:52 -0700)]
Small changes for cygwin build

Summary:
Folly is almost "out of the box" working with cygwin

This has the proper ifdefs to include cygwin in two areas and a workaround for a cygwin bug when including headers

Test Plan: fbconfig -r folly && fbmake runtests

Reviewed By: delong.j@fb.com

FB internal diff: D1413303

10 years agoMSVC includes for inet/sockets
Elizabeth Smith [Thu, 10 Jul 2014 22:19:57 +0000 (15:19 -0700)]
MSVC includes for inet/sockets

Summary:
MSVC has all the sockets and internet functionality required except for one missing item - which can safely be defined to a windows specific type
But it requires a different set of headers than on *nix systems

Test Plan: fbconfig -r folly && fbmake runtests

Reviewed By: delong.j@fb.com

FB internal diff: D1413265

10 years agoMSVC intrinsics for bits and cpuid
Elizabeth Smith [Thu, 10 Jul 2014 22:15:26 +0000 (15:15 -0700)]
MSVC intrinsics for bits and cpuid

Summary: Use msvc intrinsics for cpuid, popcount, byteswap, and bit scan functionality

Test Plan: fbconfig -r folly && fbmake runtests

Reviewed By: delong.j@fb.com

FB internal diff: D1413254

10 years agoExpression SFINAE issue in base.h
Elizabeth Smith [Thu, 10 Jul 2014 21:54:28 +0000 (14:54 -0700)]
Expression SFINAE issue in base.h

Summary:
MSVC 14 is still broken with expression sfinae - and the things that break are often strange
Moving this out into two expr templates solves the compilation issue

Test Plan: fbconfig -r folly && fbmake runtests

Reviewed By: tjackson@fb.com

FB internal diff: D1413297

10 years agouse recursive_mutex to protect State
Wez Furlong [Thu, 10 Jul 2014 18:37:17 +0000 (11:37 -0700)]
use recursive_mutex to protect State

Summary:
maelstrom destructs a Promise during an indirect call from
maybeCallback and deadlocks on itself unless we use a recursive mutex.

There may be a smarter way to proceed but at the moment I can't build
and deploy a package from trunk because the service is non-functional
:-/

Test Plan:
run

```
fbconfig -r folly/wangle messaging/maelstrom
fbmake runtests
```

Reviewed By: hannesr@fb.com

Subscribers: fugalh, fsilva

FB internal diff: D1428504

10 years agoRemove unnecessary and broken hash specializations
Tudor Bosman [Wed, 9 Jul 2014 15:42:15 +0000 (08:42 -0700)]
Remove unnecessary and broken hash specializations

Summary:
No need to specialize std::hash for std::basic_string; the STL already does
this. Plus, the specializations were broken in multiple ways:

1. std::hash does not treat const char* specially, so it just hashes the
pointer value (contrasting the old __gnu_cxx::hash, which hashed a C-string)

2. Either way, using __gnu_cxx::hash<const char*> for std::string is broken,
as it won't hash anything past the first null byte.

Also, make sure fbstring gets the same (full) specializations as std::string
does in the standard.

Test Plan: fbconfig -r folly && fbmake runtests_opt, also tests in tupperware/agent which is still using __gnu_cxx::hash_map with string keys.

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

Subscribers: njormrod, jhj, kma, lesha

FB internal diff: D1426479

10 years agoFix race in Notification Queue
Gunjan Sharma [Wed, 9 Jul 2014 17:56:05 +0000 (10:56 -0700)]
Fix race in Notification Queue

Summary: When we are changing value of numActiveConsumers_ with setActive from handlerReady at the SCOPE_EXIT we have a race with reading of the same variable in putMessageImpl.

Test Plan: Had a local race which works fine now.

Reviewed By: davejwatson@fb.com

Subscribers: trunkagent

FB internal diff: D1424674

10 years agoSimplify pipe2 / O_CLOEXEC handling in Subprocess.cpp
Tudor Bosman [Tue, 8 Jul 2014 00:29:32 +0000 (17:29 -0700)]
Simplify pipe2 / O_CLOEXEC handling in Subprocess.cpp

Summary: per @rockyliu's suggestions

Test Plan: subprocess_test

Reviewed By: rockyliu4@fb.com

Subscribers: rockyliu, jhj, lesha, kma

FB internal diff: D1423157

10 years agoRevert "make `folly::Formatter` extendible"
Paul Tarjan [Wed, 9 Jul 2014 14:07:38 +0000 (07:07 -0700)]
Revert "make `folly::Formatter` extendible"

Summary:
This reverts commit 5ea0eb0c705224b82a5c284dc5f7722e1f71199f.

This breaks the HHVM clang build test.

Test Plan: clang will pass now

Reviewed By: smith@fb.com

Subscribers: dmitrys

FB internal diff: D1426399

Tasks: 4667712

10 years agomake `folly::Formatter` extendible
Tyler MacDonald [Wed, 9 Jul 2014 00:27:36 +0000 (17:27 -0700)]
make `folly::Formatter` extendible

Summary:
on advice of @tudorb, move most of `folly::Formatter` into `folly::BaseFormatter` so that we can use compile-time polymorphism to provide different types of Formatters.

I wasn't able to get the recursive formatter to be polymorphic -- whenever I tried to convert `class FormatValue<Formatter<containerMode, Args...>, void>` into `class FormatValue<BaseFormatter...`, `FormatTest.cpp:Test(Format, Nested)` wouldn't compile because it couldn't find the template. @tudorb, if you have an easy fix for this, lmk, otherwise I'm (reluctantly) okay with requiring that `Formatter`s define their own nesting `FormatValue`.

phew. the last time I did this sort of metaprogramming was over 5 years ago in perl. Doing it in C++ is... interesting.

Test Plan: `fbconfig -r thrift folly cold_storage && fbmake dbg && fbmake runtests`

Reviewed By: tudorb@fb.com

Subscribers: tudorb, dgp

FB internal diff: D1422343

Tasks: 4624268

10 years agoFix libc++ build errors
Tudor Bosman [Sat, 5 Jul 2014 15:50:38 +0000 (08:50 -0700)]
Fix libc++ build errors

Summary:
Reported externally:

https://github.com/facebook/folly/issues/70
https://github.com/facebook/folly/issues/71
https://github.com/facebook/folly/issues/72
https://github.com/facebook/folly/issues/73

Note that I can't test on libc++ myself, but the reports suggested fixes which
sounded good.

Test Plan: fbconfig -r folly && fbmake runtests_opt

Reviewed By: marcelo.juchem@fb.com

Subscribers: jhj, ntv, lesha, kma, fugalh, jdelong

FB internal diff: D1421029

10 years agoUse pipe2 in Subprocess; platform-specific config
Tudor Bosman [Mon, 7 Jul 2014 20:08:28 +0000 (13:08 -0700)]
Use pipe2 in Subprocess; platform-specific config

Summary:
We've wanted to use pipe2 in Subprocess for a while, but that's not supported
on glibc 2.5.1. This is not a problem in OSS (autoconf can solve this),
but, internally, we don't run autoconf; add an internal platform include file
with such per-platform differences.

Test Plan: fbconfig -r folly && fbmake runtests_opt

Reviewed By: meyering@fb.com

Subscribers: jhj, lesha, kma, agallagher

FB internal diff: D1422128

10 years agostride()
Tom Jackson [Thu, 3 Jul 2014 22:28:27 +0000 (15:28 -0700)]
stride()

Summary: thatwaseasy

Test Plan: iloveunittests

Reviewed By: lucian@fb.com

Subscribers: philipp

FB internal diff: D1419848

Tasks: 4636617

10 years agoMove the branchless, parallel ASCII toLower into folly
Brian Pane [Mon, 7 Jul 2014 17:27:30 +0000 (10:27 -0700)]
Move the branchless, parallel ASCII toLower into folly

Summary:
* Moved the fast toLower code into folly
* Updated the name to emphasize that it's ASCII-only

Test Plan: * Unit tests and benchmarks included.

Reviewed By: tudorb@fb.com

Subscribers: ruibalp, bmatheny

FB internal diff: D1421056

10 years ago(wangle) fix shadow
Hans Fugal [Mon, 7 Jul 2014 16:01:47 +0000 (09:01 -0700)]
(wangle) fix shadow

Summary: Not sure why this shadow error didn't turn up in my tests, but whatevs

Test Plan: traffic manager builds without warning-errors

Reviewed By: suhas@fb.com

Subscribers: hannesr, net-systems@, fugalh, exa

FB internal diff: D1421495

Tasks: 4653938

10 years agofix Makefile.am
Tudor Bosman [Mon, 7 Jul 2014 15:59:17 +0000 (08:59 -0700)]
fix Makefile.am

Summary: wangle/detail.h -> wangle/detail/State.h

Test Plan: OSS build

Reviewed By: meyering@fb.com

Subscribers: fugalh, lesha

FB internal diff: D1421490

10 years agogflags now likes namespace gflags, not google
Tudor Bosman [Fri, 4 Jul 2014 05:18:06 +0000 (22:18 -0700)]
gflags now likes namespace gflags, not google

Summary:
Use namespace gflags going forward, import namespace google into it if
backward.

Also added a few "checking for..." messages in autoconf.

Test Plan: fbconfig -r folly && fbmake runtests_opt, OSS build

Reviewed By: meyering@fb.com

Subscribers: fjargsto, ntv, jhj, lesha, kma, davejwatson

FB internal diff: D1420575

10 years ago(wangle) cold via
Hans Fugal [Tue, 1 Jul 2014 00:29:05 +0000 (17:29 -0700)]
(wangle) cold via

Summary:
Instead of returning a Later, `via` returns a cold future.
This works without keeping a backreference like Later does, because an inactive Future will always activate on destruction. Alternatively we could have an extra Promise, a la Later, and pass that along like Later does, and require launch() at the end (though, implicit launching on destruction would be an option there too).

If you think this approach is viable I'll clean it up on Wednesday: make sure all the calling sites work, etc.

Test Plan:
new unit test
This may fail in contbuild, I haven't done the codemod for calling sites, if there are any.

Reviewed By: hannesr@fb.com

Subscribers: jsedgwick, net-systems@, fugalh, exa

FB internal diff: D1412499

Tasks: 4480567

10 years ago(wangle) Future/Promise detachment
Hans Fugal [Mon, 30 Jun 2014 20:38:41 +0000 (13:38 -0700)]
(wangle) Future/Promise detachment

Summary:
Bring a bit more sanity to the lifetime. Now Future and Promise detach by calling the respective methods on State, and they do it during their destruction only. State manages its own lifetime.

Besides being cleaner, this also sets the stage for cancellation (where we'll need Future to hang on to its reference to State after setting the callback), and for folding in Later (we will have a bool for whether the future is hot and hold off executing the callback if it isn't).

Also cleans up various things I noticed while auditing the code for usages of `state_`.

Test Plan:
All the unit tests still pass.
Ran with ASAN (and found I had introduced a bug, then fixed it. yay)

Reviewed By: hannesr@fb.com

Subscribers: jsedgwick, net-systems@, fugalh, exa

FB internal diff: D1412038

Tasks: 4618297

10 years ago(Folly/FBString) Enum class for category
Hannes Roth [Fri, 4 Jul 2014 15:11:36 +0000 (08:11 -0700)]
(Folly/FBString) Enum class for category

Summary: Suggested by @aalexandre.

Test Plan: Compile.

Reviewed By: andrei.alexandrescu@fb.com

Subscribers: folly@lists, njormrod, aalexandre

FB internal diff: D1246180

10 years agofolly: StringPiece: add skipWhitespace
Lucian Grijincu [Thu, 26 Jun 2014 23:26:33 +0000 (16:26 -0700)]
folly: StringPiece: add skipWhitespace

Test Plan: copied from folly::json

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

FB internal diff: D1417992

Tasks: 4527315

10 years agos/setCallback_/setCallback/ for detail::State
Hans Fugal [Mon, 30 Jun 2014 20:34:42 +0000 (13:34 -0700)]
s/setCallback_/setCallback/ for detail::State

Summary: This isn't really an internal-to-this-class method. :-/

Test Plan: builds

Reviewed By: hannesr@fb.com

Subscribers: jsedgwick, net-systems@, fugalh, exa

FB internal diff: D1412008

10 years ago(wangle) s/continuation_/callback/ (missed some)
Hans Fugal [Mon, 30 Jun 2014 20:32:17 +0000 (13:32 -0700)]
(wangle) s/continuation_/callback/ (missed some)

Summary: In the spirit of D1406753

Test Plan: still builds and tests pass

Reviewed By: hannesr@fb.com

Subscribers: jsedgwick, net-systems@, fugalh, exa

FB internal diff: D1412002

10 years ago(wangle) s/FutureObject/detail::State/
Hans Fugal [Mon, 30 Jun 2014 20:22:56 +0000 (13:22 -0700)]
(wangle) s/FutureObject/detail::State/

Summary:
codemod
I never was satisfied with this name. `State` feels a little better. More descriptive. But still pretty generic, so I'm open to alternative ideas.

Test Plan: It still builds and tests pass.

Reviewed By: hannesr@fb.com

Subscribers: jsedgwick, net-systems@, fugalh, exa

FB internal diff: D1411506

10 years agoFix string split when last part is shorter than delimiter
Kevin Chou [Wed, 2 Jul 2014 16:14:24 +0000 (09:14 -0700)]
Fix string split when last part is shorter than delimiter

Summary: The bug is when ignoreEmpty is true, we use the wrong token size, which will be 0 when last token is shorter than delimiter.

Test Plan:
1. Add unit test
2. fbconfig -r folly && fbmake runtests

Reviewed By: philipp@fb.com

Subscribers: maxime, xiaol

FB internal diff: D1415803

10 years agoAdd Random-inl.h to Makefile.am
Tudor Bosman [Wed, 2 Jul 2014 01:03:26 +0000 (18:03 -0700)]
Add Random-inl.h to Makefile.am

Test Plan: OSS

Reviewed By: lesha@fb.com

FB internal diff: D1415190

@override-unit-failures

10 years agoupdate make check targets
Dave Watson [Fri, 27 Jun 2014 17:46:15 +0000 (10:46 -0700)]
update make check targets

Summary:
Update targets so that gtest isn't required unless you run 'make check'.

Simply make everything that uses gtest a 'check_PROGRAM' instead of a 'noinst_PROGRAM'

Test Plan: build folly with 'make -j32', gtest isn't required.

Reviewed By: andrewjcg@fb.com

Subscribers: pavlo, doug

FB internal diff: D1408288

10 years agoSimplify include path, make sure .. is in it
Tudor Bosman [Mon, 30 Jun 2014 23:12:47 +0000 (16:12 -0700)]
Simplify include path, make sure .. is in it

Summary: so #include <folly/File.h> works

Test Plan: built OSS folly, make check, built tiny program out of tree

Reviewed By: davejwatson@fb.com

FB internal diff: D1412123

10 years agoCodemod: use #include angle brackets in folly and thrift
Tudor Bosman [Mon, 30 Jun 2014 18:56:53 +0000 (11:56 -0700)]
Codemod: use #include angle brackets in folly and thrift

Summary: Also changed the thrift compilers to emit code with <...>.

Test Plan: fbconfig -r folly thrift && fbmake opt && fbmake runtests_opt

Reviewed By: davejwatson@fb.com

Subscribers: ruibalp, nli, shilin, tjackson, fugalh, alandau, bmatheny, njormrod

FB internal diff: D1411225

10 years agofix AsyncIO::doWait
Philip Pronin [Sun, 29 Jun 2014 11:49:47 +0000 (04:49 -0700)]
fix AsyncIO::doWait

Summary:
As it turns out, `io_getevents` may actually return less than
`min_nr` events.  According to the aio logic
(https://github.com/torvalds/linux/blob/10b5b5361a3c2a7fff9dbfa0f127adc2531e7732/fs/aio.c#L1634),
there may be a couple of rounds required to get at least `nr_min` events, and
if interrupted after the first one, incomplete results would be returned

Test Plan:
fbconfig -r folly/experimental/io/test && fbmake runtests_opt -32

and was no longer able to repro #4609062

Reviewed By: soren@fb.com

FB internal diff: D1410389

Tasks: 4609062

10 years agoBe explicit about what we're passing to Endian::big
Joel Marcey [Fri, 27 Jun 2014 21:47:54 +0000 (14:47 -0700)]
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

10 years agoFix folly on OSX and BSD in prep for FastCGI on HHVM
Joel Marcey [Fri, 27 Jun 2014 21:46:19 +0000 (14:46 -0700)]
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

10 years ago(wangle) Return a Later from Future::via
Hans Fugal [Thu, 26 Jun 2014 23:23:11 +0000 (16:23 -0700)]
(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

10 years agofolly: futexWaitUntilImpl: avoid abort triggered via tao/queues tests
Jim Meyering [Wed, 25 Jun 2014 23:47:55 +0000 (16:47 -0700)]
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

10 years agoFix use-after-free in futexWaitUntilImpl
Sarang Masti [Thu, 26 Jun 2014 22:37:13 +0000 (15:37 -0700)]
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

10 years ago(wangle) noexcept move constructor
Hans Fugal [Thu, 26 Jun 2014 22:22:55 +0000 (15:22 -0700)]
(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

10 years ago(wangle) s/continuation/callback
Hans Fugal [Thu, 26 Jun 2014 22:20:40 +0000 (15:20 -0700)]
(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

10 years agonuke executeWith
Hans Fugal [Thu, 26 Jun 2014 21:31:48 +0000 (14:31 -0700)]
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

10 years agoFix bizarre optimization
Hans Fugal [Thu, 26 Jun 2014 17:44:20 +0000 (10:44 -0700)]
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

10 years ago(folly) QueuedImmediateExecutor
Hans Fugal [Wed, 4 Jun 2014 22:38:24 +0000 (15:38 -0700)]
(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

10 years agoOops, fix README
Tudor Bosman [Tue, 24 Jun 2014 01:23:03 +0000 (18:23 -0700)]
Oops, fix README

Reviewed By: meyering@fb.com
Test Plan: no

10 years agofolly OSS fixes: add ThreadName.h and compression
Tudor Bosman [Sat, 21 Jun 2014 02:10:12 +0000 (19:10 -0700)]
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

10 years agoFix for folly open source build on Ubuntu 12.04
Anton Likhtarov [Wed, 25 Jun 2014 01:52:54 +0000 (18:52 -0700)]
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

10 years agoScheduler interface of Executor
Hans Fugal [Thu, 19 Jun 2014 01:03:45 +0000 (18:03 -0700)]
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

10 years agofolly OSS fixes: add ThreadName.h and compression
Tudor Bosman [Sat, 21 Jun 2014 02:10:12 +0000 (19:10 -0700)]
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

10 years agoMake randomNumberSeed read from /dev/urandom
Tudor Bosman [Fri, 20 Jun 2014 03:46:10 +0000 (20:46 -0700)]
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

10 years agoAdd ThreadName.h to folly's Makefile.am
Peter Ruibal [Sun, 22 Jun 2014 20:40:11 +0000 (13:40 -0700)]
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

10 years agoExpose EVLOOP_NONBLOCK
Yunqi Zhang [Thu, 19 Jun 2014 01:40:19 +0000 (18:40 -0700)]
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

10 years agoMake fbstring libgcc-safe
Nicholas Ormrod [Wed, 18 Jun 2014 16:35:10 +0000 (09:35 -0700)]
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

10 years agoFBString conservative additions
Nicholas Ormrod [Sat, 14 Jun 2014 01:09:44 +0000 (18:09 -0700)]
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

10 years agoFix open source build
Anton Likhtarov [Sat, 14 Jun 2014 00:45:11 +0000 (17:45 -0700)]
Fix open source build

Test Plan: build it

Reviewed By: pavlo@fb.com

Subscribers: folly@lists

FB internal diff: D1383722

10 years agofolly: fbstring: make it conservative-only: write '\0' in ctor and drop the c_str...
Lucian Grijincu [Fri, 6 Jun 2014 21:48:15 +0000 (14:48 -0700)]
folly: fbstring: make it conservative-only: write '\0' in ctor and drop the c_str shenanigans

Test Plan: ran folly tests

Reviewed By: njormrod@fb.com

Subscribers: folly@lists, njormrod

FB internal diff: D1373308

10 years agofbstring conservative corruption
Nicholas Ormrod [Thu, 12 Jun 2014 18:11:55 +0000 (11:11 -0700)]
fbstring conservative corruption

Summary:
@lucian's D1373308 set fbstring to conservative by default.
This breaks, eg, ti/proxygen/httpclient tests, by failing an assertion
inside of c_str(). Specifically, the terminator is not '\0'.

The fbstring_core move constructor, when sourced by a MediumLarge
string, steals the source's internal data, then resets the source by
calling ##setSmallSize(0)##. That function sets the in-situ size of the
fbstring to zero, thus requalifying the string as a small string;
however, it does nothing to the data - the previous 23 bytes now contain
garbage.

Sources of a move must be in a consistent state after the move is
complete. The source, once a MediumLarge string whose first eight bytes
were a pointer, is now a small string of size zero whose first byte is
not necessarily '\0'. This breaks the FBSTRING_CONSERVATIVE invariant.

This can be fixed by writing a terminator after the setSmallSize call.
I have fixed all setSmallSize locations that do not writeTerminator.

fbstring_core's move constructor is called exclusively from
basic_fbstring's move assignment operator, hence the odd format of the
test case.

== TMI ==

Interestingly, the source will almost certainly* contain a '\0', which
prevents this simple ##str.size() != strlen(str.c_str())## bug from
turning into a memory-trampling monster. The new size of zero is not
what saves us - the 'size' byte of a small fbstring, through a very
clever trick to allow 23-byte in-situ strings, is actually 23 minus the
actual size (now 0), so is 23! Where, then, does the '\0' byte come? A
MediumLarge string's data layout is [pointer, size, capacity]. The
pointer is not guaranteed to contain a '\0', and neither are size or
capacity. However, the size of the string needs to be very large in
order to force the top byte of the size member to be non-zero; in that
case, the string is so large that malloc is returning memory by the
page. Since page sizes are a multiple of 2^8 (almost always, and if not
then I don't think your fbstring can support large enough sizes
anyways), and we use goodMallocSize, the capacity pointer would have a
least signfigicant byte of zero.

Why the (*)? Well, when reserving extra space on a non-refcounted Large
string, the reallocation does not yield its extra goodMallocSize space.
This could be fixed, though probably isn't worth the trouble. Anyways,
since we aren't goodMallocSize-ing the user-supplied requested capacity,
it probably won't contain a '\0'.

Test Plan:
fbconfig -r folly && fbmake runtests

Modify folly/test/FBStringTest.cpp to define FBSTRING_CONSERVATIVE, then
fbconfig folly/test/:fbstring_test_using_jemalloc && fbmake runtests
Note that this fails before the patch is applied.

Note that it is possible for the tests to pass even when this bug is
present, since the top byte of the heap pointer must be non-0 in order
for this error to be triggered.

Reviewed By: lucian@fb.com

Subscribers: folly@lists, njormrod, lucian, markisaa, robbert, sdwilsh, tudorb, jdelong

FB internal diff: D1376517

10 years agostatic-ify FBString asserts
Nicholas Ormrod [Thu, 12 Jun 2014 00:34:12 +0000 (17:34 -0700)]
static-ify FBString asserts

Summary: Some asserts could be static_asserts. Make it so!

Test Plan: fbconfig -r folly && fbmke opt && fbmake runtests_opt

Reviewed By: lucian@fb.com

Subscribers: folly@lists, sdwilsh, njormrod

FB internal diff: D1378670

10 years agofolly::gen::splitByLine
Vojin Katic [Wed, 11 Jun 2014 20:53:16 +0000 (13:53 -0700)]
folly::gen::splitByLine

Summary:
I made it work, but please send your feedback how to improve code quality.

splitByLine will split on \r, \n, and \r\n.

Test Plan: add new test, arc unit

Reviewed By: tjackson@fb.com

Subscribers: folly@lists, crawler-diffs@

FB internal diff: D1322212

10 years agofolly: do not disable RW_SPINLOCK_USE_X86_INTRINSIC_ for clang
Jim Meyering [Mon, 9 Jun 2014 20:32:26 +0000 (13:32 -0700)]
folly: do not disable RW_SPINLOCK_USE_X86_INTRINSIC_ for clang

Summary:
Without this, we'd see problems like this in tao, when building with clang:
With this change, this now works with clang-3.4 and clang.dev (3.4+).
This change reverts D950285, which change appears to have been made
to accommodate weakness in clang-3.3 or older.

In file included from tao/data_providers/common/simpledp.cpp:7:
./tao/data_providers/common/stats.h:175:18: error: no type named 'RWTicketSpinLockT' in namespace 'folly'
typedef folly::RWTicketSpinLockT<64, true> RWLockType;
~~~~~~~^
./tao/data_providers/common/stats.h:175:35: error: expected member name or ';' after declaration specifiers
typedef folly::RWTicketSpinLockT<64, true> RWLockType;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

Test Plan:
ensure that all of these pass:
fbconfig -r --clang folly/test:rw_spinlock_test && fbmake runtests
fbconfig -r --clang folly/test:rw_spinlock_test && fbmake runtests_opt
fbconfig -r         folly/test:rw_spinlock_test && fbmake runtests_opt
fbconfig -r --clang --with-project-version clang:dev \
folly/test:rw_spinlock_test && fbmake runtests_opt

Reviewed By: delong.j@fb.com

Subscribers: folly@lists, mathieubaudet

FB internal diff: D1370024

Tasks: 4090011

10 years agoSpecialize string to identical string conversion
Zejun Wu [Mon, 9 Jun 2014 17:16:31 +0000 (10:16 -0700)]
Specialize string to identical string conversion

Summary:
Avoid copying underlying char array in to<string>(const string&) and
to<fbstring>(const fbstring&).

Test Plan: fbconfig -r $redteamisthebestteam/$nekomikoreimu && fbmake

Reviewed By: ldbrandy@fb.com

Subscribers: jonp, folly@lists

FB internal diff: D1368183

Tasks: 4263125

10 years agoAdd support for returning number of benchmark iterations
Marcus Holland-Moritz [Fri, 6 Jun 2014 22:57:21 +0000 (15:57 -0700)]
Add support for returning number of benchmark iterations

Summary:
I'm looping through a large number of test cases in a benchmark and I'm
interested in the average time per test case rather than the total time,
which is what I'm currently seeing. In order to get the average time,
I need to be able to tell the benchmark module how many iterations have
been run.

This change adds _MULTI variants of the different BENCHMARK_ macros that
allow for returning the actual number of iterations that have been run,
e.g.:

BENCHMARK_MULTI(benchmarkSomething) {
std::vector<int> testCases { 0, 1, 1, 2, 3, 5 };
for (int c : testCases) {
doSomething(c);
}
return testCases.size();
}

Test Plan:
* fbconfig -r folly && fbmake runtests
* added new test cases to example benchmark code

Reviewed By: simpkins@fb.com

Subscribers: folly@lists, london_search@

FB internal diff: D1356437

10 years agorevert "conditionally write terminator in c_str()"
Philip Pronin [Fri, 6 Jun 2014 17:53:51 +0000 (10:53 -0700)]
revert "conditionally write terminator in c_str()"

Summary: D1318048#21

@override-unit-failures

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

Reviewed By: njormrod@fb.com

Subscribers: folly@lists, njormrod

FB internal diff: D1368939

Tasks: 4466412

Blame Revision: D1318048

10 years agoIntroduce destruction callbacks
Stepan Palamarchuk [Thu, 5 Jun 2014 05:33:39 +0000 (22:33 -0700)]
Introduce destruction callbacks

Summary:
This change allows users to track lifetime of EventBase and perform clean shutdown when EventBase gets destructed.

It is useful for users that rely on EventBase lifetime, but don't have any feedback mechanism with the owner of EventBase.

For instance some part of code might remain running in background on the EventBase after the main object was destroyed (e.g. it might be finalizing some async requests). In such case the original owner doesn't know that there's something still running and may try to destroy EventBase. In that case such background code will remain zombie forever.

AsyncMcClient changes are presented just as an example of usage.

@davejwatson, @simpkins: Could you please take a look at the proposed changes for the EventBase? If this is something not worth adding into EventBase, could you recommend a better way of doing things?

Test Plan: fbmake runtests

Reviewed By: alikhtarov@fb.com

Subscribers: folly@lists, simpkins, davejwatson

FB internal diff: D1353101

10 years agoAllowing additional arguments to be passed to split_step's functor
Marcelo Juchem [Tue, 3 Jun 2014 21:40:29 +0000 (14:40 -0700)]
Allowing additional arguments to be passed to split_step's functor

Summary: more flexibility for using functors with split_step

Test Plan: unit tests added + arc unit

Reviewed By: ldbrandy@fb.com

Subscribers: folly@lists

FB internal diff: D1362644

10 years agoHasher and equality comparison for IOBuf
Tudor Bosman [Mon, 2 Jun 2014 19:08:05 +0000 (12:08 -0700)]
Hasher and equality comparison for IOBuf

Test Plan: test added

Reviewed By: davejwatson@fb.com

Subscribers: folly@lists

FB internal diff: D1359469

10 years agoTimed wait for futures
Matt Dordal [Tue, 3 Jun 2014 17:57:38 +0000 (10:57 -0700)]
Timed wait for futures

Summary:
It might be useful to be able to wait for some time (but not forever) on a
future, so this is a shot at doing that. It's a very heavyweight implementation, however.

Since the current interface for waitWithSemaphore doesn't really make sense if
the timeout fires, change it to return a Future<T>.

Test Plan: unit tests

Reviewed By: hans@fb.com

Subscribers: trunkagent, folly@lists, fugalh

FB internal diff: D1358230

10 years agoAdd missing make_unique overload.
Jon Purdy [Sat, 31 May 2014 00:10:38 +0000 (17:10 -0700)]
Add missing make_unique overload.

Summary: C++14 adds this overload but I wanted it today.

Test Plan: It compiles, and this is the definition described in the standard.

Reviewed By: xning@fb.com

Subscribers: folly@lists

FB internal diff: D1338839

10 years agouse NoInt() wrappers in FileUtil
Philip Pronin [Fri, 30 May 2014 07:05:28 +0000 (00:05 -0700)]
use NoInt() wrappers in FileUtil

Summary:
Accidentally spotted this problem.  `folly/FileUtil.h` and
`common/files/FileUtil.h` are now using `*NoInt` wrappers where appropriate.

Test Plan: fbconfig -r common/files folly && fbmake opt -j32

Reviewed By: lucian@fb.com

Subscribers: folly@lists, fbcode-common-diffs@lists

FB internal diff: D1356261

10 years agoMinor edit to comment
Tom Jackson [Fri, 30 May 2014 18:52:55 +0000 (11:52 -0700)]
Minor edit to comment

Summary: I was confused by it, thought rephrasing might help.

Test Plan: Read

Reviewed By: tudorb@fb.com

Subscribers: folly@lists

FB internal diff: D1315612

10 years agoRemove extraneous syscalls if NotificationQueue size() > 1
Dave Watson [Fri, 11 Apr 2014 18:46:40 +0000 (11:46 -0700)]
Remove extraneous syscalls if NotificationQueue size() > 1

Summary:
Currently notification queue does 2 syscalls per item: one read, one write.  We only need the eventfd to notify to wake up the thread, so instead, if the thread is already awake, don't bother writing to the fd.

Benchmark shows that when the queue size() > 1, this is ~4x faster.

Note that this might be unfair if there are multiple consumers: I could imagine a situation where one thread eats all the wakeups written to the fd, so only one thread is actually working.  However, multiple consumers is a bad idea anyway, and I'd consider removing it entirely:  If the same fd is in multiple epoll() loops, _all_ epolls will wake up, resulting in a thundering herd problem.  I don't see any multiConsumer cases in fbcode

Using EFD_SEMAPHORE or not doesn't seem to matter, since hopefully we're only writing 1 wakeup per thread - and it wouldn't work at all for multiConsumer case.

Test Plan:
fbconfig thrift/lib/cpp/test:TNotificationQueueTest; fbamke runtests
fbconfig common/concurrency:QueueBenchmark
fbmake opt
QueueBenchmark --bm_min_iters=10000

Reviewed By: afrind@fb.com

Subscribers: doug, folly@lists, fbcode-common-diffs@lists, alandau, bmatheny, haijunz

FB internal diff: D1272872

Tasks: 2802758

10 years agofolly/wangle: temporarily disable compilation of Thens.cpp
Jim Meyering [Thu, 29 May 2014 20:44:06 +0000 (13:44 -0700)]
folly/wangle: temporarily disable compilation of Thens.cpp

Summary:
This code fails to compile with clang:dev, so don't try for now.
* folly/wangle/test/Thens.cpp: Don't attempt to compile test/Thens.cpp.
See 4412111 for details.  Prompted by clang:dev+MSAN effort, 4090011.

Test Plan:
Run this:
fbconfig --clang --with-project-version clang:dev -r folly/wangle
fbmake runtests
Failed before, passes with this patch.

Reviewed By: hans@fb.com

Subscribers: folly@lists, fugalh

FB internal diff: D1354751

Tasks: 40900114412111

10 years agoAdd shorthand functions to Format.h.
Yedidya Feldblum [Sat, 24 May 2014 18:45:38 +0000 (11:45 -0700)]
Add shorthand functions to Format.h.

Summary:
[Folly] Add shorthand functions to Format.h.

This makes calling code simpler when it does not depend on the raw performance of writing to a stream.

Test Plan:
$ fbconfig -r folly/test
$ fbmake runtests

Reviewed By: tudorb@fb.com

Subscribers: folly@lists, dougw

FB internal diff: D1347353

Tasks: 4391110

10 years agoadd support for whenAll to waitWithSemaphore
Matt Dordal [Fri, 23 May 2014 16:19:20 +0000 (09:19 -0700)]
add support for whenAll to waitWithSemaphore

Summary:
waitWithSemaphore currently doesn't support vector<Try<T>>, unless T is void.
Fix that, and also add a now-required void specialization.

Test Plan:
Add a test that uses vector<Try<bool>>, ensure that the tests compile
(and pass).

Reviewed By: hans@fb.com

Subscribers: folly@lists, fugalh

FB internal diff: D1338528

Tasks: 4389473

10 years agoFuture::value() should throw when unset
Simon Martin [Wed, 21 May 2014 20:31:54 +0000 (13:31 -0700)]
Future::value() should throw when unset

Summary:
Added a test to call Future::value() before the Promise value is set, expecting an exception.
In a dbg build the test failed due on the assertion in Optional::value().
In a opt build the test failed due as no exception was thrown.
There are 2 points where we could throw our exception:
a) Optional::value() - replacing the assertion
b) Future::value()

I'm not sure which location makes the most sense.
With the assertion in Optional it seems that adding the throw here would not be unexpected but this is outside the wangle code.
So as a first pass I've added the throw in Future::value(), and made a new WangleException for this.

Test Plan:
$ fbconfig folly/wangle
$ fbmake runtests

Reviewed By: hans@fb.com

Subscribers: folly@lists, fugalh

FB internal diff: D1340886

10 years agoadded missing includes; also fixed lint issue with noexcept
Daniil Burdakov [Wed, 21 May 2014 17:52:03 +0000 (17:52 +0000)]
added missing includes; also fixed lint issue with noexcept

Summary: subj

Test Plan: unit tests

Reviewed By: tjackson@fb.com

Subscribers: folly@lists

FB internal diff: D1341693

10 years agoMore opensource build fixes
Tudor Bosman [Tue, 20 May 2014 21:32:43 +0000 (14:32 -0700)]
More opensource build fixes

Summary:
- libtool version
- get rid of tiny libraries
- add folly/gen and a bunch of stuff from experimental

Test Plan: built, built a program against it in a ubuntu vm

Reviewed By: davejwatson@fb.com

Subscribers: folly@lists, fugalh

FB internal diff: D1339920

10 years agomake BucketedTimeSeries::addValue() honor old timestamps
Adam Simpkins [Wed, 14 May 2014 20:40:33 +0000 (13:40 -0700)]
make BucketedTimeSeries::addValue() honor old timestamps

Summary:
Previously BucketedTimeSeries()::addValue() documented that it required
time to move forwards.  If it was ever called with a timestamp older
than the most recent one it had seen, it would just use latestTime_ as
the time, and add the value to the most recent bucket.

This changes addValue() so that it always uses the timestamp passed in
by the caller.  If this time value refers to an old bucket that is still
being tracked, the data point will be added to that bucket.  If the time
value is older than the oldest currently tracked bucket, the data point
will be ignored, and false will be returned.

I did consider leaving the current addValue() behavior as-is, and
requiring a separate addHistoricalValue() for when users intentionally
want to try adding old data points.  However, it seems nicer to build
this into the existing addValue() function.  The old behavior of just
replacing the supplied time value seems potentially surprising to users.

This does change the behavior of addValue(), and therefore could affect
the behavior of some programs.  However, up until now no-one should have
been calling addValue() with old time values, as it wouldn't have done
what they want anyway.  I did a brief search through our code base, and
all call sites I saw always called addValue() with the current time.
(Most of the callers use wall clock time, so this change might affect
program behavior if the system time changes after the program starts.
We should ideally change our programs to use monotonic clocks instead.)

Test Plan:
Included a new unit test.

Also compared the timeseries_benchmark results before and after this
change.  Overall this new logic seems to be faster.  For the "all time"
case, the new code is over 2x as fast.  For the normal, non-all-time
case the new code is around 5% faster.

Reviewed By: hans@fb.com

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

FB internal diff: D1338466

10 years agoSome opensource build fixes
Tudor Bosman [Tue, 20 May 2014 15:49:16 +0000 (08:49 -0700)]
Some opensource build fixes

Summary:
- switch to new versions of ax_boost_*.m4
- versioning in libtool
- better checks in configure.ac

Test Plan: built in an Ubuntu VM

Reviewed By: davejwatson@fb.com

Subscribers: folly@lists

FB internal diff: D1338957

10 years agoBuild up signal handler message before writing
Tudor Bosman [Mon, 19 May 2014 19:13:46 +0000 (12:13 -0700)]
Build up signal handler message before writing

Summary: So it doesn't interleave with whatever other threads write to stderr.

Test Plan: folly/experimental/symbolizer/test

Reviewed By: lucian@fb.com

Subscribers: folly@lists

FB internal diff: D1337029

10 years agofix waitWithSemaphore return type
Matt Dordal [Mon, 19 May 2014 20:03:28 +0000 (13:03 -0700)]
fix waitWithSemaphore return type

Summary:
waitWithSemaphore always tried to return a value, which is not what the
underlying implementation did. If the value_type was an object, it would
fail to compile.

Test Plan: unit tests (added one to compile all the variants)

Reviewed By: hans@fb.com

Subscribers: folly@lists, fugalh

FB internal diff: D1326916

10 years agoMake EventHandler::isPending const
Alex Landau [Thu, 15 May 2014 20:23:23 +0000 (13:23 -0700)]
Make EventHandler::isPending const

Summary: Because it just queries state

Test Plan: fbmake

Reviewed By: haijunz@fb.com

Subscribers: folly@lists

FB internal diff: D1332397

10 years agoRemoved old FBVector compatibility functions
Nicholas Ormrod [Thu, 15 May 2014 17:36:38 +0000 (10:36 -0700)]
Removed old FBVector compatibility functions

Summary: FBVector still has some code for gcc-4.6. Removed it.

Test Plan:
fbconfig -r folly && fbmake runtests
fbconfig folly/test/stl_test && fbmake runtests (after enabling)

Reviewed By: robbert@fb.com

Subscribers: folly@lists, sdwilsh

FB internal diff: D1320358

10 years agoRevert "[folly::Subprocess] Set O_CLOEXEC by default when creating pipes to avoid...
Rocky Liu [Tue, 13 May 2014 23:40:54 +0000 (16:40 -0700)]
Revert "[folly::Subprocess] Set O_CLOEXEC by default when creating pipes to avoid race conditions resulting from concurrent Subprocess creations"

Summary: This reverts commit c2f089cf080f2b3effa9efa5e4708b9674437d45.

Test Plan: Compile && folly::Subprocess unit tests

Reviewed By: tudorb@fb.com

FB internal diff: D1327952

10 years agoAlways #define _GNU_SOURCE to pull in pipe2() declarations
Rocky Liu [Tue, 13 May 2014 21:35:37 +0000 (14:35 -0700)]
Always #define _GNU_SOURCE to pull in pipe2() declarations

Summary: [folly::Subprocess] Always #define _GNU_SOURCE to pull in pipe2() declarations

Test Plan: Compile

Reviewed By: tudorb@fb.com

FB internal diff: D1327004