1. 24 Aug, 2019 1 commit
    • Yedidya Feldblum's avatar
      Avoid __forceinline for catch_exception under MSVC · 2fc030b4
      Yedidya Feldblum authored
      Summary: [Folly] Avoid `__forceinline` for `catch_exception` under MSVC, which warns about functions which contain `try`-and-`catch` blcoks having the `__forceinline` modifier.
      
      Reviewed By: akrieger
      
      Differential Revision: D16982707
      
      fbshipit-source-id: 68c443c4ce8ca77edd49d509a88ef4b0ab9488a9
      2fc030b4
  2. 23 Aug, 2019 4 commits
    • Aaryaman Sagar's avatar
      Fix definition of SynchronizedBase::RLockedPtr · 16b42cc0
      Aaryaman Sagar authored
      Summary:
      The definition of RLockedPtr should use a non-const Subclass type, and not a
      const one.
      
      Reviewed By: ot
      
      Differential Revision: D15356827
      
      fbshipit-source-id: b8ad41e263f0e15ffa25b0698aa85eab8ca2ccb8
      16b42cc0
    • Tristan Rice's avatar
      folly: move SemiFuture::within to be with the other within methods · 7cfb9591
      Tristan Rice authored
      Summary: This moves within to be in a more logical spot. In the parent diff we kept it where it was to make it easier to see the differences.
      
      Reviewed By: LeeHowes
      
      Differential Revision: D16967106
      
      fbshipit-source-id: 9f9cd2ea38a996ac12d3ca8256c1ec050d57dfc0
      7cfb9591
    • Tristan Rice's avatar
      folly: make within be a SemiFuture and fix deadlock bug · 4594bbdf
      Tristan Rice authored
      Summary:
      This fixes a deadlock bug where the after continuation runs inline.
      
      We resolve this by using defer to delay execution until both futures are created thus avoiding any extra synchronization.
      
      Reviewed By: LeeHowes
      
      Differential Revision: D16952748
      
      fbshipit-source-id: a88a40d3135bdabc43bb51f9b5ea072f8e6564a3
      4594bbdf
    • Joe Romano's avatar
      Add docs to insert_or_assign re: inconsistency with std::map interface · 33fb91d9
      Joe Romano authored
      Summary:
      `ConcurrentHashMap::insert_or_assign` does not follow the interface for `std::map::insert_or_assign`.  Making this clear for future users to avoid confusion.
      
      Code:
      ```
      int main(int argc, char** argv) {
        folly::ConcurrentHashMap<int, std::string> map;
        std::cout << "Insertion took place?: " << map.insert_or_assign(1, "hey").second << std::endl;
        std::cout << "Insertion took place?: "
      << map.insert_or_assign(0, "wow").second << std::endl;
        std::cout << "Insertion took place?: "
      << map.insert_or_assign(1, "wow").second << std::endl;
      }
      ```
      
      Output:
      ```
      Insertion took place?: 1
      Insertion took place?: 1
      Insertion took place?: 1
      ```
      
      Also see: https://github.com/facebook/folly/blob/master/folly/concurrency/test/ConcurrentHashMapTest.cpp#L86-L87
      
      Reviewed By: magedm
      
      Differential Revision: D16967939
      
      fbshipit-source-id: ce0d32813371b31a94e14e404665d4fb2e7ffdfe
      33fb91d9
  3. 22 Aug, 2019 6 commits
    • Lewis Baker's avatar
      Add cancellable folly::coro::sleep() · 1a0ddc9c
      Lewis Baker authored
      Summary:
      Adds folly::coro::sleep() function as an alternative to using folly::futures::sleep().
      
      The coro version returns a Task<void> and supports cancellation of the sleep operation when awaited within another Task.
      
      Reviewed By: kirkshoop
      
      Differential Revision: D16816328
      
      fbshipit-source-id: 46bc4ee2475e6bd0bdfd0f7f30f3e0f1ea54d4d5
      1a0ddc9c
    • Lewis Baker's avatar
      Integrate CancellationToken support into Task · 14959740
      Lewis Baker authored
      Summary:
      The `folly::coro::Task` coroutine type now has an associated `CancellationToken` that is implicitly passed down to child operations that it awaits.
      
      This is a first step towards supporting cancellation of persistent async streams.
      
      This adds a new `co_withCancellation()` customisation point that awaitable types can customise to allow them to opt-in to cancellation. Currently only `Task` customises this operation.
      
      Also provided a new `co_current_cancellation_token` object that can be awaited within a `Task` to retrieve the current `CancellationToken`.
      
      Note that I have not yet hooked up the `Future` or `SemiFuture` to integrate with this cancellation mechanism (most `Future`-based code is not cancellation-aware). So a coroutine that is currently suspended awaiting for a `Future` may not currently respond to a cancellation request.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D16610810
      
      fbshipit-source-id: 72a31d7a3ba4c281db54c1942ab41d4ea2f34d21
      14959740
    • Giuseppe Ottaviano's avatar
      Turn MemoryMapping::LockFlags into a struct of bools · fbb2e01e
      Giuseppe Ottaviano authored
      Summary: `LockFlags` is a set of flags that mirrors `mlock2(..., int flags)`, but since this is not a C API we don't need a bitset, we can just use a more idiomatic struct of bools (also used for the other options in the class). Furthermore, having an entry with value 0 (`LOCK_PREFAULT`) does not make sense in a bitset.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D16900127
      
      fbshipit-source-id: 6477854121c0626e0f36cb7a50d50df73323bd4e
      fbb2e01e
    • Wez Furlong's avatar
      watchman: only enable eden support for FB internal builds · da621b8f
      Wez Furlong authored
      Summary:
      This simplifies things for the OSS CI situation in
      the short term, especially since Eden isn't quite buildable
      or usable outside FB at this time.
      
      Reviewed By: chadaustin
      
      Differential Revision: D16953346
      
      fbshipit-source-id: 028150bb3cfc9a8ccbe1197321214b56ad359463
      da621b8f
    • Yedidya Feldblum's avatar
      Drop workaround for clang-3.6 in Range ctor · bebe69e7
      Yedidya Feldblum authored
      Summary: [Folly] Drop workaround for clang-3.6 in `Range` ctor.
      
      Reviewed By: gkmhub, Orvid
      
      Differential Revision: D16945307
      
      fbshipit-source-id: d70d7560375d0c020b19fbac227767605459a834
      bebe69e7
    • Rosen Penev's avatar
      JemallocHugePageAllocator: bzero to memset (#1195) · 24cde640
      Rosen Penev authored
      Summary:
      bzero is deprecated and can be compile time disabled for uClibc-ng
      Pull Request resolved: https://github.com/facebook/folly/pull/1195
      
      Reviewed By: Orvid
      
      Differential Revision: D16451837
      
      Pulled By: yfeldblum
      
      fbshipit-source-id: 929a8e8cd7f8ddb3a904c1b1956a5f8ca115244f
      24cde640
  4. 21 Aug, 2019 7 commits
    • Lewis Baker's avatar
      Remove iterator interface for folly::coro::AsyncGenerator · fbba622d
      Lewis Baker authored
      Summary:
      Simplified the interface for consuming an AsyncGenerator to now just have a single async next() method instead of an iterator-based API.
      
      The iterator-based API was added to integrate with the 'for co_await' syntax present in the Coroutines TS, however this syntax has been removed from C++20 to allow for future exploration of the AsyncRanges design-space.
      
      The `co_await gen.next()` expression produces an optional-like object that lets you query whether the result is a sentinel or contains a value.
      
      Old:
      ```
      Task<void> consume(AsyncGenerator<T> gen) {
        for (auto it = co_await gen.begin();
             it != gen.end();
             co_await ++it) {
          use(*it);
        }
      }
      ```
      
      New:
      ```
      Task<void> consume(AsyncGenerator<T> gen) {
        while (auto item = co_await gen.next()) {
          use(*item);
        }
      }
      ```
      
      Reviewed By: andriigrynenko, kirkshoop
      
      Differential Revision: D16586151
      
      fbshipit-source-id: 4b0bf31ba9291d894a18e9553513eddee0cde33a
      fbba622d
    • Amir Livneh's avatar
      Remove unused TestAsyncUDPSocket · 9cd581b6
      Amir Livneh authored
      Reviewed By: Orvid
      
      Differential Revision: D16640245
      
      fbshipit-source-id: 3a184e4d877ea27a9400de5993b494095f6bd5e5
      9cd581b6
    • Luca Niccolini's avatar
      do not build proxygen and mvfst for Windows (yet) · e9691bca
      Luca Niccolini authored
      Summary:
      does not affect the github build.
      this is for fb CI
      
      Reviewed By: dddmello
      
      Differential Revision: D16935982
      
      fbshipit-source-id: 61656fa600f19438b5aa89486486ed4ee103dea4
      e9691bca
    • Aaryaman Sagar's avatar
      Make folly::Hash work with pointer and pointer-like types · b3410b78
      Aaryaman Sagar authored
      Summary:
      folly::Hash did not work with pointer-like types like std::unique_ptr<T>,
      std::shared_ptr<T> and T*.  Add specializations for those
      
      Reviewed By: yfeldblum
      
      Differential Revision: D16134842
      
      fbshipit-source-id: 78d3cf9c6f5ef4f49b008c0d1c489d3c6203ba89
      b3410b78
    • Michael Lee's avatar
      Move folly/Benchmark.h from test/FBVectorTestUtil.h to test/FBVectorBenchmark · 83a5c644
      Michael Lee authored
      Summary: As far as I can tell, folly/test/FBVectorTestUtil.h does not need to include folly/Benchmark.h. Move it to folly/testFBVectorBenchmark where it is actually used.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D16931137
      
      fbshipit-source-id: 8ef5f99a783537672d55883adadd08270e318a61
      83a5c644
    • Dan Melnic's avatar
      Fix : iterating through ConcurrentHashMapSIMD results in infinite loop · f3930359
      Dan Melnic authored
      Summary: Fix : iterating through ConcurrentHashMapSIMD results in infinite loop
      
      Reviewed By: nbronson
      
      Differential Revision: D16923826
      
      fbshipit-source-id: c8b98ef13034240c162c155cf0e5c3f097b73c7f
      f3930359
    • Elliott Clark's avatar
      Don't overflow/underflow in folly::stats::detail::Bucket · 8973236c
      Elliott Clark authored
      Summary: Underflow/overflow of signed integers is fraught with dangers. So this diff removes the potential for overflow while adding or subtracting buckets in folly stats.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D16898755
      
      fbshipit-source-id: 4d3df1024b4c01ea0b276278105071e62e27fa27
      8973236c
  5. 20 Aug, 2019 4 commits
    • Wez Furlong's avatar
      getdeps: fixup testpilot new test recording · 1dd79077
      Wez Furlong authored
      Summary:
      In the Facebook infrastructure the testpilot runner talks
      to a service to determine whether a given test should be run locally.
      
      The remote service was returning an error for some tests because they
      didn't have enough configuration specified.
      
      This diff associates some configuration with the tests based on the
      host type and makes things happier.
      
      Reviewed By: Ben0mega
      
      Differential Revision: D16894682
      
      fbshipit-source-id: b6f59b112991160ef26cc126e98041d8908a6273
      1dd79077
    • Nathan Bronson's avatar
      add tests for sized deallocation of size zero · 2cf2b4f9
      Nathan Bronson authored
      Summary:
      Sized deallocation via ::operator delete with size == 0 is
      broken in some allocators.  This diff adds a unit test that ensures we
      are either disabling sized deallocator or running with a good allocator.
      
      Reviewed By: interwq
      
      Differential Revision: D10857654
      
      fbshipit-source-id: 981c7bcc1b021d4cd1ea1725ccf510d1958842fd
      2cf2b4f9
    • Ming Zhao's avatar
      Switch dev mode debug level from -g2 to -g1 since dev mode implies build as fast as possible. · 202eace0
      Ming Zhao authored
      Reviewed By: pixelb
      
      Differential Revision: D15301144
      
      fbshipit-source-id: f94a805427b6fc8b20e7c01fcf6e1853fbebf7f1
      202eace0
    • Victor Zverovich's avatar
      Don't fail on EINPROGRESS error in bind · 2e6e2196
      Victor Zverovich authored
      Summary: Make `AsyncServerSocket` not fail on `EINPROGRESS` in `bind` and fix handling of `errno` there.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D16791566
      
      fbshipit-source-id: 1aeaefb6bae47bf41fd2d20238b716b84d0566d1
      2e6e2196
  6. 19 Aug, 2019 6 commits
    • Aaryaman Sagar's avatar
      Fix test build break · ce5afdc6
      Aaryaman Sagar authored
      Summary: T52681488
      
      Reviewed By: Orvid
      
      Differential Revision: D16901429
      
      fbshipit-source-id: 0a5fc218edf6ef29b100365163102dbdc2abf313
      ce5afdc6
    • Yedidya Feldblum's avatar
      Suppress a spurious MSVC warning in folly/Traits.h · 9bcfff7a
      Yedidya Feldblum authored
      Summary:
      [Folly] Suppress a spurious MSVC warning in `folly/Traits.h`.
      
      ```
      folly\traits.h(645): warning C4287: '>': unsigned/negative constant mismatch
      folly\traits.h(646): warning C4287: '<=': unsigned/negative constant mismatch
      folly\traits.h(647): warning C4287: '<': unsigned/negative constant mismatch
      ```
      
      Reviewed By: Orvid
      
      Differential Revision: D16889045
      
      fbshipit-source-id: 31edd58bf046143092a5f006ee0ac5b071b539a0
      9bcfff7a
    • Yedidya Feldblum's avatar
      Fix MSVC conversion warning in Optional test · 05a06785
      Yedidya Feldblum authored
      Summary:
      [Folly] Fix MSVC conversion warning in `Optional` test.
      
      ```
      folly\optional.h(372): warning C4244: 'argument': conversion from 'double' to 'int', possible loss of data
      folly\optional.h(358): note: see reference to function template instantiation 'void folly::Optional<Type>::construct<std::initializer_list<_Ty>&,double>(std::initializer_list<_Ty> &,double &&)' being compiled
                with
                [
                    _Ty=int
                ]
      folly\optional.h(359): note: see reference to function template instantiation 'void folly::Optional<Type>::construct<std::initializer_list<_Ty>&,double>(std::initializer_list<_Ty> &,double &&)' being compiled
                with
                [
                    _Ty=int
                ]
      folly\optional.h(449): note: see reference to function template instantiation 'folly::Optional<Type>::Optional<std::initializer_list<_Ty>&,double>(folly::Optional<Type>::PrivateConstructor,std::initializer_list<_Ty> &,double &&) noexcept' being compiled
                with
                [
                    _Ty=int
                ]
      folly\optional.h(451): note: see reference to function template instantiation 'folly::Optional<Type>::Optional<std::initializer_list<_Ty>&,double>(folly::Optional<Type>::PrivateConstructor,std::initializer_list<_Ty> &,double &&) noexcept' being compiled
                with
                [
                    _Ty=int
                ]
      folly\test\optionaltest.cpp(659): note: see reference to function template instantiation 'folly::Optional<Type> folly::make_optional<Type,int,double>(std::initializer_list<_Ty>,double &&)' being compiled
                with
                [
                    _Ty=int
                ]
      ```
      
      Reviewed By: Orvid
      
      Differential Revision: D16889085
      
      fbshipit-source-id: c59f5e3fa0d4402e1b836841dff66d73b111235f
      05a06785
    • Victor Zverovich's avatar
      Fix building projects that use target_compile_features · 240c1593
      Victor Zverovich authored
      Summary:
      Building a project that uses folly and `target_compile_features` may fail
      because folly requires C++14 and CMake doesn't know about it. So if a project
      has only C++11 features in `target_compile_features` CMake will pick
      `-std=gnu++11` or similar and compilation will fail on an assertion in
      `folly/Portability.h`. To fix this, add `target_compile_features` to the
      `folly` target pushing the minimum required standard to C++14.
      
      Reviewed By: Orvid
      
      Differential Revision: D16884888
      
      fbshipit-source-id: 0e5ac4abde10b1ea757011bcd05b17d508859b4f
      240c1593
    • Adam Simpkins's avatar
      fbcode_builder: CMake functions for building standalone python programs · bca45896
      Adam Simpkins authored
      Summary:
      Add some CMake functions for building standalone executables from Python
      source files.  This generates executables similar to PEX
      (https://github.com/pantsbuild/pex).
      
      In the future this could potentially be leveraged to directly build XAR files
      (https://github.com/facebookincubator/xar).
      
      The main advantages of these functions is that they allow easily defining
      "libraries" of python files, and their dependencies, which can then be used
      and packaged as part of multiple different standalone executables.
      
      Reviewed By: wez
      
      Differential Revision: D16722499
      
      fbshipit-source-id: e1d829b911dc428e5438b5cf9cebf99b3fb6ce24
      bca45896
    • Dan Melnic's avatar
      Avoid SIGSEGV if getIOExecutor() returns null · 7329a2b5
      Dan Melnic authored
      Summary: Avoid SIGSEGV if getIOExecutor() returns null
      
      Reviewed By: yfeldblum
      
      Differential Revision: D16859157
      
      fbshipit-source-id: 00c7a45677c61d84a10486f11b4f792093ac2ff5
      7329a2b5
  7. 18 Aug, 2019 2 commits
    • Orvid King's avatar
      Disable an additional warning on windows · 651dace4
      Orvid King authored
      Summary:
      It's spammy and is just informational.
      
      Created from Diffusion's 'Open in Editor' feature.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D16886741
      
      fbshipit-source-id: 29aecb8a62cac9a60cbc4cabc596fd1ee00cfc04
      651dace4
    • Yedidya Feldblum's avatar
      Cut IsRelocatable of containers · cd5c885f
      Yedidya Feldblum authored
      Summary:
      [Folly] Cut IsRelocatable markings of containers, removing forward declarations of the containers to avoid over-inclusion and to avoid undefined behavior.
      
      > 16.5.4.2.1 [namespace.std]\1
      > Unless otherwise specified, the behavior of a C++ program is undefined if it adds declarations or definitions to namespace std or to a namespace within namespace std.
      
      Closes #1203.
      Closes #1204.
      
      Reviewed By: igorsugak
      
      Differential Revision: D16855473
      
      fbshipit-source-id: 0e6acc4f589707aa79b0001b415bcadfab652d62
      cd5c885f
  8. 17 Aug, 2019 4 commits
    • Yedidya Feldblum's avatar
      Revise atomic_fetch_set, atomic_fetch_reset comments · 210e404b
      Yedidya Feldblum authored
      Summary: [Folly] Revise `atomic_fetch_set`, `atomic_fetch_reset` comments, enforcing structure and switching comment style.
      
      Reviewed By: aary
      
      Differential Revision: D16877442
      
      fbshipit-source-id: 0c4c163f2daa14616f20c4e0cac1002c83ec5fac
      210e404b
    • Lucian Grijincu's avatar
      folly: add support for MLOCK_ONFAULT · d5e069c2
      Lucian Grijincu authored
      Summary:
      http://man7.org/linux/man-pages/man2/mlock.2.html
      
             MLOCK_ONFAULT
                    Lock pages that are currently resident and mark the entire
                    range so that the remaining nonresident pages are locked when
                    they are populated by a page fault.
      
      The kernel still checks a few things for `MLOCK_ONFAULT`: rlimits RLIMIT_MEMLOCK / CAP_IPC_LOCK => EPERM or ENOMEM
      
      `TRY_LOCK` & `MUST_LOCK` are only different in in their handling of EPERM, ENOMEN: whether to fail or ignore the errors, so I added a separate enum.
      
      https://github.com/torvalds/linux/blob/v5.0/mm/mlock.c#L29-L37
      ```
      bool can_do_mlock(void)
      {
      	if (rlimit(RLIMIT_MEMLOCK) != 0)
      		return true;
      	if (capable(CAP_IPC_LOCK))
      		return true;
      	return false;
      }
      EXPORT_SYMBOL(can_do_mlock);
      ```
      
      https://github.com/torvalds/linux/blob/v5.0/mm/mlock.c#L671-L714
      ```
      static __must_check int do_mlock(unsigned long start, size_t len, vm_flags_t flags)
      {
      	unsigned long locked;
      	unsigned long lock_limit;
      	int error = -ENOMEM;
      
      	if (!can_do_mlock())
      		return -EPERM;
      
      	len = PAGE_ALIGN(len + (offset_in_page(start)));
      	start &= PAGE_MASK;
      
      	lock_limit = rlimit(RLIMIT_MEMLOCK);
      	lock_limit >>= PAGE_SHIFT;
      	locked = len >> PAGE_SHIFT;
      
      	if (down_write_killable(&current->mm->mmap_sem))
      		return -EINTR;
      
      	locked += current->mm->locked_vm;
      	if ((locked > lock_limit) && (!capable(CAP_IPC_LOCK))) {
      		/*
      		 * It is possible that the regions requested intersect with
      		 * previously mlocked areas, that part area in "mm->locked_vm"
      		 * should not be counted to new mlock increment count. So check
      		 * and adjust locked count if necessary.
      		 */
      		locked -= count_mm_mlocked_page_nr(current->mm,
      				start, len);
      	}
      
      	/* check against resource limits */
      	if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
      		error = apply_vma_lock_flags(start, len, flags);
      
      	up_write(&current->mm->mmap_sem);
      	if (error)
      		return error;
      
      	error = __mm_populate(start, len, 0);
      	if (error)
      		return __mlock_posix_error_return(error);
      	return 0;
      }
      ```
      
      https://github.com/torvalds/linux/blob/v5.0/mm/mlock.c#L721-L732
      ```
      SYSCALL_DEFINE3(mlock2, unsigned long, start, size_t, len, int, flags)
      {
      	vm_flags_t vm_flags = VM_LOCKED;
      
      	if (flags & ~MLOCK_ONFAULT)
      		return -EINVAL;
      
      	if (flags & MLOCK_ONFAULT)
      		vm_flags |= VM_LOCKONFAULT;
      
      	return do_mlock(start, len, vm_flags);
      }
      
      ```
      
      Reviewed By: yfeldblum
      
      Differential Revision: D16760748
      
      fbshipit-source-id: 54937046f5faaceac2cfb9dd6a0f207ad653fe6b
      d5e069c2
    • Tristan Rice's avatar
      Future.within: cancel timeout callbacks on success · 619679d3
      Tristan Rice authored
      Summary:
      Currently the timekeeper callback set by the within method isn't cleaned up when the future resolves and always waits the full duration. This can cause OOM under high QPS and long timeout situations.
      
      This resolves this by cancelling the callback.
      
      Reviewed By: mpark
      
      Differential Revision: D16835816
      
      fbshipit-source-id: c400afc37dbc66447aaa8fd557a770d717d9ab02
      619679d3
    • Aaryaman Sagar's avatar
      Fix DistributedMutex TSAN failures for rocksdb · 83bddb4d
      Aaryaman Sagar authored
      Summary:
      RocksDB's TSAN version was not able to instrument atomic_fetch_set and
      atomic_fetch_reset; and as a result the DistributedMutex tests were failing
      under TSAN
      
      Also TSAN seems to have some issue when and exception_ptr is placed into an
      aligned_storage_t instance. This verifiably correct program (I think) also fails
      with the same TSAN error P78696506. So
      disable that test
      
      This is the code with the same false-negative
      ```
      namespace {
      class ExceptionWithConstructionTrack : public std::exception {
       public:
        explicit ExceptionWithConstructionTrack(int id)
            : id_{folly::to<std::string>(id)}, constructionTrack_{id} {}
      
        const char* what() const noexcept override {
          return id_.c_str();
        }
      
       private:
        std::string id_;
        TestConstruction constructionTrack_;
      };
      
      template <typename Storage, typename Atomic>
      void transferCurrentException(Storage& storage, Atomic& produced) {
        assert(std::current_exception());
        new (&storage) std::exception_ptr(std::current_exception());
        produced->store(true, std::memory_order_release);
      }
      
      void concurrentExceptionPropagationStress(
          int numThreads,
          std::chrono::milliseconds milliseconds) {
        auto&& stop = std::atomic<bool>{false};
        auto&& exceptions = std::vector<std::aligned_storage<48, 8>::type>{};
        auto&& produced = std::vector<std::unique_ptr<std::atomic<bool>>>{};
        auto&& consumed = std::vector<std::unique_ptr<std::atomic<bool>>>{};
        auto&& consumers = std::vector<std::thread>{};
        for (auto i = 0; i < numThreads; ++i) {
          produced.emplace_back(new std::atomic<bool>{false});
          consumed.emplace_back(new std::atomic<bool>{false});
          exceptions.push_back({});
        }
      
        auto producer = std::thread{[&]() {
          auto counter = std::vector<int>(numThreads, 0);
          for (auto i = 0; true; i = ((i + 1) % numThreads)) {
            try {
              throw ExceptionWithConstructionTrack{counter.at(i)++};
            } catch (...) {
              transferCurrentException(exceptions.at(i), produced.at(i));
            }
      
            while (!consumed.at(i)->load(std::memory_order_acquire)) {
              if (stop.load(std::memory_order_acquire)) {
                return;
              }
            }
      
            consumed.at(i)->store(false, std::memory_order_release);
          }
        }};
      
        for (auto i = 0; i < numThreads; ++i) {
          consumers.emplace_back([&, i]() {
            auto counter = 0;
            while (true) {
              while (!produced.at(i)->load(std::memory_order_acquire)) {
                if (stop.load(std::memory_order_acquire)) {
                  return;
                }
              }
              produced.at(i)->store(false, std::memory_order_release);
      
              try {
                auto storage = &exceptions.at(i);
                auto exc = folly::launder(
                  reinterpret_cast<std::exception_ptr*>(storage));
                auto copy = std::move(*exc);
                exc->std::exception_ptr::~exception_ptr();
                std::rethrow_exception(std::move(copy));
              } catch (std::exception& exc) {
                auto value = std::stoi(exc.what());
                EXPECT_EQ(value, counter++);
              }
      
              consumed.at(i)->store(true, std::memory_order_release);
            }
          });
        }
      
        std::this_thread::sleep_for(milliseconds);
        stop.store(true);
        producer.join();
        for (auto& thread : consumers) {
          thread.join();
        }
      }
      } // namespace
      ```
      
      Reviewed By: yfeldblum
      
      Differential Revision: D16739396
      
      fbshipit-source-id: 0eba191ffc07d2e64a3ea550c5fe9a7d01ce2f18
      83bddb4d
  9. 16 Aug, 2019 6 commits
    • Aaryaman Sagar's avatar
      Define sanitize macros if they weren't already defined · d5c4abb3
      Aaryaman Sagar authored
      Summary: As title
      
      Reviewed By: yfeldblum
      
      Differential Revision: D16821444
      
      fbshipit-source-id: 14f0655caf0f53ef47fa65b9b6ba57f0f190df12
      d5c4abb3
    • Yedidya Feldblum's avatar
      #define FOLLY_ERASE FOLLY_ALWAYS_INLINE FOLLY_ATTR_VISIBILITY_HIDDEN · e7a9b358
      Yedidya Feldblum authored
      Summary: [Folly] `#define FOLLY_ERASE FOLLY_ALWAYS_INLINE FOLLY_ATTR_VISIBILITY_HIDDEN`.
      
      Reviewed By: vitaut
      
      Differential Revision: D16686469
      
      fbshipit-source-id: cedaee61955a40ae28ad2b0da565fc9fb385bc6e
      e7a9b358
    • Adam Simpkins's avatar
      getdeps: distinguish build vs install steps in run_cmake.py · 9876b788
      Adam Simpkins authored
      Summary:
      Update the generated `run_cmake.py` script to allow the caller to specify that
      they just want to run a build without the install step.
      
      Reviewed By: wez
      
      Differential Revision: D16778007
      
      fbshipit-source-id: 1859aca2b80fa7b099b4790682a6508e0185f2a0
      9876b788
    • Adam Simpkins's avatar
      getdeps: honor INSTALL_DIR correctly in the generated run_cmake.py script · 1bfbd0d8
      Adam Simpkins authored
      Summary:
      This cleans up how the `CMAKE_ENV` and `CMAKE_DEFINE_ARGS` variables are
      written in the generated `run_cmake.py` script that we emit for CMake-based
      projects.
      
      We now emit each entry in these variables on separate lines, just to improve
      readability.  (Both of these variables tend to have a number of entries and
      are very long if emitted on a single line.)
      
      This also replaces the `-DCMAKE_INSTALL_PREFIX` entry in `CMAKE_DEFINE_ARGS`
      to have it correctly honor the `INSTALL_DIR` variable defined in
      `run_cmake.py`.  This makes `run_cmake.py` still do the right thing if someone
      manually edits it to change the `INSTALL_DIR` value.
      
      Reviewed By: wez
      
      Differential Revision: D16778006
      
      fbshipit-source-id: fee5d25748b87b5d9c57ee2edf8de5e586e872ee
      1bfbd0d8
    • Adam Simpkins's avatar
      getdeps: allow overriding project source, build, and install directories · 8479be08
      Adam Simpkins authored
      Summary:
      Add arguments to getdeps.py to allow overriding the source, build, and install
      directories a per-project basis.  The arguments take the form `[PROJECT:]PATH`
      If the `PROJECT` portion is omitted, it defaults to the current project being
      built.
      
      In particular this makes it possible to specify `--src-dir .` to tell
      getdeps.py to find the project sources from the current directory rather than
      downloading them.
      
      Reviewed By: wez
      
      Differential Revision: D16778011
      
      fbshipit-source-id: f33b87213ace04abb66334f588babdf59df91964
      8479be08
    • Adam Simpkins's avatar
      getdeps: fix a crash if the project_hashes directory does not exist · 4ce59c1d
      Adam Simpkins authored
      Summary:
      This makes getdeps.py no longer crash if used in the folly repository.
      Folly does not depend on any other Facebook projects, so it does not
      include a `build/deps` directory.
      
      Reviewed By: wez
      
      Differential Revision: D16778009
      
      fbshipit-source-id: 41be53d862f41b62154b081eb90ddba8742658fe
      4ce59c1d