1. 05 Jun, 2019 3 commits
    • Shrikrishna Khare's avatar
      fbcode_builder: getdeps: fboss: add iproute2 fetcher · cfed36bd
      Shrikrishna Khare authored
      Summary:
      This is towards getting open source FBOSS to build using fbcode_builder.
      iproute2 is one of the dependencies for FBOSS. This patch adds a manifest file
      to build the specific version of iproute2 needed for FBOSS.
      
      Additionally, the default git clone depth of 100 is insufficient for the
      version of iproute2 FBOSS depends on. Thus, this patch extends the git SCHEMA
      to add optional argument depth. The default remains 100.
      
      The usual /configure --prefix does not work for iproute2. Thus, we need to add
      a custom builder that:
        - copies sources to build directory, builds, and
        - installs to installed directory using DEST_DIR.
        - it must also explicitly copy include from build dir to install dir
      
      Reviewed By: wez
      
      Differential Revision: D15588809
      
      fbshipit-source-id: ac5eab24134e078d88b85b4be433c78b05ef8ce5
      cfed36bd
    • Yedidya Feldblum's avatar
      Use std interface in fibers mutex types · d4774463
      Yedidya Feldblum authored
      Summary:
      [Folly] Use std interface in fibers mutex types: `try_lock_for`, `lock_shared`, etc.
      
      This makes fibers mutex types play well with `Synchronized`.
      
      Reviewed By: mnv104
      
      Differential Revision: D15440755
      
      fbshipit-source-id: 068b0c0b973577729f76f78c9063ff2ec06f4d90
      d4774463
    • Marshall Cline's avatar
      pipe fittings between a container/range-v3 and a folly::gen · 45f4b89d
      Marshall Cline authored
      Summary:
      Create pipe-adapters ("pipe fittings") that allow a `|`-based pipeline mixing {std-containers and/or range-v3} with folly::gen, e.g.,
      
      ```
      auto result = myVec              // anything consistent with range-v3 or these adapters
          | ranges::view::filter(...)  // zero-or-more range-v3 pipe-elems
          | <adapter-goes-here>        // <==**one of the pipe-adapters provided by this task**
          | folly::gen::blah();        // trailing pipe-elems are folly::gen
      ```
      
      This diff supplies only adapters that transition from {std-containers and/or range-v3} to folly::gen, but not the other way around.
      
      Q&A:
      
      * Why distinguish containers from range-v3's? E.g., container_to_gen vs. rangev3_to_gen?
          * Containers and range-v3's have different copy-costs: range-v3's have O(1) copy
          * Using two different names lets us separate the implementations so we can know which can be copied without significant overhead.
      * Why `#include` range-v3 from inside folly::gen? Why the dependency?
          * That `#include` / dependency adds value to the process, and it is included only for the client-files that need it.
          * It adds value to the process since the subset of client-files to be migrated are precisely the same subset of client-files that _need_ to include range-v3.
          * The alternative would be to add the `#include` out in all the various client-files during the migration process, and we will do that as the last step in the migration process.
          * The migration process is sped up by including range-v3 for that specific subset of client-files _and_ it hurts no one since only those who need that `#include` actually get it.
          * Note: we limit the `#include` to the subset of files to be migrated via the `FOLLY_USE_RANGEV3` define; see folly-config.h.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D15035294
      
      fbshipit-source-id: 694979850d1f35dd382e3afde792ea51a2397af0
      45f4b89d
  2. 04 Jun, 2019 13 commits
    • Adam Simpkins's avatar
      update EventBaseTest to use precise timing with libevent2 · c3ac4113
      Adam Simpkins authored
      Summary:
      Change the EventBaseTest code to request precise timing from libevent.
      libevent 2.1+ uses a coarse monotonic clock by default on Linux.
      This causes several of folly's timing-related tests for EventBase to fail most
      of the time.
      
      This changes the tests to request precise timing from libevent2, using the
      `EVENT_PRECISE_TIMER`.  While we can request this programmatically, doing so
      portably across libevent versions is awkward, so the environment variable is
      the easiest solution for now.
      
      Alternatively we could change the tests to use larger, coarser timeouts to
      make them pass reliably.  However, this would make the tests slower.
      
      Differential Revision: D15528322
      
      fbshipit-source-id: 20dc55de36235e63910cf7fb5b67c6f2d509cc15
      c3ac4113
    • Adam Simpkins's avatar
      put local classes in EventBaseTest.cpp inside an unnamed namespace · 7bf08cd2
      Adam Simpkins authored
      Summary: Put file-local classes and helper functions into an unnamed namespace.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D15528323
      
      fbshipit-source-id: 9e90aafe4382d9ba237823fea1e68dbea7fa1f2f
      7bf08cd2
    • Yedidya Feldblum's avatar
      Fix references to TTransportException · 13ae097b
      Yedidya Feldblum authored
      Summary: [Folly] Fix references to `TTransportException` in `folly/io/async/` to refer to `AsyncSocketException`.
      
      Reviewed By: jmswen, knekritz
      
      Differential Revision: D15628173
      
      fbshipit-source-id: f6d36ede5e8b33d9407751733bcc9a7fa764815c
      13ae097b
    • Joe Loser's avatar
      Fix -Wstring-plus-int in FixedStringTest.cpp (#1148) · 7b7cc4e6
      Joe Loser authored
      Summary:
      - Clang 8 warns about appending integers to a string using `operator+`
        without a cast.
      
      ```
      ../folly/test/FixedStringTest.cpp:353:23: warning: adding 'unsigned int' to a string does not append to the string [-Wstring-plus-int]
        a.append("X world!" + 2u, 5u);
                 ~~~~~~~~~~~^~~~
      ../folly/test/FixedStringTest.cpp:353:23: note: use array indexing to silence this warning
        a.append("X world!" + 2u, 5u);
                            ^
                 &          [   ]
      ../folly/test/FixedStringTest.cpp:354:23: warning: adding 'unsigned int' to a string does not append to the string [-Wstring-plus-int]
        a.append("X world!" + 7u);
                 ~~~~~~~~~~~^~~~
      ../folly/test/FixedStringTest.cpp:354:23: note: use array indexing to silence this warning
        a.append("X world!" + 7u);
                            ^
                 &          [   ]
      ../folly/test/FixedStringTest.cpp:365:23: warning: adding 'unsigned int' to a string does not append to the string [-Wstring-plus-int]
        a.append("X world!" + 2u, 5u);
                 ~~~~~~~~~~~^~~~
      ../folly/test/FixedStringTest.cpp:365:23: note: use array indexing to silence this warning
        a.append("X world!" + 2u, 5u);
                            ^
                 &          [   ]
      ../folly/test/FixedStringTest.cpp:366:23: warning: adding 'unsigned int' to a string does not append to the string [-Wstring-plus-int]
        a.append("X world!" + 7u);
                 ~~~~~~~~~~~^~~~
      ../folly/test/FixedStringTest.cpp:366:23: note: use array indexing to silence this warning
        a.append("X world!" + 7u);
                            ^
                 &          [   ]
      ```
      
      - Fix this warning by creating a local char[] and using that to append
        to the fixed string
      Pull Request resolved: https://github.com/facebook/folly/pull/1148
      
      Reviewed By: ericniebler
      
      Differential Revision: D15618465
      
      Pulled By: yfeldblum
      
      fbshipit-source-id: 7f72b3597f51d99665da85744aeb8805eb2e8f00
      7b7cc4e6
    • Yedidya Feldblum's avatar
      Fix PriorityUnboundedBlockingQueue priority translation · de733c9a
      Yedidya Feldblum authored
      Summary: [Folly] Fix `PriorityUnboundedBlockingQueue` priority translation from `Executor` priorities to offsets as used by `PriorityUnboundedBlockingQueueSet`.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D15619435
      
      fbshipit-source-id: 1c5d4d68dfde7f9db07d64f40e73717b48a05ed1
      de733c9a
    • Neel Goyal's avatar
      Fix issue when reading more than 2GB · 07d59092
      Neel Goyal authored
      Summary: If performRead is called with bufLen > 2GB then overflow occurred with the value passed to SSL_read.  We'll clamp it here. This should be fine since performRead will be called again as there is more data to read.
      
      Reviewed By: andriigrynenko, knekritz, mingtaoy
      
      Differential Revision: D15625000
      
      fbshipit-source-id: 8633686a76baebd796139f3b20c6f7286339fd96
      07d59092
    • Kyle Nekritz's avatar
      Return 1 on success in OPENSSL_init_ssl compatibility implementation. · 6c11bbdc
      Kyle Nekritz authored
      Summary: Exposed by D15610738.
      
      Reviewed By: ngoyal
      
      Differential Revision: D15622920
      
      fbshipit-source-id: f3058c69098ae740d43f27e8161e99b3c5a6b995
      6c11bbdc
    • Matthieu Martin's avatar
      Simplify doSetContextData · fd879f06
      Matthieu Martin authored
      Summary:
      The main change is to grab a wlock in doSetContextData, which enables to make the code more readable, and (insignificantly) more efficient.
      
      Grabbing the wlock directly is also strictly better for both `set` and `override`.
      `setIfAbsent` is the only one to potentially suffers from the lock change, in the case where it already exists. But `setIfAbsent` isn't used by either of the guards, which are the recommended way of changing values in RequestContext. So it seems incorrect to optimize for it, and overkill to fork the code.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D15604768
      
      fbshipit-source-id: 44f564b09ff50e8bfe0e1c4cf5ee2d77b654e929
      fd879f06
    • Orvid King's avatar
      Add a basic utility for checked addition of unsigned integers · c79ac334
      Orvid King authored
      Summary: A very basic function that if done incorrectly will get optimized away as undefined behavior. For now keep things simple and only support addition of unsigned values.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D15609542
      
      fbshipit-source-id: 70d5fde784f57d3d52e6122352a885d7a835f104
      c79ac334
    • Yedidya Feldblum's avatar
      Fix SerialExecutor task destruction order · da3a4406
      Yedidya Feldblum authored
      Summary: [Folly] Fix SerialExecutor task destruction order where tasks are destroyed outside of the request-context scope.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D15618395
      
      fbshipit-source-id: e2ec8e42137d14f549f92dbc96a904eadcc0a587
      da3a4406
    • REDMOND\acoates's avatar
      Allow building x86 and arm on msvc (#1147) · 436efbfe
      REDMOND\acoates authored
      Summary:
      A couple of changes to support building folly in MSVC/win32 for x86 and arm platforms.
      Pull Request resolved: https://github.com/facebook/folly/pull/1147
      
      Reviewed By: Orvid
      
      Differential Revision: D15592309
      
      Pulled By: yfeldblum
      
      fbshipit-source-id: 97860ab9309e5492bfadac56079af735741d4a2c
      436efbfe
    • Mingtao Yang's avatar
      Fail early in folly::ssl::init() if we can't initialize · f8b36eab
      Mingtao Yang authored
      Reviewed By: yfeldblum
      
      Differential Revision: D15610738
      
      fbshipit-source-id: 367919db6465536e215735400652d33290930ca0
      f8b36eab
    • Stiopa Koltsov's avatar
      folly/string: better strerror_r detection · fa3eb5b1
      Stiopa Koltsov authored
      Summary:
      There are two variants of `strerror_r` function, one returns
      `int`, and another returns `char*`. Selecting proper version using
      preprocessor macros portably is extremely hard.
      
      For example, on Android function signature depends on `__USE_GNU` and
      `__ANDROID_API__` macros (https://git.io/fjBBE).
      
      So we are using C++ overloading trick: we pass a pointer of
      `strerror_r` to `invoke_strerror_r` function, and C++ compiler
      selects proper function.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D15484722
      
      fbshipit-source-id: fc0bd45fa67dc401631ffc185c9fad231e4a48a0
      fa3eb5b1
  3. 03 Jun, 2019 6 commits
    • Matthieu Martin's avatar
      Avoid extra lookup in overrideContextData · 03078807
      Matthieu Martin authored
      Summary: Title, unecessary cost in case of conflict
      
      Reviewed By: yfeldblum
      
      Differential Revision: D15604536
      
      fbshipit-source-id: ad40c84b822a96a688f810b24b539ac162fdcc59
      03078807
    • REDMOND\acoates's avatar
      Add some explicit casts to prevent some compiler warnings (#1145) · 762658ad
      REDMOND\acoates authored
      Summary:
      As part of trying to get our internal usage of folly off a fork, we have various compiler warnings set ridiculously high.
      
      This gets rid of a couple of warnings that we hit in folly code.
      Pull Request resolved: https://github.com/facebook/folly/pull/1145
      
      Reviewed By: LeeHowes, Orvid
      
      Differential Revision: D15586209
      
      Pulled By: yfeldblum
      
      fbshipit-source-id: dc3ebffbddd0b82f2c2ee719a95b7fcfe551e074
      762658ad
    • Woo Xie's avatar
      catch the exception of getPeerAddress/getLocalAddress, separately · fe97992a
      Woo Xie authored
      Summary: swap the order of getLocalAddress() and getPeerAddress(), so we are more likely to log the local address after exception happens.
      
      Reviewed By: knekritz
      
      Differential Revision: D15559814
      
      fbshipit-source-id: 50b7a964d6c3add2e4ae1da9fde8e9e4e67e5715
      fe97992a
    • Matthieu Martin's avatar
      Avoid mutex in RequestContext setShallowCopyContext · 40e49acc
      Matthieu Martin authored
      Summary:
      Grabbing the mutex of the newly created context is unecessary cost.
      folly::Synchronized's constructor support this optimization, so it's an easy change.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D15600165
      
      fbshipit-source-id: e92570a7ac7ac1e908d7c797bed6de22f940d387
      40e49acc
    • Matthieu Martin's avatar
      Optimize RequestData shallow copying · 0f3478f4
      Matthieu Martin authored
      Summary:
      The shallow copy code path currently iterates and copies all values manually. Instead of benefiting from the underlying data collection's implementation of self-copy.
      At the very least, it's simpler looking code.
      
      Inheriting unique_ptr is usually discouraged, but in this specific (internal impl detail) use case, I can't foresee any risk.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D15599260
      
      fbshipit-source-id: 73edea27a27e8fbc8b057cf3e974ee3d83a6e760
      0f3478f4
    • Gautham B A's avatar
      Fix typos in README.md · c719177f
      Gautham B A authored
      Summary: Pull Request resolved: https://github.com/facebook/folly/pull/1141
      
      Reviewed By: LeeHowes
      
      Differential Revision: D15560029
      
      Pulled By: yfeldblum
      
      fbshipit-source-id: 5f0d5ee8d09be834d1216d4c39244e0855d2dc0f
      c719177f
  4. 01 Jun, 2019 5 commits
  5. 31 May, 2019 2 commits
    • Roman Leventov's avatar
      Refer to 7-bit tag in comment · 48926dfb
      Roman Leventov authored
      Summary: Pull Request resolved: https://github.com/facebook/folly/pull/1142
      
      Reviewed By: shixiao
      
      Differential Revision: D15574540
      
      Pulled By: yfeldblum
      
      fbshipit-source-id: 2ce91f7510f0b278677c15b3a9f1f80b43ff8998
      48926dfb
    • Miroslav Crnic's avatar
      SerialExecutor correctly set RequestContext · 76747b04
      Miroslav Crnic authored
      Summary:
      SerialExecutor can not rely on parent to save RequestContext for him as it is not guaranteed that an enqueued function will be executed from the parent callback that was scheduled at the same time.
      This diff captures RequestContext in a lambda and sets it correctly
      
      Reviewed By: shixiao
      
      Differential Revision: D15381223
      
      fbshipit-source-id: 9b3ab1f96e57eb5e697efb52105d80c2899a03e7
      76747b04
  6. 30 May, 2019 2 commits
    • Rui Zhang's avatar
      Add eligible-for-elision accessors to folly::SharedMutex. · 9feea214
      Rui Zhang authored
      Summary: Lock elision requires non-mutating functions that check if lock acquisition could succeed. This diff adds such functions to folly::SharedMutex, including eligible_for_lock_elision(), eligible_for_lock_upgrade_elision(), and eligible_for_lock_shared_elision(). The diff also adds assertions to validate these functions' correctness under single-threaded executions.
      
      Reviewed By: nbronson
      
      Differential Revision: D15545398
      
      fbshipit-source-id: 0037d473c9dd360f7143ea4c4c9092fb9bb7f5f9
      9feea214
    • Phil Willoughby's avatar
      mark lock holders with nodiscard · 1ebd3b04
      Phil Willoughby authored
      Summary: Acquiring a lock into an unused temporary is generally a bug. Anyone wanting to do this can suppress their compiler's warning by explicitly `static_cast`ing the lock holder to void.
      
      Reviewed By: vitaut
      
      Differential Revision: D15504563
      
      fbshipit-source-id: 1033f6a1d4044b9698934b73eefebfe83602a2a5
      1ebd3b04
  7. 29 May, 2019 4 commits
    • Yedidya Feldblum's avatar
      Use a M:N caches-to-lifetimes in SingletonThreadLocal · 670c29f0
      Yedidya Feldblum authored
      Summary:
      [Folly] Use a M:N caches-to-lifetimes in `SingletonThreadLocal`.
      
      Sometimes the compiler will not merge cache and lifetime thread-local variables in expected ways, so be resilient. More details in #1135 and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90562.
      
      At the same time, move the tracking into the wrapper. The lifetime was an intrusively-linked-list node which was clever and which was allocation-free but which increased the TLS requirement per instantiation of `SingletonThreadLocal`. Moving the tracking into the wrapper decreases the TLS requirement, although the tracking now requires heap allocations.
      
      Fixes #1135.
      Closes #1138.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D15508024
      
      fbshipit-source-id: a344e8dd52bd52724ad85b0fc88d6a2a349952ac
      670c29f0
    • Rui Zhang's avatar
      Fix cacheline padding in folly/test/SharedMutexTest with alignment. · 4856057b
      Rui Zhang authored
      Summary: The cacheline padding in folly/test/SharedMutexTest is not actually functional since the compiler is free to rearrange and optimize away local variables. This diff fixes the cacheline padding by aligning the false-sharing critical values.
      
      Reviewed By: nbronson
      
      Differential Revision: D15523241
      
      fbshipit-source-id: c51b1e4cd78ab33f75fa93faf0a0346ec602f97c
      4856057b
    • Yedidya Feldblum's avatar
      Move executor to local var immediately in doCallback · 47ef08c0
      Yedidya Feldblum authored
      Summary:
      [Folly] Move executor to local var immediately in `doCallback`, and always move it into the callback.
      
      (Note: this ignores all push blocking failures!)
      
      Reviewed By: andrewcox
      
      Differential Revision: D15532854
      
      fbshipit-source-id: 971a6a64ad3c47c9f5e9f75907a568f9d59b1000
      47ef08c0
    • Joe Loser's avatar
      Replace some NDEBUG with kIsDebug (#1128) · 0236a802
      Joe Loser authored
      Summary:
      - Replace some calls sites from `NDEBUG` to `kIsDebug`.
      - Not every call site is changed; there are a few useful cases of
        `NDEBUG` still. `xlog` macros are one of them. Another is where we
        conditionally define a variable in a local scope and then use it in an
        `assert`.
      Pull Request resolved: https://github.com/facebook/folly/pull/1128
      
      Reviewed By: aary
      
      Differential Revision: D15490848
      
      Pulled By: yfeldblum
      
      fbshipit-source-id: 4f2d1689f90baa25d3ba9e99a2a388d9cfc43f18
      0236a802
  8. 28 May, 2019 2 commits
    • Yedidya Feldblum's avatar
      Cut extra return in Core::doCallback · c3cb8f09
      Yedidya Feldblum authored
      Summary: [Folly] Cut extra `return` statement in `Core<T>::doCallback`.
      
      Reviewed By: Orvid
      
      Differential Revision: D15527963
      
      fbshipit-source-id: 9396f9ac2b246676b33d13c87e24dd42198a11ec
      c3cb8f09
    • Yedidya Feldblum's avatar
      Template fibers baton timed-wait over the deadline types · 8e6901ad
      Yedidya Feldblum authored
      Summary:
      [Folly] Template fibers baton timed-wait over the deadline types, rather than over the timeout types and rather than fixing a single timeout type.
      
      Templating it over the deadline types permits specifying the clock and permits passing a single deadline through unchanged through multiple time-delayed layers of code without skew, and templating it rather than fixing it over a single timeout type permits caller-specified fine-grained or coarse-grained timings.
      
      Currently, the `EventBase` timers do not parameterize over the deadline types, so the fiber version of timed-wait must for now convert to a fixed timeout type.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D15448177
      
      fbshipit-source-id: aa3fdbffdcb83cbfd1571780ba431a1004beb347
      8e6901ad
  9. 27 May, 2019 1 commit
    • Yuhan Hao's avatar
      update README.md on ubuntu and gcc version · 988daad8
      Yuhan Hao authored
      Summary: it seems since D15286181, we updated docker os_image to ubuntu18 and gcc7. this diff changes the README.md to reflect the change.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D15513580
      
      fbshipit-source-id: 0a3518c21c912903921946850bd08c948f09c295
      988daad8
  10. 25 May, 2019 1 commit
    • Yedidya Feldblum's avatar
      Disable TLS optimization in PIC mode for SingletonThreadLocal · 2320c70c
      Yedidya Feldblum authored
      Summary:
      [Folly] Disable TLS optimization in PIC mode for `SingletonThreadLocal`.
      
      In PIC mode, TLS offsets must be translated to addresses at runtime via calls to `__tls_get_addr`. Since there is not much of a small inline path or a fast inline fast path anymore anyway in PIC mode, might as well skip the bulky slow caching.
      
      Also, some versions of gcc do not properly support this code in shared libraries. Details in #1135 and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90562.
      
      Fixes #1135.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D15468086
      
      fbshipit-source-id: 038e13f900fe56205c1333a620ea3bfa468c47ad
      2320c70c
  11. 24 May, 2019 1 commit
    • Greg McGary's avatar
      Avoid redefinition of mmsghdr with Android NDK unified headers · 41ed69c4
      Greg McGary authored
      Summary:
      Avoid redefinition of mmsghdr with newer Android NDK unified headers.
      
      Unified headers unconditionally define `struct mmsghdr`, but the `sendmmsg` and `recvmmsg` system calls are conditional on API level. API 21 is the first level that supports them.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D15344307
      
      fbshipit-source-id: 6f03197cc346511ce7a02f1468c35313140a8fd7
      41ed69c4