1. 19 Jul, 2016 9 commits
    • Christopher Dykes's avatar
      Wrappers folly::chrono::clock_gettime and clock_gettime_ns · 5ab482b1
      Christopher Dykes authored
      Summary:
      On Linux hosts, the fast path to get the current time in
      nanoseconds without doing a syscall to the kernel is available via the
      VDSO kernel-runtime interface.
      
      In this diff, I:
      
      1. Expose portability wrappers `folly::chrono::clock_gettime()` and
      `folly::chrono::clock_gettime_ns()`
      2. Implement a VDSO wrapper on Linux hosts to implement those without
      a round-trip to the kernel
      
      Depends On D3418054
      
      Reviewed By: bmaurer
      
      Differential Revision: D3418087
      
      fbshipit-source-id: 3fb99f0dd946f19ba29d0d52a1038dad3556bafd
      5ab482b1
    • Steve Muir's avatar
      Generate a pkg-config file for Folly · 4786b768
      Steve Muir authored
      Summary: First cut at autoconf rules for generating a pkg-config file for Folly. The only interesting part is that we want to handle packages that provide their own .pc files as dependencies rather than just stuffing them into the list of libraries required from packages that don't provide .pc.
      
      Reviewed By: simpkins
      
      Differential Revision: D3556611
      
      fbshipit-source-id: d1c5f89416d1d96d2cdf5ccdc5bd7117fb822a82
      4786b768
    • Christopher Dykes's avatar
      Handle small_vectors with 0 inline capacity correctly · 6a3ea696
      Christopher Dykes authored
      Summary: It is an error to attempt to get the size of a zero length array, such as `unsigned char[0]`, which is what you get if `MaxInline` has been passed in as 0. We can work around this by simply defining `InlineStorageType` to be `void*` if the size is exactly 0, which will result in the capacity correctly being stored out of line.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3572898
      
      fbshipit-source-id: c96bb7cc6a890044bb74b0f6d5238c503552ee25
      6a3ea696
    • Elliott Clark's avatar
      Correctly use iters_ in ProducerConsumerQueueBenchmark · 26b139fc
      Elliott Clark authored
      Summary: iters was only being used on one side of the producer/consumer.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3588593
      
      fbshipit-source-id: 5e9a8a02bb9addbd6f936b8cc411d58cdf82b6e2
      26b139fc
    • Yedidya Feldblum's avatar
      Make the mprotect variant of asymmetricHeavyBarrier work when mlock fails · c17a113e
      Yedidya Feldblum authored
      Summary: [Folly] Make the `mprotect` variant of `asymmetricHeavyBarrier` work when `mlock` fails.
      
      Reviewed By: djwatson
      
      Differential Revision: D3585948
      
      fbshipit-source-id: c3a46884434b7f9da9caa9cf203573f9e3ce7444
      c17a113e
    • Michael Lee's avatar
      Fix macro check in SysMembarrier · 7dd33144
      Michael Lee authored
      Summary:
      FOLLY_X64 is usually defined, so check whehter it is defined
      to 0 or 1.  In addition, memory barriers are not necessarily widely
      available on the mobile platforms. What leads me to believe this is
      that, at least for older ndk's, atomics are not guaranteed to work for
      multicore platforms.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D3586806
      
      fbshipit-source-id: 3ac8c4b74cac09e41bc3cb65c8adc2732b8b2256
      7dd33144
    • Wez Furlong's avatar
      folly: unconditionally include boost mutex definitions on macOS · 06064ddf
      Wez Furlong authored
      Summary:
      macOS doesn't have timedwait functionality and this header file was
      gating including the boost headers on that check which caused dependent modules
      to fail to compile because `boost::mutex` and `boost::recursive_mutex` were not
      known to the compiler.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3585470
      
      fbshipit-source-id: 7f8d9603e95ce01328103c7c6ac0bc75a35ddf4d
      06064ddf
    • Christopher Dykes's avatar
      Make sure to return from atomicHashArrayInsertRaceThread · 9dbb52ab
      Christopher Dykes authored
      Summary: Because, unfortunately, `pthread_exit` is not marked as noreturn in the pthread library primarily used on Windows, we need to return something to avoid errors.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3571465
      
      fbshipit-source-id: 4713b2364d6584ae255fb83cd21406fdc33ee299
      9dbb52ab
    • Andrii Grynenko's avatar
      Use membarrier in TLRefCount · 3f0064f6
      Andrii Grynenko authored
      Summary: membarrier guarantees that there's at most one update to thread-local counter, which collecting thread may not see.
      
      Reviewed By: djwatson
      
      Differential Revision: D3532952
      
      fbshipit-source-id: 6106bfe87c70c5f864573a424662778e20423bbb
      3f0064f6
  2. 18 Jul, 2016 5 commits
    • Wez Furlong's avatar
      folly: improve setThreadName for macOS · cf21fddd
      Wez Furlong authored
      Summary:
      Since OS X 10.6 it is possible to set the name of the current thread.
      This diff adjusts our setThreadName routine to do this, partially fixing
      the associated test case.  Even though this doesn't completely cover
      all cases it is still a valid improvement: most callers are
      threads setting their own name.
      
      I've amended the tests so that they can accomodate systems that cannot
      set the names of other threads.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3576281
      
      fbshipit-source-id: 13caf0dca6496aa2da897631e8d7327a6ee452bb
      cf21fddd
    • Andrii Grynenko's avatar
      Fix mocking to support multiple overrides · 46763a64
      Andrii Grynenko authored
      Summary: When installing the mock, we should make sure to remove singleton from the creation_order list.
      
      Differential Revision: D3580725
      
      fbshipit-source-id: dfb489de1be860ab639380644eab0b45a07a1450
      46763a64
    • Christopher Dykes's avatar
      Always pack small_vector · 71b5c881
      Christopher Dykes authored
      Summary:
      The check was overly restrictive, the conditional packing was originally used to limit it to GCC only (as it used the `__attribute__` directly), but that restriction is no longer needed as `FOLLY_PACK_*` will be defined appropriately for whatever platform we are currently on.
      
      This just switches it to unconditionally use the `FOLLY_PACK_*` macros rather than defining it's own `FB_PACK_*` macros.
      
      See https://github.com/facebook/folly/commit/aafd8ff9151615a8de09682d41d1c29966e4c8fe for where the `FB_PACK_*` macros could originally have been removed.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3373779
      
      fbshipit-source-id: 9e41b0836f8ba12de4f37aba58c51f841be08b41
      71b5c881
    • Christopher Dykes's avatar
      Make static analysis happy about the length of patternBuf · 9c4ce90b
      Christopher Dykes authored
      Summary: The static analysis doesn't quite understand that we are assigning a NUL to, at most, `patternBuf[MAX_PATH + 1]` so increase the buffer size slightly to make it happy.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3571923
      
      fbshipit-source-id: c027e2b253dc3e56d13e9a15a0e960a6aa3a0e6c
      9c4ce90b
    • Christopher Dykes's avatar
      Add an Atomic portability header · 9d4e8129
      Christopher Dykes authored
      Summary: Because there are situations where we need to do an atomic write to a plain pointer, rather than an atomic value. Unfortunately, there is no support in the standard library for this, so different compilers implement the primitives differently. This specifically implements an `int64_t` overload for `__sync_fetch_and_add` for use in the atomic hash map test.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3571830
      
      fbshipit-source-id: c27d8d2a5238bbc9aba6a9e48e4b3412a199288f
      9d4e8129
  3. 17 Jul, 2016 1 commit
    • Wez Furlong's avatar
      folly: fix initialization for CLOCK_PROCESS_CPUTIME_ID emulation on macOS · 4592f5e8
      Wez Furlong authored
      Summary:
      this fixes TimeTest on macOS.
      
      The problem was that `task_info_count` is an in/out parameter and it wasn't correctly initialized due to a typo.  The lack of initialization meant that the `task_info()` call would fail at runtime.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3576262
      
      fbshipit-source-id: 8388fa3c5020309d64a0fa7e01fd6cea80200219
      4592f5e8
  4. 16 Jul, 2016 4 commits
    • Wez Furlong's avatar
      folly: fix constexpr methods in RandomTest on macos · 92fd1080
      Wez Furlong authored
      Summary:
      the RNG max and min methods must be marked constexpr in order to
      compile.  The macos compiler doesn't know to propagate the constexpr-ness from
      numeric_limits::max on its own, so we have to be explicit (this also matches
      the annotations in ThreadLocalPRNG in Random.h)
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3576189
      
      fbshipit-source-id: e4eeb3361d1c48f582dad5a52e35cae133f007a1
      92fd1080
    • Wez Furlong's avatar
      folly: fixup CompressionTest compilation on macos · 95fb46db
      Wez Furlong authored
      Summary:
      The compiler on macos is pedantic about the size of the 9UL not
      matching the size of the type returned by `oneBasedMsbPos`.  Cast it to
      the appropriate size.
      
      Reviewed By: meyering
      
      Differential Revision: D3576183
      
      fbshipit-source-id: 41e9afc78eed2994e34238da119774e9bf6b7cea
      95fb46db
    • Qinfan Wu's avatar
      Fix FBStringTest build failure and hash computation for wchar · 77cf88a7
      Qinfan Wu authored
      Summary:
      Getting some build errors when doing `buck test folly/...`. This seems to be fixing it.
      
        folly/test/FBStringTest.cpp:1290:23: error: unknown type name 'basic_fbstring'; did you mean 'basic_fstream'?
          using u16fbstring = basic_fbstring<char16_t>;
                              ^~~~~~~~~~~~~~
                              basic_fstream
      
      Also the test `testHashChar16` was failing because only part of the string is used when computing hash.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3575858
      
      fbshipit-source-id: cdd5bdb9653d50beaf0ec82b659d31354b345441
      77cf88a7
    • Tom Jackson's avatar
      get_or_throw(map, key) returns references · 6871c5cc
      Tom Jackson authored
      Differential Revision: D3572671
      
      fbshipit-source-id: a80390921b41e47ed2794d48d943a9e4060c7135
      6871c5cc
  5. 15 Jul, 2016 6 commits
    • Matthieu Martin's avatar
      Fix compilation issue related to Fibers WhenN · b2810210
      Matthieu Martin authored
      Summary: In a separate diff, I made changes that switched include order, and suddently this file failed to compile. This fixes it.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D3574775
      
      fbshipit-source-id: 02422d803708aa8490123d19aab5a16c10fdc36e
      b2810210
    • Eric Niebler's avatar
      Make Synchronized tests work with gtest-1.7 · 6bc33db2
      Eric Niebler authored
      Summary: Gtest-1.7's ASSERT macros don't work with types with explicit conversions to bool, so do the cast for it.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3570782
      
      fbshipit-source-id: 885a1022675e63afca00219c5b9de3791742207f
      6bc33db2
    • Eric Niebler's avatar
      out-line the SharedMutexImpl members that directly reference tls_lastTokenlessSlot · d0a6ecc6
      Eric Niebler authored
      Summary: Recent changes to SharedMutex.h broke mcrouter's open source build. See https://travis-ci.org/facebook/mcrouter/builds/140608809. It looks like we're getting bitten by https://sourceware.org/bugzilla/show_bug.cgi?id=16773. We're hitting it now because the extern template is forcing the instantiation of the thread-local static member to be located in SharedMutex.o, but the inline members that reference that thread-local are *not* located in SharedMutex.o. binutils seems to be stepping on its own feet trying to fix up the references at link time. We can fix it by making sure the code that references the thread-local is colocated with the thread-local.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3498477
      
      fbshipit-source-id: 86ea86812010ff1ef7351e6f8c106bb4291d0234
      d0a6ecc6
    • Christopher Dykes's avatar
      Assume GFlags isn't present if FOLLY_HAVE_LIBGFLAGS isn't defined · f3c02cfc
      Christopher Dykes authored
      Summary: Because, if it follows the same pattern as a normal config flag, it simply won't be defined if it isn't available.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3571862
      
      fbshipit-source-id: 3322ceb0ce349de16b29310b66d1333aa04da516
      f3c02cfc
    • Christopher Dykes's avatar
      Fix the base gen test with GTest 1.7 · 2e521043
      Christopher Dykes authored
      Summary: Becuase it has bugs that cause the compiler to error :(
      
      Reviewed By: ericniebler
      
      Differential Revision: D3571263
      
      fbshipit-source-id: 9a17fc2c3c7344c3532df33cd4b84517c97d8efc
      2e521043
    • Michael Lee's avatar
      Add a check for wchar support · ebcf92c2
      Michael Lee authored
      Summary:
      Not all libc's are the same. Some support wchar_t and some
      don't do a great job...
      
      Reviewed By: Orvid
      
      Differential Revision: D3565016
      
      fbshipit-source-id: 91da4f1332e30bdb20a93d0a26a0445d5eadd1b7
      ebcf92c2
  6. 14 Jul, 2016 6 commits
    • Saurabh Singh's avatar
      Adding std::unique_ptr definition for the ASN1_TIME type. · 81957665
      Saurabh Singh authored
      Summary:
      The ASN1_TIME is the typically used within OpenSSL for representing
      time. For example, it can be used to represent the NotBefore and NotAfter
      properties of a certificate to be verified. This diff introduces a
      ASN1TimeUniquePtr type to take care of the ownership of the ASN1_TIME.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3561274
      
      fbshipit-source-id: ca4d1431b33098cccd727253dd301e209d2561a5
      81957665
    • Vikas Kumar's avatar
      s/PortabilityTimeTest.cpp/TimeTest.cpp · 8ba9a001
      Vikas Kumar authored
      Summary:
      The test file in `../portability/test` is named `TimeTest.cpp`. Makefile refers to it as `PortabilityTimeTest.cpp`. Possibly a typo. Or the test file should be renamed to `PortabilityTimeTest.cpp`.
      Closes https://github.com/facebook/folly/pull/438
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3558452
      
      Pulled By: Orvid
      
      fbshipit-source-id: 0cee874b63e98e671153c507f42a7a3b9d8084c1
      8ba9a001
    • Tavian Barnes's avatar
      fbstring: Fix std::hash specializations for non-char types · 78890b3f
      Tavian Barnes authored
      Summary: Closes https://github.com/facebook/folly/pull/407
      
      Reviewed By: ot
      
      Differential Revision: D3428571
      
      Pulled By: Orvid
      
      fbshipit-source-id: 0b82afae2df24803250e8d6005e2e59bbc8348c9
      78890b3f
    • zhangkehong2brad's avatar
      Enable GroupVarint on Arm64 · 9be1d48f
      zhangkehong2brad authored
      Summary: Closes https://github.com/facebook/folly/pull/430
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3558454
      
      Pulled By: Orvid
      
      fbshipit-source-id: 8a69b4db31b73806b770fbcf15663411140a04f0
      9be1d48f
    • Christopher Dykes's avatar
      Switch away from things that are removed in C++17 · 048c5964
      Christopher Dykes authored
      Summary:
      That currently includes `std::binary_function`, `std::unary_function`, and `std::random_shuffle`.
      `std::{unary|binary}_function<T{, T2}, Ret>` changes to `std::function<Ret(T{, T2})>`.
      `std::random_shuffle` has no immediate equivalent, but `std::shuffle` while passing a specific RNG achieves the same effect.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3506405
      
      fbshipit-source-id: cdefc698a841eca762174eddd8ce636e2d8d26ef
      048c5964
    • Sven Over's avatar
      ManualExecutor: add clear method · a5f4fbe0
      Sven Over authored
      Summary:
      ManualExecutor::clear removes all waiting functions from the
      executor.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3555434
      
      fbshipit-source-id: 604c352f2299b0dada062e5f8287be98e2a5f72c
      a5f4fbe0
  7. 13 Jul, 2016 1 commit
  8. 12 Jul, 2016 7 commits
    • Yedidya Feldblum's avatar
      Fix Build: sorted_vector_types.h on GCC v4.8 · 6215a88d
      Yedidya Feldblum authored
      Summary:
      [Folly] Fix Build: `sorted_vector_types.h` on GCC v4.8.
      
      Problem: that compiler does not yet support `auto`-typed lambda parameters.
      
      Solution: specify the types of the lambda parameters.
      
      Reviewed By: mzlee, Orvid
      
      Differential Revision: D3551262
      
      fbshipit-source-id: 160d3245ec422060175ce59ee653d158954477ed
      6215a88d
    • Christopher Dykes's avatar
      Define TCPI_OPT_SYN_DATA if it isn't defined · 82142aa3
      Christopher Dykes authored
      Summary: Because it doesn't in a lot of our open-source builds.
      
      Differential Revision: D3551445
      
      fbshipit-source-id: 599f45f51d1cbecedd02cb2ca3ef611648986039
      82142aa3
    • Kevin Lewi's avatar
      Adding the ability to check for whether TCP fast open succeeded on a socket · 106a2a56
      Kevin Lewi authored
      Summary: Modifies AsyncSocket to check if TFO succeeded. Also added checks to AsyncSocketTest2 to check if TFO succeeded when it should.
      
      Reviewed By: siyengar
      
      Differential Revision: D3540330
      
      fbshipit-source-id: 8a4b64fdb040dea73ba264b8e3dfff4d717fd96f
      106a2a56
    • Christopher Dykes's avatar
      Improve folly/portability/Time.cpp OS X and Windows compatibility · a4657e89
      Christopher Dykes authored
      Summary:
      Folly currently contains wrappers to emulate
      `clock_gettime()` on platforms which don't support it.
      
      The OS X and Windows wrappers are missing a bit of functionality we
      need. In this diff, I:
      
      1. Bring the OS X and Windows wrappers closer to Linux's functionality
      2. Add unit tests
      
      Reviewed By: bmaurer, mzlee
      
      Differential Revision: D3418054
      
      fbshipit-source-id: 47eba871e844b4c3dccd7ab201ec82e1f6edf729
      a4657e89
    • Adam Simpkins's avatar
      add Synchronized::withLock() methods · b179601d
      Adam Simpkins authored
      Summary:
      Add withLock() and related methods for invoking a lambda function while the
      lock is held.  This is sometimes more convenient than opening a new scope and
      using lock().
      
      withLock() also retains some of the benefits of the SYNCHRONIZED macro in that
      it forces users to put their critical section code in a new scope, making the
      critical section more visibly distinct in the code.  This also encourages users
      to only put necessary work inside the critical section, and do to other work
      once the lock is released.
      
      This also adds a LockedGuardPtr class, which is a slightly cheaper version of
      LockedPtr.  The relationship between LockedGuardPtr and LockedPtr is very much
      like that between std::lock_guard and std::unique_lock.  It saves a branch in
      the destructor, and in the case of std::mutex it also saves a small amount of
      storage space (since LockedPtr is specialized for std::mutex to also store a
      std::unique_lock).
      
      Reviewed By: yfeldblum, djwatson
      
      Differential Revision: D3530368
      
      fbshipit-source-id: 72a4f457b3f18e8e8f4cc6713218f6882bb89818
      b179601d
    • Adam Simpkins's avatar
      improve Synchronized LockedPtr class, and add new lock() APIs · 50f4f92c
      Adam Simpkins authored
      Summary:
      This refactors the Synchronized::LockedPtr class, and adds new
      lock()/wlock()/rlock() APIs to Synchronized.
      
      The LockedPtr changes include:
      
      - Consolidate code so a single template class can be used for both const
        and non-const operation, rather than requiring separate class definitions.
        A LockPolicy template parameter controls if the lock should be acquired in
        exclusive or shared mode, and a SynchronizedType parameter controls whether
        or not the internal data is const or not.
      
      - Specialize LockedPtr for std::mutex, so it uses std::unique_lock<std::mutex>
        internally.  This requires slightly more storage space internally, but it
        allows Synchronized<T, std::mutex> to be used with std::condition_variable.
      
      - Implement operator*() to dereference the pointer and retrieve a reference to
        the locked data.
      
      - Implement operator!() and provide an isValid() method to check the validity
        of the LockedPtr.  These are needed to tell if a timed acquire operation
        succeeded or timed out.
      
      - Drop the LockedPtr copy constructor.  Previously the copy constructor
        acquired the lock a second time.  If anyone needs the ability to hold a
        shared lock a second time solely via a LockedPtr (and not via the original
        Synchronized object), I think we should add back a much more explicit API to
        do this.
      
      Furthermore, this adds lock(), wlock(), and rlock() methods to Synchronized to
      explicitly obtain a LockedPtr.  These APIs behave similar to operator->(), but
      are more explicit, and require the caller to make a concious choice about
      whether or not an exclusive or shared lock should be acquired.  The lock()
      method is present only on Synchronized instantiations using an exclusive mutex,
      and the wlock() and rlock() methods are present only on Synchronized
      instantiations that use a shared mutex.
      
      I plan to deprecate the existing Synchronized::operator->() method and the
      various SYNCHRONIZED macros in upcoming diffs.  For now this adds comments
      directing users to the new methods, but does not start any of the technical
      deprecation changes yet.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3526489
      
      fbshipit-source-id: 8a96a09b68656ff9215dcdfdf32ecd2bfbb1727f
      50f4f92c
    • Yedidya Feldblum's avatar
      Inline the lower_bound and upper_bound callbacks in sorted_vector_map · 594f18f7
      Yedidya Feldblum authored
      Summary:
      [Folly] Inline the `lower_bound` and `upper_bound` callbacks in `sorted_vector_map`.
      
      Avoids unnecessary use of legacy `boost::bind`, and allows the compiler to avoid the indirection it introduces. This way, we use templates instead of vtables.
      
      Reviewed By: Orvid
      
      Differential Revision: D3545939
      
      fbshipit-source-id: 277e9e4862beb71e99b94a62308783771071d2bc
      594f18f7
  9. 09 Jul, 2016 1 commit
    • Yedidya Feldblum's avatar
      Move IPAddress definitions to source files · c8f4d603
      Yedidya Feldblum authored
      Summary:
      [Folly] Move `IPAddress` definitions to source files.
      
      And to internal header files. Keeping headers lightweight can help with build times.
      
      Reviewed By: simpkins
      
      Differential Revision: D3514455
      
      fbshipit-source-id: de78f4ef9e70e7ddd7fb666348ed705c5228531c
      c8f4d603