1. 07 Sep, 2016 1 commit
    • Maged Michael's avatar
      Expand DSched interface for managing auxiliary functions · f6b5f78b
      Maged Michael authored
      Summary:
      Changed DSched interface for managing auxiliary functions to allow separate auxiliary functions for single actions (applicable to the next shared access by a specific thread) and repeating actions (applicable to all subsequent shared accesses).
      
      [Note: I have a dependent diff that depends on both this diff and the diff for dynamic MPMCQueue (/D3462592). I don't think I can submit a diff that depends on multiple diffs that haven't landed yet. So, I'll wait until this one lands.]
      
      Reviewed By: djwatson
      
      Differential Revision: D3792669
      
      fbshipit-source-id: 52654fffda2dc905b19ff91f4459f15da11f7735
      f6b5f78b
  2. 06 Sep, 2016 3 commits
    • Christopher Dykes's avatar
      Rework the de-allocation guard on the munmap implementation · 18914ab5
      Christopher Dykes authored
      Summary:
      The previous version assumed that `RegionSize` would always be the full size of the allocation done by `VirtualAlloc`. However, `RegionSize` actually only includes the following pages that have the same attributes, so, if you change the access permissions via `mprotect`, the `RegionSize` would exclude that region, which is not what was intended.
      This instead stores the length and a dummy magic value after the end of the requested allocation.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3812949
      
      fbshipit-source-id: 53bbbcc371accbed08adaffa82fc082ec44f316f
      18914ab5
    • Chip Turner's avatar
      Eliminate a string allocation in folly::SocketAddr and bug in char[] conversion · e64edf80
      Chip Turner authored
      Summary:
      We were doing an unnecessary and wasteful string conversion in the
      SocketAddr codepath.  This eliminates it.  I also noticed we had an off-by-one
      in the "convert string to char buffer" code path, so I added a test to confirm
      the bug and fixed it.
      
      Reviewed By: yfeldblum, meyering
      
      Differential Revision: D3817959
      
      fbshipit-source-id: 51fed8331ab23c0888a3d1f9e0cc9cea5ea8329b
      e64edf80
    • Christopher Dykes's avatar
      Implement more of the sockets API · bf77be6e
      Christopher Dykes authored
      Summary:
      This gets the socket portability layer functional enough that most of the socket tests are passing, the few that are left are depending on specific error messages.
      This also switches all of the additional overloads for some of the socket functions to forward to a single implementation, to make adjustments to these functions easier in the future. (most of the functions already needed adjustments and would have had to change regardless)
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3814011
      
      fbshipit-source-id: c6793ee74a91d9e164775a2d52c96f54b28b9f24
      bf77be6e
  3. 02 Sep, 2016 1 commit
    • Philip Pronin's avatar
      delete const rvalue reference ctor of folly::Function · 1813ca3f
      Philip Pronin authored
      Summary:
      This code compiles and is causing stack overflow at runtime:
      
      ```
      using F = folly::Function<void()>;
      void foo(F);
      
      F bar;
      auto baz = [bar = std::move(bar)] {
        foo(std::move(bar));
      };
      baz();
      ```
      
      The bug there is that `baz` is missing `mutable` keyword, so when
      constructing argument for `foo`, `F(const F&&)` is called, which is selecting
      `template <typename Fun> F(Fun&&)` (where `Fun = F const`) and we end up in
      an infinite `F<Fun>(Fun&&) <-> F<Fun>(Fun&&, SmallTag|HeapTag)` cycle.
      
      This diff transforms this easy-to-make-bug into compile-time error.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3810269
      
      fbshipit-source-id: f80a18ab02bd0715d692cf67c3c8943f557c2982
      1813ca3f
  4. 01 Sep, 2016 3 commits
  5. 31 Aug, 2016 8 commits
    • Andrii Grynenko's avatar
      Properly report observable returning nullptr · 2f987219
      Andrii Grynenko authored
      Summary: Make sure exception is propagated to caller (especially when Observer is just created).
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3798991
      
      fbshipit-source-id: cee8452cfd40dcfbaf0e2ae2c2ee628af0362c6e
      2f987219
    • Colin Ni's avatar
      Update FBVector.md · bd2c1914
      Colin Ni authored
      Summary:
      Minor changes. Simplified the memory-handling explanation; also fixed some grammar issues and re-worded some confusing paragraphs. (I suggest reading the edited and unedited versions separately.)
      Closes https://github.com/facebook/folly/pull/459
      
      Reviewed By: simpkins
      
      Differential Revision: D3779296
      
      Pulled By: Orvid
      
      fbshipit-source-id: 24b086cbd0b67e4c592731aeec6a7ffc14ff0319
      bd2c1914
    • Adam Simpkins's avatar
      update TimeseriesHistogram::rate to return a template type · bd8228d9
      Adam Simpkins authored
      Summary:
      Update TimeseriesHistogram::rate(int level) to have a configurable return type,
      similar to the rate(TimeType start, TimeType end) function, as well as the
      avg() functions.  I believe it was simply an oversight initially that this
      version of rate did not have a configurable return type.
      
      Since rate() and avg() are template methods, their full definitions should
      really be available in TimeseriesHistogram.h rather than
      TimeseriesHistogram-defs.h.  This also fixes that problem.  Most of the logic
      in these functions isn't actually dependent on the return type, so that was
      split out into separate non-template helper functions that are still in
      TimeseriesHistogram-defs.h
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3776017
      
      fbshipit-source-id: 7deebf5b9ea1be143b5d772a15246706cb0cae80
      bd8228d9
    • Zonr Chang's avatar
      Consolidate namespace for using GFlags. · 9d7ab809
      Zonr Chang authored
      Summary:
      Default namespace for GFlags has been changed from "google" to "gflags".
      
      See: https://github.com/gflags/gflags/commit/d9d06b9.
      Closes https://github.com/facebook/folly/pull/466
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3787144
      
      Pulled By: Orvid
      
      fbshipit-source-id: db7bcaf4e2bcd46b022a48b17b50ef155570f296
      9d7ab809
    • Philip Pronin's avatar
      Reverted commit D3755446 · f8908e51
      Philip Pronin authored
      Summary:
      Move ThreadLocal object destruction to occur under the lock to avoid races.
      This causes a few cascading changes - the Tag lock needs to be a recursive_mutex so
      constructing a new object while destroying another st. Also, forking requires
      a new mutex to avoid deadlocking on accessing a recursive_mutex across a fork()
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D3755446
      
      fbshipit-source-id: f1f1f92175eb39e77aaa2add6915e5c9bb68d0fb
      f8908e51
    • Naizhi Li's avatar
      Fix folly::SocketAddress::reset · 8c3d0bc9
      Naizhi Li authored
      Summary:
      Currently reset does not actually reset it. This change
      make sure it does the job.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3788869
      
      fbshipit-source-id: 771a641e31bb3cf307e5bebb979b81a3d3feea55
      8c3d0bc9
    • Gabriel Grise's avatar
      Expose SSL key materials to debug SSL · 4458ae04
      Gabriel Grise authored
      Summary: Adding two methods to export the parameters used to generate the key material   (key_block). These parameter can be used to decrypt a TLS session from a packet capture.
      
      Reviewed By: anirudhvr
      
      Differential Revision: D3687099
      
      fbshipit-source-id: 04137f34dd32c387a1b7aec04b3ed6066f123a8e
      4458ae04
    • Michael Lee's avatar
      Use a normal variable if thread local is not available. · e081efca
      Michael Lee authored
      Summary: This should not affect correctness, but it means SharedMutex would need to share the variable across threads.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3621227
      
      fbshipit-source-id: dc1baa7c47cd2d459cd0ef89451bcd7fd4d553aa
      e081efca
  6. 30 Aug, 2016 5 commits
  7. 29 Aug, 2016 7 commits
    • Dan Schatzberg's avatar
      Fix ThreadCachedInt race condition · bae33d68
      Dan Schatzberg authored
      Summary:
      Move ThreadLocal object destruction to occur under the lock to avoid races.
      This causes a few cascading changes - the Tag lock needs to be a recursive_mutex so
      constructing a new object while destroying another st. Also, forking requires
      a new mutex to avoid deadlocking on accessing a recursive_mutex across a fork()
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D3755446
      
      fbshipit-source-id: bb4c4f29bab98d763490df29b460066f124303e0
      bae33d68
    • Andrii Grynenko's avatar
      Resolve fibers-futures dependency · c93226d1
      Andrii Grynenko authored
      Reviewed By: mzlee
      
      Differential Revision: D3780312
      
      fbshipit-source-id: c42c8f0a06b82520ee1b46f105a2a85ad524c442
      c93226d1
    • Yedidya Feldblum's avatar
      gen::dereference should perfectly-forward unwrapped values · 2dedc14b
      Yedidya Feldblum authored
      Summary:
      [Folly] `gen::dereference` should perfectly-forward unwrapped values.
      
      The problem comes in when the wrapped value is not actually a pointer, but is actually an rvalue-ref to some other kind of wrapper type with `Inner&& operator*() &&`. In such cases, the compiler emits a type mismatch error that it cannot cast `Inner` to `Inner&&`, with the errors originating in `Dereference::foreach` and `Dereference::apply`.
      
      Fixes a couple other missing-forwarding and extra-forwarding bugs.
      
      Reviewed By: ddrcoder
      
      Differential Revision: D3776617
      
      fbshipit-source-id: 6926fc18244a572846b22d428bd407d37fb20aa1
      2dedc14b
    • Yedidya Feldblum's avatar
      Use Synchronized in RequestContext · 214d5f7c
      Yedidya Feldblum authored
      Summary:
      [Folly] Use `Synchronized` in `RequestContext`.
      
      Because we can. And it makes the code a tad simpler and also enforces access correctness a tad.
      
      Also use `folly::make_unique` in `RequestContextTest` to keep balance between the explicit `new` and `delete` ops.
      
      Reviewed By: markisaa
      
      Differential Revision: D3781115
      
      fbshipit-source-id: 63b41ddd8009e9546e3be5f89bdd23a4d791105c
      214d5f7c
    • Nick Terrell's avatar
      Add default constructor to folly::IOBuf::Iterator. · b90a2ba5
      Nick Terrell authored
      Summary:
      Iterators must be default constructible.
      folly::IOBuf can now be used as a range in ranges-v3.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3782536
      
      fbshipit-source-id: 854813b4e3336aba50048649e6ae7b375d49e382
      b90a2ba5
    • Jon Maltiel Swenson's avatar
      Fix up TokenBucket.h in Makefile headers · 7259fd8c
      Jon Maltiel Swenson authored
      Summary: Title.
      
      Reviewed By: andreazevedo
      
      Differential Revision: D3785212
      
      fbshipit-source-id: c551e0367196cbc68cf39a5d40f2b324883fcdf4
      7259fd8c
    • Philipp Unterbrunner's avatar
      Generalized and polished folly::TokenBucket · 07802d90
      Philipp Unterbrunner authored
      Summary: Added support for user-defined clock classes, improved comments, and removed part of the std::atomics use that had no effect on thread-safety.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3708378
      
      fbshipit-source-id: 1a933c3707c12311584a3b33afd773ee91577167
      07802d90
  8. 26 Aug, 2016 6 commits
    • Lee Howes's avatar
      Added fiber-compatible semaphore. · dcf0273a
      Lee Howes authored
      Summary: Adds a standard semaphore type with signal and wait methods that is safe to use in both multi-threaded contexts and from fibers.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D3778943
      
      fbshipit-source-id: 6997f1fb870739e07f982399dbebfd8b3e45daa2
      dcf0273a
    • Christopher Dykes's avatar
      Use folly::Random and ensure M_PI is defined · 0decb439
      Christopher Dykes authored
      Summary: Because MSVC doesn't have `random()` and `M_PI` is guarded by a pre-processor macro.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3767159
      
      fbshipit-source-id: fcb1c41cd75925455c76efad38423cd52bd98aeb
      0decb439
    • Yunqiao Zhang's avatar
      collectOne · da9e05e8
      Yunqiao Zhang authored
      Summary:
      The resultant future of collectOne will be fulfilled when the first one of
      the future in the list completes without exception. If all input futures throws
      exception, the resultant future will get the last exception that was thrown.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D3764760
      
      fbshipit-source-id: 76484254e35182eddc8266865853d65c28170f82
      da9e05e8
    • David Goldblatt's avatar
      Add CachelinePadded<T> to folly. · e0ac799a
      David Goldblatt authored
      Summary:
      This class allows easy insertion of padding bytes after an object to ensure
      that two cacheline-padded elements of an array don't engage in false sharing.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3485144
      
      fbshipit-source-id: a3ece1e34566b20f94ff9f66532b2386ab19a9b1
      e0ac799a
    • Nicholas Ormrod's avatar
      Remove now-useless FOLLY_MALLOC_H_ · a4430933
      Nicholas Ormrod authored
      Summary:
      Malloc.h is intentionally included multiple times, once from folly and once from libstdc++. The current ###pragma once## implicitly allows this to happen. FBString.h has an undef for Malloc.h's include guard, which originally accomplished this goal.
      
      The undefing code is presently moot, since its functionality has been replaced by ###pragma once##. Remove it.
      
      I noticed this when ott was copying FBString over to libstdc++ in D3757853.
      The diff that switched the include guards to pragmas was a codemod, and was not specific to fbstring. D3054492
      
      Reviewed By: ot
      
      Differential Revision: D3758119
      
      fbshipit-source-id: e796d039a031d5f842ed39bf55a6b1aeb2686bc4
      a4430933
    • Christopher Dykes's avatar
      Use intrusive base hook rather than a member hook · 1bc610c2
      Christopher Dykes authored
      Summary: Because MSVC is not happy about the member hook when used in complex inheritence scenarios.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3774513
      
      fbshipit-source-id: 9e1ef8dd76d966de339f8486ff1a1d0ab1571849
      1bc610c2
  9. 25 Aug, 2016 6 commits
    • Christopher Dykes's avatar
      Suppress an abort in FileUtilTest under MSVC · 243fbe8d
      Christopher Dykes authored
      Summary: Because MSVC is right, this shouldn't be happening, but we test weird things.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3773486
      
      fbshipit-source-id: 50f28bf0ac8ff53f63231b4f6f9ce050b509b464
      243fbe8d
    • Christopher Dykes's avatar
      lseek returns the new offset, not 0 · ff5c9335
      Christopher Dykes authored
      Summary:
      With how this was written it would fail if the call to `lseek` failed, or if it succeeded, unless it was setting the length to 0, in which case it would succeed.
      This makes it work right.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3773311
      
      fbshipit-source-id: 3dc94502d0c4259f6f2766b4c0903c081d7c36ab
      ff5c9335
    • Christopher Dykes's avatar
      Allow locking nullptr if the length is 0 · 19c6708b
      Christopher Dykes authored
      Summary:
      Because apparently this is valid (and we test it).
      This also adds a check in mmap to make sure we aren't passing an invalid handle to `MapViewOfFileEx`.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3772853
      
      fbshipit-source-id: 11593997a3fb12b7b391c5e52661060b71341aef
      19c6708b
    • Andrii Grynenko's avatar
      Fix SimplerObservable build with -Werror=unused-local-typedefs · 6a7f9395
      Andrii Grynenko authored
      Reviewed By: yfeldblum
      
      Differential Revision: D3765642
      
      fbshipit-source-id: 9b1cc4007c553da5082799fa4ed0af8f7850ec8d
      6a7f9395
    • Christopher Dykes's avatar
      Don't pass the single quote format parameter when formatting things · e4e0bbe1
      Christopher Dykes authored
      Summary:
      We are formatting an integer value, so it is doing absolutely nothing at all, as confirmed by the version I implemented for MSVC, which does output the value with digit separators, which fails the unit tests because the unit test expects the digit separators to not be present. What's more, whe specifically assert that the user has not requested digit separators in the format string.
      This also kills the MSVC special case entirely because it's not needed.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3768405
      
      fbshipit-source-id: 388cd0ca9699e257c71798b9bf355aa651748e60
      e4e0bbe1
    • Felix Handte's avatar
      Easy: Mark folly::static_function_deleter::operator() const · ff92b6ea
      Felix Handte authored
      Summary:
      First, folly::static_function_deleter::operator() is in fact a const
      operation, so this should be a reasonable change. The motivation for this is
      to make folly::ThreadLocalPtr and folly::static_function_deleter play nice with
      each other.
      
      Minimal example:
      ```lang=c++
      
      void deleter(int* ptr) {
        free(ptr);
      }
      
      int main(int argc, char* argv[]) {
        folly::ThreadLocalPtr<int> tl;
        tl.reset(std::unique_ptr<int, folly::static_function_deleter<int, deleter>>(
            new int(0)));
        return 0;
      }
      ```
      
      Currently produces:
      ```
      folly/ThreadLocal.h:207:7: error: no matching function for call to object of type 'const folly::static_function_deleter<int, &deleter>'
            delegate(ptr);
            ^~~~~~~~
      Test.cpp:10:6: note: in instantiation of function template specialization 'folly::ThreadLocalPtr<int, void>::reset<int, folly::static_function_deleter<int, &deleter>, void>' requested here
        tl.reset(std::unique_ptr<int, folly::static_function_deleter<int, deleter>>(new int(0)));
           ^
      folly/Memory.h:91:8: note: candidate function not viable: 'this' argument has type 'const folly::static_function_deleter<int, &deleter>', but method is not marked const
        void operator()(T* t) { f(t); }
             ^
      1 error generated.
      ```
      
      With the fix, the build succeeds.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3764624
      
      fbshipit-source-id: c28c791b79f1415704c205c36bfda2d888d6c010
      ff92b6ea