1. 25 Jun, 2017 2 commits
  2. 24 Jun, 2017 1 commit
    • Michael Lee's avatar
      Fix up and namespace clock_gettime and clock_getres for MacOS · 8a7112c6
      Michael Lee authored
      Summary:
      Resolve two issues with folly's clock_gettime() shim on Apple platforms (iOS, macOS, etc.):
      
      When detecting whether folly should define clock_gettime() on Apple platforms, don't assume clock_gettime() is declared in Apple's headers just because MAC_OS_X_VERSION_10_12/__IPHONE_10_0 is defined. Someone might use a newer macOS or iOS SDK (which defines MAC_OS_X_VERSION_10_12/__IPHONE_10_0), but not have clock_gettime() (because _DARWIN_FEATURE_CLOCK_GETTIME isn't set).
      
      When defining a shim for clock_gettime(), don't rely on Apple's clock_gettime() declaration. Instead, shadow Apple's declaration with our own. This prevents folly from inheriting Apple's availability and visibility attributes for clock_gettime().
      
      Reviewed By: yfeldblum
      
      Differential Revision: D5312574
      
      fbshipit-source-id: f16634ce92ee6c299613d3db22f0537bd31ac14d
      8a7112c6
  3. 23 Jun, 2017 11 commits
    • Kyle Nekritz's avatar
      Move address caching logic from AsyncSSLSocket to AsyncSocket. · 4c7a736d
      Kyle Nekritz authored
      Summary: So that it is available on other transports.
      
      Reviewed By: Orvid
      
      Differential Revision: D5302039
      
      fbshipit-source-id: cbfdadd158061ed9a2b3ed3e0960ce66f0d545fd
      4c7a736d
    • Ilya Maykov's avatar
      fix UBSAN failure in atomic_shared_ptr_test · d71b7361
      Ilya Maykov authored
      Summary: Fix UBSAN failure in atomic_shared_ptr_test by using reinterpret_cast instead of static_cast.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D5314116
      
      fbshipit-source-id: 8479c9c4bdeeb155067a3de75efe4e97c36519e5
      d71b7361
    • Giuseppe Ottaviano's avatar
      MoveOnly utility · efcacd1c
      Giuseppe Ottaviano authored
      Summary: Same as `boost::noncopyable` but it does not disable move constructor/assignment.
      
      Reviewed By: luciang
      
      Differential Revision: D5311043
      
      fbshipit-source-id: 44fe95712169b95a00e474385be43fa857cfd8ec
      efcacd1c
    • Christopher Dykes's avatar
      Fix AsyncFileWriterTest due to long being 32-bit on Windows · a1a70d94
      Christopher Dykes authored
      Summary: `long` is only 32-bits on Windows, which means this call to `std::min` was ambiguous, which caused a compile error.
      
      Reviewed By: simpkins
      
      Differential Revision: D5305964
      
      fbshipit-source-id: 7e4152006e163a0301652be46318f0fc937e5ead
      a1a70d94
    • Andrew Krieger's avatar
      Fix exception_wrapper on Windows by abusing internals · e7e6d29a
      Andrew Krieger authored
      Summary:
      exception_wrapper's non-allocating variant was depending
      on the exception reference being a reference to a heap object,
      which is not the case on Windows. All thrown exceptions are
      copied to the stack first.
      
      So, we abuse internals of exception_ptr to get the internally
      heap allocated copy of the object. What could possibly go wrong.
      
      Reviewed By: yfeldblum, ericniebler, Orvid
      
      Differential Revision: D5270634
      
      fbshipit-source-id: 2983a6af9a2c3cb66cbee8a382707a76b582c489
      e7e6d29a
    • Ilya Maykov's avatar
      move input shared_ptr in atomic_shared_ptr constructor · a325a1c8
      Ilya Maykov authored
      Summary: By moving the input shared_ptr instead of copying it, we avoid doing an unnecessary ref count increment + decrement.
      
      Reviewed By: djwatson, yfeldblum
      
      Differential Revision: D5298467
      
      fbshipit-source-id: b9f0b6999278609417bb4dc062030ca2388ba20a
      a325a1c8
    • Christopher Dykes's avatar
      Fix GlogFormatterTest on Windows · 297d72d1
      Christopher Dykes authored
      Summary:
      It was missing a portability header needed for `setenv`, and was assuming that the `system_clock` was represented as nanoseconds.
      On Windows `std::chrono::system_clock` is represented as 100s of nanoseconds, ie. `FILETIME`.
      
      Reviewed By: simpkins
      
      Differential Revision: D5308182
      
      fbshipit-source-id: facb922ebe1587723358b38499dadac683e3517b
      297d72d1
    • Christopher Dykes's avatar
      Stop MSVC from complaining about digraphs not being supported · 59e47de8
      Christopher Dykes authored
      Summary: MSVC complains about `<:` being a digraph and that it isn't interpreting it as one (C4628). Make it be quiet by making it not look like a digraph.
      
      Reviewed By: simpkins
      
      Differential Revision: D5305162
      
      fbshipit-source-id: 7385164e8f73226ce18bc04c32894c2f27f8ae25
      59e47de8
    • Christopher Dykes's avatar
      Switch the logging tests from .native() to .string() · d4e51b57
      Christopher Dykes authored
      Summary: These were using `boost::filesystem::path.native()` in contexts where an `std::string` was the expected output. `boost::filesystem::path.native()` returns a `std::wstring` on Windows, so use `.string()` instead.
      
      Reviewed By: simpkins
      
      Differential Revision: D5305649
      
      fbshipit-source-id: 3c7cd53d2f33d2dbb222731655cdab69d1c4a187
      d4e51b57
    • Christopher Dykes's avatar
      Fix ThreadName.cpp on Windows · 7af82bb2
      Christopher Dykes authored
      Summary: I failed to realize that this helper function also needs to be guarded on `!_WIN32`, because the assertions are false on Windows.
      
      Reviewed By: ot, luciang
      
      Differential Revision: D5304914
      
      fbshipit-source-id: f2564cb2fcbfdc73a2529d4a41df2995748bc3f6
      7af82bb2
    • Christopher Dykes's avatar
      Enable more auto-deps in Folly · 7f4b7fc6
      Christopher Dykes authored
      Summary: This enables auto-deps support in more places in Folly. It also fixes a couple of auto-deps declarations that were missing an `s`.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D5289542
      
      fbshipit-source-id: 7d34b29bcc172fb31f91f1ba880864e2d5869ffd
      7f4b7fc6
  4. 22 Jun, 2017 6 commits
    • Adam Simpkins's avatar
      allow passing function pointers to Future::onError() · 49f2f8b1
      Adam Simpkins authored
      Summary:
      Add appropriate specializations for detail::Extract() so that you can pass a
      plain function pointer to `onError()`.  Previously the code only worked with
      member function pointers and functor-style objects.
      
      Reviewed By: yfeldblum, wez
      
      Differential Revision: D5286773
      
      fbshipit-source-id: 67b44d1d7573eb1da501475045fd24ad4ab1c074
      49f2f8b1
    • Adam Simpkins's avatar
      logging: fix issues detecting XLOG(FATAL) statements as noreturn · 61a0ef55
      Adam Simpkins authored
      Summary:
      Update the FB_LOG() and XLOG() macros so that FATAL log messages are correctly
      detected as not returning, by both clang and gcc.
      
      We have to ensure that both sides of the log statement check (log message
      enabled or disabled) evaluate to `[[noreturn]]` expressions.  I did try
      updating the log check itself so that it could be constexpr detected as always
      passing, but this was not sufficient.
      
      Reviewed By: wez
      
      Differential Revision: D5290780
      
      fbshipit-source-id: 773a56a8392dfd7c310d5d84fc9311e66edf99cb
      61a0ef55
    • Aaron Balsara's avatar
      AsyncSSLSocket connect without SSL · 38ba47c3
      Aaron Balsara authored
      Summary:
      Currently when calling connect with AsyncSSLSocket in unencrypted
      mode it still attempts to perform a SSL handshake. Add check to not
      do SSL. Calling sslConnect will always run the SSL handshake
      
      Reviewed By: jrahman
      
      Differential Revision: D5153456
      
      fbshipit-source-id: 4d9164115be72c8ee76e383535561e3083a327e3
      38ba47c3
    • Adam Simpkins's avatar
      logging: improve the AsyncFileWriter flush test() · 00ff5917
      Adam Simpkins authored
      Summary:
      This test has run into occasional failures on continuous build test runs.
      Unfortunately when something goes wrong it crashes in the std::thread
      destructor due to this thread still being joinable when it is destroyed, which
      hides information about what actually failed in the test.
      
      This updates the test to immediately detach the thread, so that on error we
      will be able see the real failure reason.
      
      This also increases the size of the message that we write, which will hopefully
      help ensure that this write always blocks.
      
      Reviewed By: wez
      
      Differential Revision: D5295574
      
      fbshipit-source-id: ea8cfa855613398f88f9f982c600ec661018a31c
      00ff5917
    • Adam Simpkins's avatar
      logging: fully convert the ERROR level to ERR · 53f2f752
      Adam Simpkins authored
      Summary:
      Switch all code in the logging library from using `ERROR` to `ERR`,
      and remove the `ERROR` LogLevel entirely, even if it is not already
      defined as a macro.
      
      Previously the code kept `ERROR` available as a LogLevel name if it had
      not already been defined as a macro (which is done by common Windows header
      files).  However, this made for inconsistent behavior, and made it easy to
      write code that would not be portable to Windows.
      
      This diff fully drops the `ERROR` name for consistency across platforms.
      
      Reviewed By: wez
      
      Differential Revision: D5288600
      
      fbshipit-source-id: 8d2d52e955959c278345fc9c2086c7cacf9660f9
      53f2f752
    • Adam Simpkins's avatar
      logging: add more tests for fatal log messages · cffc8a77
      Adam Simpkins authored
      Summary:
      Add some tests for fatal log messages during static initialization and
      destruction.  Ideally most programs won't actually do much real work before or
      after main, but make sure the logging framework behaves sanely in these
      situations.
      
      This also fixes a bug in the `test_none()` test, which previously caused it to
      always succeed without testing the desired behavior.
      
      Reviewed By: wez
      
      Differential Revision: D5281718
      
      fbshipit-source-id: ca838c098886e99418264acf9a4d651ea9e7502c
      cffc8a77
  5. 21 Jun, 2017 13 commits
    • Maged Michael's avatar
      Add support for move operations on hazptr-holder. Other optimizations. · 703049c3
      Maged Michael authored
      Summary:
      - Support empty hazptr_holder, move constructor and assignment operator
      - Limit thread caching to the default domain to improve performance of thread caching
      - Fix unnecessary calls to stats singleton
      - Use the mprotect version of AsymmetricMemoryBarrier for reducing the overhead of bulkReclaim().
      - Update read-side benchmark results
      
      Reviewed By: djwatson
      
      Differential Revision: D5292885
      
      fbshipit-source-id: bc5713ac95492a7114e1e467e71d2278e64b165d
      703049c3
    • Adam Simpkins's avatar
      logging: shorten output of logLevelToString() · 60ab0b97
      Adam Simpkins authored
      Summary:
      Remove the "LogLevel::" prefix from the logLevelToString() output.
      
      This makes the output shorter and easier to read, and makes it simpler to write
      LogFormatter implementations that want a short human-readable level
      description.  Callers can always add a "LogLevel::" prefix on their own if
      desired.
      
      Reviewed By: wez
      
      Differential Revision: D5288601
      
      fbshipit-source-id: 046579ebdda76842d5a44c33d68941d73dd81162
      60ab0b97
    • Giuseppe Ottaviano's avatar
      Print expected/actual thread names when running EventBase logic in unexpected thread · fc84e02a
      Giuseppe Ottaviano authored
      Summary: The existing assertion errors do not give a lot of information to track down which thread is incorrectly using the `EventBase`. Print both the current thread name and the name of the thread running the event base loop.
      
      Reviewed By: luciang
      
      Differential Revision: D5289790
      
      fbshipit-source-id: 563c7f68b7f9b7a6e85e22290d7e81afbf89871e
      fc84e02a
    • Victor Zverovich's avatar
      Call onRecycle after element is marked as deallocated in IndexedMemPool · 15884e47
      Victor Zverovich authored
      Summary: Make `IndexedMemPool` call `Traits::onRecycle` on the element just before it is marked as deallocated. This mirrors the allocation behavior implemented in D5177462 and simplifies preventing access to recycled elements (the client just needs to check `isAllocated` before accessing the element).
      
      Reviewed By: nbronson
      
      Differential Revision: D5275283
      
      fbshipit-source-id: 58365b5b7b32b07fa56529c476078f241fc20811
      15884e47
    • Christopher Dykes's avatar
      Shift the exception tracer benchmark and test into the test directory · 51e345da
      Christopher Dykes authored
      Summary: Tests and benchmarks don't belong in the same directory as source code.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D5288080
      
      fbshipit-source-id: 865c6dfbeff751bda49870e5284e168d33aff256
      51e345da
    • Dave Watson's avatar
      Add flags to asymmetric mem barrier · 614cc8c3
      Dave Watson authored
      Summary:
      Original sys_membarrier call supported an EXPEDITED flag, that was much faster than the current version, at some extra CPU cost.
      
      The basic idea was a normal one would be used in a background thread, while EXPEDITED would be useful inline in foreground threads.
      
      Add the flag here, and use the mprotect hack until sys_membarrier supports both.
      
      Reviewed By: magedm
      
      Differential Revision: D5292680
      
      fbshipit-source-id: 30edf27514976991bbaa8e776a7138eb815ade36
      614cc8c3
    • Petr Lapukhov's avatar
      Have reserved sockopt to disable TSOCKS · 08f64cbb
      Petr Lapukhov authored
      Summary: as title, similar to TTLS
      
      Reviewed By: djwatson
      
      Differential Revision: D5284200
      
      fbshipit-source-id: 7eb95668740b239349c6e73f3b152e6506671072
      08f64cbb
    • Uladzislau Paulovich's avatar
      Add missing uint32 type to folly::ProgramOptions::gFlagAdders · f975d3c5
      Uladzislau Paulovich authored
      Summary: Absence of "uint32" type in gFlagAdders map breaks all apps that use gflags of this type (i.e. define a flag with "DEFINE_uint32").
      
      Reviewed By: WillerZ
      
      Differential Revision: D5286720
      
      fbshipit-source-id: c02bd959cb9ea9a47fba1e01429181ba09edf5dd
      f975d3c5
    • Giuseppe Ottaviano's avatar
      Add support for getting other threads' names · af5ec753
      Giuseppe Ottaviano authored
      Summary: Complete the `ThreadName.h` API.
      
      Reviewed By: luciang, Orvid
      
      Differential Revision: D5289160
      
      fbshipit-source-id: a48e61093008039da50b1c568364fa5b8744b401
      af5ec753
    • Adam Simpkins's avatar
      logging: reduce the amount of code emitted for log statements · fc91e303
      Adam Simpkins authored
      Summary:
      This refactors the logging code with the aim of reducing the amount of assembly
      code emitted for each log statement, particularly for `XLOG()` statements.
      Ideally it should be possible to put debug `XLOG()` statements throughout your
      code without having to worry about the performance overhead.  Therefore we
      should attempt to make sure that `XLOG()` statements do not generate a lot of
      assembly and hurt icache performance.
      
      This diff does not have any code behavior changes--it just moves code around a
      bit.  The high-level summary is:
      
      - Move as much code as possible into the LogStreamProcessor constructors and
        destructor.  Make sure these methods are defined in LogStreamProcessor.cpp to
        avoid having them be emitted inline at each log statement.
      - Move some of the XLOG level checking logic into separate non-inline functions
        defined in xlog.cpp
      - Pass xlog category information around as a pair of (categoryName,
        isOverridden) parameters.  If isOverridden is true then the categoryName
        parameter should be used as the category name directly.  If isOverridden is
        false, then categoryName is a filename that needs to go through filename to
        category name string processing.  This allows the category name processing to
        be done in non-inlined code.
      
      Reviewed By: wez
      
      Differential Revision: D5269976
      
      fbshipit-source-id: 7a7877ddfed66cd27ed82f052330b6aa2be4b37b
      fc91e303
    • Adam Simpkins's avatar
      logging: add printf-style logging macros · cf984921
      Adam Simpkins authored
      Summary:
      Add new `FB_LOGC()` and `XLOGC()` macros that accept C-style printf format
      strings.  (The `FB_LOGF()` and `XLOGF()` macro names are already used for
      `folly::format()` style formatting.)
      
      This will make it easier for users to update existing printf-style code to use
      this new logging library.
      
      These are in a separate `printf.h` header file that must be explicitly included
      to have access to these macros.  The intent is to encourage users to use one of
      the other APIs (streaming, append-style, or `folly::format()`) instead of these
      printf-like APIs in new code.
      
      Reviewed By: omry
      
      Differential Revision: D5269974
      
      fbshipit-source-id: 56e55f9642bb00806d9b4c762fb6a91778ef6ad3
      cf984921
    • Adam Simpkins's avatar
      logging: make XLOG_GET_CATEGORY() safe for all callers · e38fcb3a
      Adam Simpkins authored
      Summary:
      The `XLOG_GET_CATEGORY()` macro was previously written assuming it was only
      used inside `XLOG()` statement.  When used inside the main translation unit
      being compiled (e.g., a .cpp file and not a header file), the code assumed that
      the file-scope category had already been initialized, since a level check had
      presumably already been performed.
      
      However, it is useful in some places for external users (outside of the logging
      library itself) to call `XLOG_GET_CATEGORY()`.  In these cases a log level
      check may not have been performed yet, so the file-scope category may not be
      initialized yet.
      
      This diff renames the existing `XLOG_GET_CATEGORY()` macro to
      `XLOG_GET_CATEGORY_INTERNAL()` and adds a new `XLOG_GET_CATEGORY()` macro that
      is slower (it always looks up the category by name) but always safe to use.
      
      This also adds a new `XLOG_GET_CATEGORY_NAME()` macro, and renames the existing
      `XLOG_SET_CATEGORY()` macro to `XLOG_SET_CATEGORY_NAME()` for API consistency.
      
      Reviewed By: wez
      
      Differential Revision: D5269975
      
      fbshipit-source-id: 373805255823855282fa7a8d4a4d232ba06367f6
      e38fcb3a
    • Adam Simpkins's avatar
      logging: improve the AsyncFileWriterTest discard test · 440cddaf
      Adam Simpkins authored
      Summary:
      This improves the test that exercises the AsyncFileWriter message discarding
      logic.
      
      Previously each writer thread wrote a fixed number of small messages.  This was
      fairly slow, and wasn't always guaranteed to reliably produce discards.
      Now each writer thread writes larger messages, which produce discards faster.
      The test also automatically stops after 10 separate discard events, so that it
      finishes faster (typically a few hundred milliseconds, rather than 5+ seconds).
      
      This also updates the test to use XLOG() internally rather than using fprintf()
      to print to stderr, now that the XLOG() diffs have landed.
      
      Reviewed By: wez
      
      Differential Revision: D5261059
      
      fbshipit-source-id: 120224706fee36948ef76efbeb579ccc56400c51
      440cddaf
  6. 20 Jun, 2017 7 commits
    • Adam Simpkins's avatar
      logging: implement FATAL and DFATAL log levels · 61fbd669
      Adam Simpkins authored
      Summary:
      Add new `FATAL` and `DFATAL` log levels.
      
      Any log message with a level of `FATAL` always crashes the program.  Log
      messages with a level of `DFATAL` crash the program in debug build modes.
      
      Before crashing, the code makes sure to flush all LogHandlers, so that the
      fatal message is not lost if some of the LogHandlers process messages
      asynchronously.  If no LogHandlers were configured, the message is printed to
      stderr.
      
      Reviewed By: wez
      
      Differential Revision: D5189497
      
      fbshipit-source-id: c45dbd582fb1c3a962d00effb2967737ef97cc8b
      61fbd669
    • Maged Michael's avatar
      Update hazard pointer interface to standard proposal P0233R4 · eeae0d90
      Maged Michael authored
      Summary:
      Updated to the interface to be in synch with the latest standard proposal in P0233R4 as follows:
      - Renamed hazptr_owner as hazptr_holder.
      - Combined hazptr_holder member functions set() and clear() as reset().
      - Replaced the template parameter A for hazptr_holder member function templates try_protect() and get_protected with atomic<T*>.
      - Moved the template parameter T from the class hazptr_holder to its member functions try_protect(), get_protected(), and reset().
      - Added a non-template overload of hazptr_holder::reset() with an optional nullptr_t parameter.
      - Removed the template parameter T from the free function swap() as hazptr_holder is no longer a template.
      
      Reviewed By: davidtgoldblatt
      
      Differential Revision: D5283863
      
      fbshipit-source-id: 2bc1a09f4f844aa72d9b7dff9c450540bbe09972
      eeae0d90
    • Qi Zhou's avatar
      fix folly::FunctionScheduler.cancelFunctionAndWait() hanging issue · b3ef1edc
      Qi Zhou authored
      Summary:
      When
      - only one function is scheduled in FunctionScheduler; and
      - the function is running while cancelFunctionAndWait() is being called;
      FunctionScheduler.cancelFunctionAndWait() will hang forever.  The root cause is that the condition in cancelFunctionAndWait() is incorrect:
      
      ```
      runningCondvar_.wait(l, [currentFunction, this]() {
        return currentFunction != currentFunction_;
      });
      ```
      
      because currentFunction will not be changed if only one function is in the scheduler.
      
      The fix here is to
      - clear currentFunction as nullptr.  This also makes the internal behaviors of cancelFunction() and cancelFunctionAndWait() consistent.
      - introduces additional variable to indicate the state of cancelling current function.  After running the function, the background thread will detect cancellation of current function and clear the variable.
      - cancelFunctionAndWait() condition variable will wait for the variable to be cleared.
      
      Similarly, cancelAllFunctionsAndWait() also suffers from the same issue.
      
      Unit tests are added to reproduce the issue.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D5271664
      
      fbshipit-source-id: acb223304d3eab23129907ce9ff5e57e55f1e909
      b3ef1edc
    • Adam Simpkins's avatar
      logging: add LoggerDB::flushAllHandlers() · a5766338
      Adam Simpkins authored
      Summary:
      Add a method to flush all LogHandler objects.
      
      This will be necessary to implement FB_LOG(FATAL), as we will want to flush all
      outstanding messages before crashing.
      
      Reviewed By: wez
      
      Differential Revision: D5189501
      
      fbshipit-source-id: faf260b8e71e5dfed4a3b1c1aee32f072bd7b764
      a5766338
    • Adam Simpkins's avatar
      logging: add a LogHandler::flush() call · d65439dd
      Adam Simpkins authored
      Summary:
      Add a flush() call to the LogHandler interface.  This is needed to implement
      `FB_LOG(FATAL)` so that we can flush all LogHandlers before aborting the
      program.
      
      Reviewed By: wez
      
      Differential Revision: D5189499
      
      fbshipit-source-id: 75fa4d7e75ea26de5b7383bf7e8d073fb37e9309
      d65439dd
    • Adam Simpkins's avatar
      logging: add a NEVER_DISCARD flag to LogWriter · 84458670
      Adam Simpkins authored
      Summary:
      Add a flag to the LogWriter so we can ensure that particular messages are never
      discarded, even when the LogWriter is throttling messages.
      
      This functionality will be necessary to implement `FB_LOG(FATAL)` to that we
      can avoid discarding the reason for crashing.
      
      Reviewed By: wez
      
      Differential Revision: D5189498
      
      fbshipit-source-id: dc4322ea5ba449a341cdbdc32afb0ed466019801
      84458670
    • Adam Simpkins's avatar
      logging: add a small example program · 1b5a7dbf
      Adam Simpkins authored
      Summary:
      This adds a small example program which demonstrates using the logging library.
      
      This gives a very basic example of how the library is intended to be used, and
      can also be used to play around with controlling the log levels from the
      command line argument.
      
      Reviewed By: wez
      
      Differential Revision: D5083104
      
      fbshipit-source-id: ab09c6c88db33065f6e39f35b28014f2a6153cef
      1b5a7dbf