Include <folly/portability/SysTime.h> rather than <sys/time.h>
authorChristopher Dykes <cdykes@fb.com>
Mon, 30 May 2016 23:05:07 +0000 (16:05 -0700)
committerFacebook Github Bot 6 <facebook-github-bot-6-bot@fb.com>
Mon, 30 May 2016 23:09:18 +0000 (16:09 -0700)
Summary:
This changes includes of `<sys/time.h>` to `<folly/portability/SysTime.h>`.

The ultimate goal of all of this is to get HHVM compiling on Windows with MSVC 2015. At the moment there are no plans to support MCRouter, Squangle, or AFDT under Windows. There are also no current plans to support MinGW or Cygwin.

Now, on to the headers themselves. There are three primary kinds of portability headers.

  - Replacement headers. These are headers such as `<sys/time.h>` that MSVC simply does not have. These headers should always be included instead of the headers they are replacing.
  - Additive headers. These are headers, such as `<time.h>` that MSVC has, but are either missing functions, or has the functions but under a different name. The portability headers for these only needs to be included instead of the original header if you are using a function that MSVC does not have. The reason for this is that forcing the use of the portability header for `<stdlib.h>` just because MSVC doesn't have `mkdtemp` and `realpath` would just be messy.
  - Utility headers. These are portability headers, such as `Memory.h` that exist to provide a portable interface to various things, in this case the allocation and freeing of aligned memory. They are not implementing any existing API, and all contents are in the `folly` namespace.

The API's implemented in the first and second types of headers are intended as drop-in replacements for the Linux versions, however they only implement the functions and features that are actually needed, and are not intended as feature-complete replacements. They are not intended for use outside of Facebook projects. Any API's expecting text input expect them to be in the same encoding as the Posix API's define, in most cases that means UTF-8. Anywhere in the portability headers that fails to account for this is a bug, and should be pointed out in the diff (if it's still in review), or else by filing a task detailing the issue and assigning it to me.

For all headers, if there is a mechanism in C++11, or else in Folly itself, that allows the same functionality, that mechanism should be used instead of adding a function to the portability headers.

Reviewed By: swtaarrs, yfeldblum

Differential Revision: D3095643

fbshipit-source-id: 3a5c0029f95b03ea320725df88e14a67ca38a445

folly/Random.cpp
folly/experimental/EventCount.h
folly/test/AtomicHashMapTest.cpp
folly/test/MPMCQueueTest.cpp

index ef2e8b9cc5d6bc570870614398d1e31111246cee..f27092f218c09c81fbbbd7ffaea9a8637571d522 100644 (file)
@@ -18,7 +18,6 @@
 
 #include <atomic>
 #include <unistd.h>
-#include <sys/time.h>
 #include <mutex>
 #include <random>
 #include <array>
@@ -28,6 +27,7 @@
 #include <folly/File.h>
 #include <folly/FileUtil.h>
 #include <folly/ThreadLocal.h>
+#include <folly/portability/SysTime.h>
 
 #ifdef _MSC_VER
 # include <wincrypt.h>
index 7c491542013f0b4e474456384d9a558193af859c..e45be5a52d84a6f1833efc122b0dfcbe32d0e311 100644 (file)
@@ -19,7 +19,6 @@
 #include <unistd.h>
 #include <syscall.h>
 #include <linux/futex.h>
-#include <sys/time.h>
 #include <climits>
 #include <atomic>
 #include <thread>
@@ -27,6 +26,7 @@
 
 #include <folly/Bits.h>
 #include <folly/Likely.h>
+#include <folly/portability/SysTime.h>
 
 
 namespace folly {
index 4e5000d248267c13f61db6ddd0886c89257a3d3d..9082ddd62092ea10f04719f5c9e77b5b5dbf63d1 100644 (file)
 
 #include <glog/logging.h>
 #include <gtest/gtest.h>
-#include <sys/time.h>
 #include <thread>
 #include <atomic>
 #include <memory>
 #include <folly/Benchmark.h>
 #include <folly/Conv.h>
+#include <folly/portability/SysTime.h>
 
 using std::vector;
 using std::string;
index e3cd980c4f142f9d69ad3b1e85b8e9ac1541ecfd..d42f402ab0f96d69e27ef5bc59deeabdfb233714 100644 (file)
@@ -17,6 +17,7 @@
 #include <folly/MPMCQueue.h>
 #include <folly/Format.h>
 #include <folly/Memory.h>
+#include <folly/portability/SysTime.h>
 #include <folly/test/DeterministicSchedule.h>
 
 #include <boost/intrusive_ptr.hpp>
@@ -25,7 +26,6 @@
 #include <thread>
 #include <utility>
 #include <unistd.h>
-#include <sys/time.h>
 #include <sys/resource.h>
 
 #include <gtest/gtest.h>