walltime.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2018 The urg_stamped Authors
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef SCIP2_WALLTIME_H
00018 #define SCIP2_WALLTIME_H
00019 
00020 #include <string>
00021 
00022 namespace scip2
00023 {
00024 template <int DEVICE_TIMESTAMP_BITS>
00025 class Walltime
00026 {
00027 protected:
00028   bool initialized_;
00029   uint32_t time_device_prev_;
00030   uint64_t walltime_device_base_;
00031 
00032 public:
00033   uint64_t update(const uint32_t &time_device)
00034   {
00035     if (!initialized_)
00036     {
00037       time_device_prev_ = time_device;
00038       initialized_ = true;
00039     }
00040 
00041     if (time_device < (1 << DEVICE_TIMESTAMP_BITS) / 2 &&
00042         (1 << DEVICE_TIMESTAMP_BITS) / 2 < time_device_prev_)
00043       walltime_device_base_ += 1 << DEVICE_TIMESTAMP_BITS;
00044     time_device_prev_ = time_device;
00045 
00046     return walltime_device_base_ + time_device;
00047   }
00048   Walltime()
00049     : initialized_(false)
00050     , time_device_prev_(0)
00051     , walltime_device_base_(0)
00052   {
00053   }
00054 };
00055 }  // namespace scip2
00056 
00057 #endif  // SCIP2_WALLTIME_H


urg_stamped
Author(s): Atsushi Watanabe
autogenerated on Thu Jun 6 2019 18:59:51