1. 20 May, 2014 15 commits
    • Tudor Bosman's avatar
      Fix Chatty subprocess test, call callback on hangup · 6b20f11e
      Tudor Bosman authored
      Summary:
      The Chatty subprocess test incorrectly assumed that we saw EOF on the last
      read from the child (that is, read() returned 0). That's not the case for two
      reasons: 1. the child is allowed to stall right before it closes its stdout, in
      which case we get EAGAIN, and 2. Subprocess::communicate would close the fd
      without calling the read callback anyway. Fix both such things.
      
      Test Plan: ran test
      
      Reviewed By: njormrod@fb.com
      
      FB internal diff: D1303215
      6b20f11e
    • Dave Watson's avatar
      QueueBenchmark set max read at once · 309fa7e7
      Dave Watson authored
      Summary: Makes a fair comparison between asox queue and notification queue.  THe updated benchmark is just noise in this diff, notificationqueue isn't fast enough (yet) to make a difference.
      
      Test Plan:
      fbconfig common/concurrency; fbmake opt
      ./common/concurrency/QueueBenchmark.sh
      
      Reviewed By: afrind@fb.com
      
      FB internal diff: D1272859
      309fa7e7
    • Andrey Goder's avatar
      Use readNoInt/writeNoInt in folly::Subprocess · b8ec9e50
      Andrey Goder authored
      Summary: We have these helper methods, but are not using them. What sadness.
      
      Test Plan:
      fbconfig -r folly
      fbmake runtests
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D1299720
      b8ec9e50
    • Peter Griess's avatar
      Include <random> in folly/Random.h · e29b86e4
      Peter Griess authored
      Summary:
      - Its methods are being used; include the header
      
      @override-unit-failures
      
      Test Plan: - Build for iOS
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D1299440
      e29b86e4
    • Marc Celani's avatar
      Default to using folly::LifoSem · 9b5a1e4b
      Marc Celani authored
      Summary:
      Unless a service is overloaded, it should be able to clear
      its queue frequently. When this happens, threads fall asleep until
      more work is available in the queue. Waking up threads in LIFO
      order gives us a lot of benefits. First, threads that were most
      recently active are more likely to be mapped to the same cpu core
      and thereby experience better L1 cache hit rate. Second, we can
      madvise away jemalloc arenas on very idle threads. If we wake up
      threads in FIFO order, we will never get a thread to remain idle
      long enough for this to be worthwhile.
      
      folly::LifoSem does just that. Benchmark in which the queue is
      allowed to drain show that we get a substantial increase in
      throughput by waking up threads in LIFO order.
      
      Test Plan:
      QueueBenchmark results summary:
      As expected, benchmarks run faster in the case where the queue is
      able to frequently drain itself, particularly in cases where the
      number of threads is large. Benchmarks run slower when the
      consumers cannot keep up with the producers, particularly when we
      reach the queue capacity and we need to synchronize between
      producers and consumers. However, in this case I think we care
      less about the overhead of the queue itself and more about how
      quickly we can shed the actual underlying load.
      
      Reviewed By: davejwatson@fb.com
      
      FB internal diff: D1298343
      9b5a1e4b
    • Marcelo Juchem's avatar
      fixing split_step documentation · 6205123a
      Marcelo Juchem authored
      Summary: example results were backwards
      
      Test Plan: unit tests
      
      Reviewed By: brg@fb.com
      
      FB internal diff: D1262425
      6205123a
    • Tudor Bosman's avatar
      SymbolizedFrame::name is already null-terminated · 5ed60bc7
      Tudor Bosman authored
      Summary:
      ... as it comes from Elf::getSymbolName, which returns null-terminated C
      strings. So there's no need to copy it into a fixed-size buffer (and have a
      buffer overflow, ouch).
      
      Test Plan: folly/experimental/symbolizer_test, see what else "arc unit" gets us
      
      Reviewed By: tconerly@fb.com
      
      FB internal diff: D1286348
      5ed60bc7
    • Tom Jackson's avatar
      std::move-able MemoryMapping · 2c73945c
      Tom Jackson authored
      Test Plan: unit tests
      
      Reviewed By: lucian@fb.com
      
      FB internal diff: D1290632
      2c73945c
    • Tian Fang's avatar
      Support addValueAggregated() for histogram · 9c428ab9
      Tian Fang authored
      Summary:
      Support addValueAggregated() for histogram to add multiple samples for
      one bucket at one time.
      
      Test Plan: Have a client to call the new API and test in production.
      
      Reviewed By: simpkins@fb.com
      
      FB internal diff: D1286528
      9c428ab9
    • Elizabeth Smith's avatar
      Better <bits/c++config.h> detection · 0630bb0f
      Elizabeth Smith authored
      Summary:
      When worrying about only 2 cpp libraries, detection of "is this libstdc++ or libc++" works, but when throwing in a third option (msvc) this becomes a very brittle way of detecting features.  Also depending on how clang is used it may or may not have this header about
      
      Changed to instead use configuration value for "do we have this header file" for including bits/c++config.h and changed the logic to be identical in all three use cases
      
      Test Plan: fbmake runtests
      
      Reviewed By: njormrod@fb.com
      
      FB internal diff: D1291547
      0630bb0f
    • Elizabeth Smith's avatar
      msvc packed attribute translation · aafd8ff9
      Elizabeth Smith authored
      Summary:
      Provide translations for gcc packed
      
      MSVC has a very very ugly syntax for packing using pragmas which is very different from the gcc attribute
      this makes it very hard to macro around, but lots of ifdefs are also painful - cleanest of the hackery is to simply have push, pop, and attribute macros for packed that define properly depending on the compiler
      
      Test Plan: fbmake runtests
      
      Reviewed By: njormrod@fb.com
      
      FB internal diff: D1279966
      aafd8ff9
    • Andrii Grynenko's avatar
      Future API for CacheClientCommon · b7ccdf65
      Andrii Grynenko authored
      Summary:
      Allow mutable functors in Promise::fulfil.
      
      Facebook:
      Works both with EventBase and without it (thanks to wangle::Future thread-safety). CacheClientImpl lifetime is guaranteed using shared_ptr.
      
      Test Plan: unit test
      
      Reviewed By: stepan@fb.com
      
      FB internal diff: D1291024
      b7ccdf65
    • Adam Simpkins's avatar
      fix off-by-one error in IPAddress::longestCommonPrefix() · dea4e166
      Adam Simpkins authored
      Summary:
      Fix an off-by-one error causing an ASAN abort.  When calling
      longestCommonPrefix() with a full mask, it would compare one byte past
      the end of the address data, and would end up writing past the end of
      the ba array on the stack.
      
      Test Plan:
      Built with ASAN, ran the unit tests, and verified the ASAN failure was
      gone.
      
      Reviewed By: jasmeetbagga@fb.com
      
      FB internal diff: D1284750
      dea4e166
    • Anton Likhtarov's avatar
      Move common/network/IPAddress.h and related to folly/ · dced19f5
      Anton Likhtarov authored
      Summary:
      Moving our internal IP/Mac address libraries to folly/
      
      Facebook:
      We want to get rid of common/ dependencies in Mcrouter since we're going to open source it. Also looking at the original commit, seems like it's been the intention all along, so I just did it.
      
      I tried to keep dependencies intact as much as possible. Changing projects to use this directly should be in separate diffs.
      
      Test Plan:
      Run folly/network and common/network unit tests.
      
      Generate the list of targets with:
      
      ```
      fbgs /$FILE.h | cut -f1 -d: | xargs -L1 dirname | cut -f2- -d/ | sort | uniq
      ```
      
      Then fbconfig + fbmake. Will fix contbuild failures.
      
      Revert Plan:
      
      Reviewed By: simpkins@fb.com
      
      FB internal diff: D1261089
      dced19f5
    • Peter Griess's avatar
      Fix type mismatch in IOBuf::getIov() · fbdb6012
      Peter Griess authored
      Summary: - On iOS, iovec::iov_len is a size_t, which is a uint32_t; convert
      
      Test Plan:
      - fbconfig -r folly && fbmake runtests
      - Builds in fbobjc
      
      Reviewed By: simpkins@fb.com
      
      FB internal diff: D1284931
      fbdb6012
  2. 18 Apr, 2014 23 commits
    • Nicholas Ormrod's avatar
      Fix header ordering lint failures · b215baa2
      Nicholas Ormrod authored
      Summary:
      Headers whose includes are not sufficient cause problems when included
      from other files. An easy way to prevent this is to include the header
      first in its associated cpp file. In fact, we have a lint rule for this.
      However, there are places where this rule is ignored. This diff fixes
      many of them.
      
      Note that a few top-level directories were excluded.
      
      Reviewed By: robbert@fb.com
      
      FB internal diff: D1281032
      b215baa2
    • Elizabeth Smith's avatar
      x64 detection missing an include · b7433faa
      Elizabeth Smith authored
      Summary: rwspinlock.h was missing the portability.h header which made the x64 detection go wonky, but only shows up when used with isolated rwspinlock use
      
      Test Plan: fbmake runtests
      
      Reviewed By: andrei.alexandrescu@fb.com
      
      FB internal diff: D1284387
      
      Blame Revision: D1282140
      b7433faa
    • Elizabeth Smith's avatar
      macro for cross platform x64 detection · 779cbf35
      Elizabeth Smith authored
      Summary: Another cross platform fun macro - this one detects x64 status and requires some portability.h includes (which should only define portability stuff and not actually include anything)
      
      Test Plan: fbmake runtests
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D1282140
      779cbf35
    • Bryan Alger's avatar
      Fix flag naming · d8662420
      Bryan Alger authored
      Summary: doh
      @override-unit-failures
      
      Test Plan: compiled under android
      
      Reviewed By: subodh@fb.com
      
      FB internal diff: D1283177
      d8662420
    • Elizabeth Smith's avatar
      fbstring likely/unlikley ifdef for stuff that doesn't support it · c9b41e27
      Elizabeth Smith authored
      Summary: the fbstring specific unlikely/likely defs were missing the ifdef blocks to avoid breaking things without builtin_expect
      
      Test Plan: fbmake runtests
      
      Reviewed By: njormrod@fb.com
      
      FB internal diff: D1282166
      c9b41e27
    • Hannes Roth's avatar
      (Folly/Gen) Make ranges and sequences take a stepping functor · 8cd97e5f
      Hannes Roth authored
      Summary:
      The functor allows to create ranges and sequences that advance the
      iterator by more than 1 per iteration.
      
      Test Plan: Unit test.
      
      Reviewed By: tjackson@fb.com
      
      FB internal diff: D1228065
      8cd97e5f
    • Hannes Roth's avatar
      (Folly/Gen) Fix compilation with clang · d456b584
      Hannes Roth authored
      Summary:
      Clang chokes because it tries to instantiate both versions of `from<const int*>`, one of which calls `std::begin(const int*)`, which doesn't work. By casting the intializer list to the right type, it can pick the overload.
      
      Clang, because it makes debugging these templates so much better.
      
      Test Plan: `fbconfig --clang folly/gen/test && fbmake runtests_dbg`
      
      Reviewed By: tjackson@fb.com
      
      FB internal diff: D1280888
      d456b584
    • Elizabeth Smith's avatar
      abstract thread_local support · ec06f66c
      Elizabeth Smith authored
      Summary:
      change from using __thread to using FOLLY_THREAD_LOCAL macro, this will allow abstraction over gcc and msvc implementations of thread local (__thread and __declspec(thread)) which have the same semantices and will also allow drop in replacement of thread_local when compiler support for the feature is complete  This doesn't do anything about apple, however, which still has broken __thread support
      
      This doesn't actually change any implementation for now, simply allows for correct compilation
      
      Test Plan: fbmake runtests
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D1278726
      ec06f66c
    • Elizabeth Smith's avatar
      Add missing includes for msvc · f585e98a
      Elizabeth Smith authored
      Summary: MSVC is a stricter compiler and needs additional includes explicitly declared
      
      Test Plan: fbmake runtests
      
      Reviewed By: njormrod@fb.com
      
      FB internal diff: D1277004
      f585e98a
    • Tom Jackson's avatar
      parallel(pipeline) · d3cc50e0
      Tom Jackson authored
      Summary:
      Adding `... | parallel(my | pipe | line) | ...` for parallelizing a portion of a generator pipeline.
      
      ```lang=cpp
      auto factored = from(values)
      | parallel(filter(isEven) | map(square) | sub(count))
      | sum;
      ```
      
      Work is divided evenly among a fixed number of threads using a `MPMCQueue`.
      
      Test Plan: Unit tests and benchmarks testing for a variety of workloads and performance characteristics, including sub-linear (blocking) workloads, linear (mostly math) workloads, and superlinear (sleeping) workloads to simulate real-world use.
      
      Reviewed By: lucian@fb.com
      
      FB internal diff: D638551
      d3cc50e0
    • Marc Celani's avatar
      Introduce LifoSem · 7fbec719
      Marc Celani authored
      Summary: A LIFO semaphore is useful for building a thread pool because we can keep cpu caches warmer by continually reusing the last used thread. This diff introduces a LIFO semaphore to folly.
      
      Test Plan: unit tests
      
      Reviewed By: davejwatson@fb.com
      
      FB internal diff: D1280405
      7fbec719
    • Jun LI's avatar
      Fix folly Uri::host() return value for IPv6 address · 59c7c8ea
      Jun LI authored
      Summary: folly Uri::host() returns leading and trailing brackets for IPv6 host, for example, for URI "http:://[::1]:8080/index.html", host() method returns "[::1]". But square brackets are not part of host in fact, this diff is going to remove brackets for IPv6 host.
      
      Test Plan: fbconfig -r folly/test && fbmake runtests_dbg
      
      Reviewed By: chip@fb.com
      
      FB internal diff: D1276513
      59c7c8ea
    • Elizabeth Smith's avatar
      MSVC translation of noreturn attribute · 934a0b06
      Elizabeth Smith authored
      Summary:
      Provide translations for gcc noreturn attribute
      
      __attribute__((noreturn)) is gcc specific, clang understands it on nix systems, but for msvc __declspec(noreturn) is the compiler specific version, which clang will imitate/use on windows.  There was already a FOLLY_NORETURN in portability.h, however because of __declspec limitations it must prefix the declaration, not postfix.  The gcc noreturn attribute does not have this limitation and will work prefixed OR postfixed, so to keep from turning code into spaghetti nonsense, the macro was moved to the front of declations where it is currently used.  This will allow it to work with the proper definitions on clang, clang on windows, gcc, and msvc
      
      Test Plan: fbmake runtests
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D1279466
      934a0b06
    • Elizabeth Smith's avatar
      MSVC always_inline and noinline __attributes__ translation · 2c2e0f6e
      Elizabeth Smith authored
      Summary:
      Provide translations for gcc always_inline and noinline attribute
      
      Change to using a macro from portability.h for attributes for using always_inline and noinline for cross platform support
      
      Test Plan: fbmake runtests
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D1279652
      2c2e0f6e
    • Victor Loh's avatar
      Use StringPiece instead of String · 30a71566
      Victor Loh authored
      Summary:
      Using StringPiece makes it easier than std::string
      
      Facebook: Motivation for this diff is found in D1253595
      
      Test Plan:
      Added new unittest
      
      fbconfig folly/io/test && fbmake runtests_opt
      
      Reviewed By: simpkins@fb.com
      
      FB internal diff: D1276185
      30a71566
    • Elizabeth Smith's avatar
      uint isn't portable and makes some compilers angry, change to unsigned int · 32d518c3
      Elizabeth Smith authored
      Summary: As part of the windows port, uint is not defined as a type and is not standard, it makes msvc choke, a simple change to unsigned int fixes the issue
      
      Test Plan: fbmake runtests
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D1278487
      32d518c3
    • Tudor Bosman's avatar
      Add non-const operator[] to TypedIOBuf · 0c8631dc
      Tudor Bosman authored
      Test Plan: used it
      
      Reviewed By: lucian@fb.com
      
      FB internal diff: D1277063
      
      @override-unit-failures
      0c8631dc
    • Lucian Grijincu's avatar
      folly: improve ProducerConsumerQueueBenchmark (misplaced doNotOptimizeAway) · e39dfd9d
      Lucian Grijincu authored
      Summary:
      as per discussion from https://phabricator.fb.com/D1274352
      
      After changing the queue length to be a small value (100) I didn't see
      improvement from cache alignment of atomics (too much noise). Dropping
      that and just fixing the benchmark.
      
      Test Plan: n/a
      
      Reviewed By: ngbronson@fb.com
      
      FB internal diff: D1276591
      e39dfd9d
    • Nicholas Ormrod's avatar
      Fix apparent race in SubprocessTest · 1321eef0
      Nicholas Ormrod authored
      Summary:
      The code originally contained the line
      
      EXPECT_EQ((rcount == lineCount), r); // EOF iff at lineCount
      
      Which asserted that, on the last iteration, EOF was being read (and thus
      r was true).
      
      This line has been causing errors in contbuild. There seem to be two
      issues at play.
      
      First, the left hand side of the EXPECT_EQ is always false. rcount is
      incremented three lines down, and the (implicit) loop ends when rcount
      equals lineCount. This means that, on the last iteration, rcount is
      actually one less than lineCount. Hence the check is effectively
      asserting that r is false.
      
      The second issue is that r is rarely true. Empirically, a necessary but
      not sufficient condition is that there be lots of other processes
      running at the same time (such as when running fbconfig -r folly &&
      fbmake runtests_opt). This would explain why the test passes during
      development but fails in contbuild.
      
      I am guessing that, when there are few processes running, Subprocess is
      predictably ceasing to read before whichever other process yields EOF,
      and that this does not always happen when there is resource contention.
      
      As an immediate fix, I am asserting that r may only be true on the last
      iteration. Could someone (cc @tudorb) who is more familiar with the
      intricacies of Subprocess please check to see if this is an idiosyncrasy
      of the test, or if there is actually an underlying bug.
      
      Test Plan:
      Before the change, run fbconfig -r folly && fbmake runtests_opt
      repeatedly. Notice that most of the iterations yield an error from line
      376 (which is consistent with contbuild error logs).
      
      After the change, notice that the error disappears.
      
      Reviewed By: andrewjcg@fb.com
      
      FB internal diff: D1269124
      1321eef0
    • Lucian Grijincu's avatar
      folly: gen: pmap: parallel version of map · 89c3562e
      Lucian Grijincu authored
      Summary:
      same as map, but runs it's argument in parallel over a number of threads.
      
      @override-unit-failures
      
      Test Plan: added test
      
      Reviewed By: tjackson@fb.com
      
      FB internal diff: D1258364
      89c3562e
    • Alexey Spiridonov's avatar
      Change child's working directory · 188e13f3
      Alexey Spiridonov authored
      Summary: Changing the parent's WD is prone to race conditions of various sorts, and needlessly alters parent state. Python's subprocess also has this feature.
      
      Test Plan: fbmake dbg _bin/folly/test/subprocess_test ; ../_bin/folly/test/subprocess_test
      
      Reviewed By: agoder@fb.com
      
      FB internal diff: D1269526
      188e13f3
    • Jim Meyering's avatar
      folly: allow to build with clang.dev (flex arrays vs. lambda) · a6e257a5
      Jim Meyering authored
      Summary:
      * folly/test/CacheLocalityTest.cpp (contentionAtWidth): Work around
      clang's prohibition against using flexible arrays in a lambda.
      
      Test Plan:
      fbconfig --clang --with-project-version clang:dev folly/test \
      && fbmake runtests
      
      Reviewed By: ngbronson@fb.com
      
      FB internal diff: D1263620
      a6e257a5
    • Philip Pronin's avatar
      configurable alignment for Arena · 970c7961
      Philip Pronin authored
      Summary: Allow specifying custom alignment.
      
      Test Plan: fbconfig -r folly/test && fbmake opt -j32
      
      @override-unit-failures
      
      Reviewed By: lucian@fb.com
      
      FB internal diff: D1264851
      970c7961
  3. 09 Apr, 2014 2 commits
    • ptarjan's avatar
      Make header compatible with warp · 074bdb7f
      ptarjan authored
      074bdb7f
    • Philip Pronin's avatar
      fix ConcurrentSkipList::Recycler layout · d92b1b90
      Philip Pronin authored
      Summary:
      D1261546 introduced regression in `sizeof(ConcurrentSkipList)`.
      In case of `NodeAlloc = folly::SysAlloc`, size of an empty `NodeAlloc` struct
      is 1 byte, due to the alignment requirements of the next field, it got
      translated into wasting 8 bytes.
      
      Test Plan: fbconfig -r folly/test && fbmake opt -j32
      
      @override-unit-failures
      
      Reviewed By: lucian@fb.com
      
      FB internal diff: D1264730
      d92b1b90