Skip to content

Commit

Permalink
Include <folly/portability/SysTime.h> rather than <sys/time.h>
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Orvid authored and Facebook Github Bot 4 committed May 30, 2016
1 parent 932f15b commit bff57bd
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion thrift/lib/cpp/TLogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/

#ifdef THRIFT_HAVE_CLOCK_GETTIME
#include <sys/time.h>
#include <folly/portability/SysTime.h>
#endif
#include <time.h>

Expand Down
2 changes: 1 addition & 1 deletion thrift/lib/cpp/concurrency/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#if defined(THRIFT_HAVE_CLOCK_GETTIME)
#include <time.h>
#elif defined(THRIFT_HAVE_GETTIMEOFDAY)
#include <sys/time.h>
#include <folly/portability/SysTime.h>
#endif // defined(THRIFT_HAVE_CLOCK_GETTIME)
#include <errno.h>
#include <assert.h>
Expand Down
3 changes: 2 additions & 1 deletion thrift/lib/cpp/concurrency/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
#include <stddef.h>
#include <stdint.h>
#include <time.h>
#include <sys/time.h>
#include <chrono>

#include <folly/portability/SysTime.h>

namespace apache { namespace thrift { namespace concurrency {

/**
Expand Down
2 changes: 1 addition & 1 deletion thrift/lib/cpp/concurrency/test/ThreadManagerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

#include <sys/time.h>
#include <sys/resource.h>
#include <numa.h>

Expand All @@ -26,6 +25,7 @@
#include <thread>

#include <folly/Synchronized.h>
#include <folly/portability/SysTime.h>
#include <gtest/gtest.h>
#include <thrift/lib/cpp/concurrency/FunctionRunner.h>
#include <thrift/lib/cpp/concurrency/Monitor.h>
Expand Down
3 changes: 2 additions & 1 deletion thrift/lib/cpp/server/TServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@

#include <thrift/lib/cpp/server/TServer.h>

#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>

#include <folly/portability/SysTime.h>

namespace apache { namespace thrift { namespace server {

int increase_max_fds(int max_fds) {
Expand Down
3 changes: 2 additions & 1 deletion thrift/lib/cpp/transport/TFDTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
#define _THRIFT_TRANSPORT_TFDTRANSPORT_H_ 1

#include <string>
#include <sys/time.h>

#include <folly/portability/SysTime.h>

#include <thrift/lib/cpp/transport/TTransport.h>
#include <thrift/lib/cpp/transport/TVirtualTransport.h>
Expand Down
6 changes: 2 additions & 4 deletions thrift/lib/cpp/transport/TFileTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@
#include <thrift/lib/cpp/TProcessor.h>

#include <pthread.h>
#ifdef THRIFT_HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#include <time.h>
#endif
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
Expand All @@ -40,6 +36,8 @@
#include <iostream>
#include <sys/stat.h>

#include <folly/portability/SysTime.h>

namespace apache { namespace thrift { namespace transport {

using boost::scoped_ptr;
Expand Down
2 changes: 1 addition & 1 deletion thrift/lib/cpp/transport/TSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
#define _THRIFT_TRANSPORT_TSOCKET_H_ 1

#include <string>
#include <sys/time.h>

#include <thrift/lib/cpp/transport/TRpcTransport.h>
#include <thrift/lib/cpp/transport/TVirtualTransport.h>
#include <folly/SocketAddress.h>
#include <folly/portability/SysTime.h>

namespace apache { namespace thrift { namespace transport {

Expand Down
3 changes: 2 additions & 1 deletion thrift/lib/cpp/util/PausableTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
#include <thrift/lib/cpp/util/PausableTimer.h>

#include <stdint.h>
#include <sys/time.h>

#include <folly/portability/SysTime.h>

namespace apache { namespace thrift { namespace util {

Expand Down
3 changes: 2 additions & 1 deletion thrift/lib/cpp/util/PausableTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
#pragma once

#include <stdint.h>
#include <sys/time.h>
#include <sys/types.h>

#include <folly/portability/SysTime.h>

namespace apache { namespace thrift { namespace util {

class PausableTimer {
Expand Down
3 changes: 2 additions & 1 deletion thrift/test/Benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
#include <thrift/lib/cpp/protocol/THeaderProtocol.h>
#include <thrift/test/gen-cpp/DebugProtoTest_types.h>
#include <time.h>
#include <sys/time.h>

#include <folly/portability/SysTime.h>

class Timer {
public:
Expand Down
2 changes: 1 addition & 1 deletion thrift/test/TFileTransportTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
#include <getopt.h>
#include <gtest/gtest.h>
#include <glog/logging.h>
#include <sys/time.h>

#include <thrift/lib/cpp/concurrency/Mutex.h>
#include <thrift/lib/cpp/concurrency/Util.h>
#include <thrift/lib/cpp/transport/TFileTransport.h>
#include <folly/io/async/test/Util.h>
#include <folly/portability/SysTime.h>

using apache::thrift::concurrency::Guard;
using apache::thrift::concurrency::Mutex;
Expand Down
3 changes: 2 additions & 1 deletion thrift/test/THeaderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <memory>
#include <stdio.h>
#include <iostream>
#include <sys/time.h>
#include <unistd.h>

#include <thrift/lib/cpp/async/TEventServer.h>
Expand Down Expand Up @@ -47,6 +46,8 @@

#include <thrift/test/gen-cpp/Service.h>

#include <folly/portability/SysTime.h>

#include <gtest/gtest.h>

using namespace std;
Expand Down
3 changes: 2 additions & 1 deletion thrift/test/cpp/src/TestClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#define __STDC_FORMAT_MACROS
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <thrift/lib/cpp/protocol/TBinaryProtocol.h>
#include <thrift/lib/cpp/protocol/THeaderProtocol.h>
#include <thrift/lib/cpp/transport/TTransportUtils.h>
Expand All @@ -30,6 +29,8 @@
#include <memory>
#include <thrift/test/gen-cpp/ThriftTest.h>

#include <folly/portability/SysTime.h>

#include <inttypes.h>

using std::string;
Expand Down

0 comments on commit bff57bd

Please sign in to comment.