| 1 | /******************************************************************** |
| 2 | * Copyright (c) 2013 - 2014, Pivotal Inc. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Author: Zhanwei Wang |
| 6 | ********************************************************************/ |
| 7 | /******************************************************************** |
| 8 | * 2014 - |
| 9 | * open source under Apache License Version 2.0 |
| 10 | ********************************************************************/ |
| 11 | /** |
| 12 | * Licensed to the Apache Software Foundation (ASF) under one |
| 13 | * or more contributor license agreements. See the NOTICE file |
| 14 | * distributed with this work for additional information |
| 15 | * regarding copyright ownership. The ASF licenses this file |
| 16 | * to you under the Apache License, Version 2.0 (the |
| 17 | * "License"); you may not use this file except in compliance |
| 18 | * with the License. You may obtain a copy of the License at |
| 19 | * |
| 20 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 21 | * |
| 22 | * Unless required by applicable law or agreed to in writing, software |
| 23 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 24 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 25 | * See the License for the specific language governing permissions and |
| 26 | * limitations under the License. |
| 27 | */ |
| 28 | #ifndef _HDFS_LIBHDFS3_COMMON_DATETIME_H_ |
| 29 | #define _HDFS_LIBHDFS3_COMMON_DATETIME_H_ |
| 30 | |
| 31 | #include "platform.h" |
| 32 | |
| 33 | #include <ctime> |
| 34 | #include <cassert> |
| 35 | |
| 36 | #if defined(NEED_BOOST) && defined(HAVE_BOOST_CHRONO) |
| 37 | |
| 38 | #include <boost/chrono.hpp> |
| 39 | |
| 40 | namespace Hdfs { |
| 41 | namespace Internal { |
| 42 | |
| 43 | using namespace boost::chrono; |
| 44 | |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | #elif defined(HAVE_STD_CHRONO) |
| 49 | |
| 50 | #include <chrono> |
| 51 | |
| 52 | namespace Hdfs { |
| 53 | namespace Internal { |
| 54 | |
| 55 | using namespace std::chrono; |
| 56 | |
| 57 | #ifndef HAVE_STEADY_CLOCK |
| 58 | typedef std::chrono::monotonic_clock steady_clock; |
| 59 | #endif |
| 60 | |
| 61 | } |
| 62 | } |
| 63 | #else |
| 64 | #error "no chrono library is available" |
| 65 | #endif |
| 66 | |
| 67 | namespace Hdfs { |
| 68 | namespace Internal { |
| 69 | |
| 70 | template<typename TimeStamp> |
| 71 | static int64_t ToMilliSeconds(TimeStamp const & s, TimeStamp const & e) { |
| 72 | assert(e >= s); |
| 73 | return duration_cast<milliseconds>(e - s).count(); |
| 74 | } |
| 75 | |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | #endif /* _HDFS_LIBHDFS3_COMMON_DATETIME_H_ */ |
| 80 | |