Shaka Player Embedded
clock.cc
Go to the documentation of this file.
1 // Copyright 2017 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "src/util/clock.h"
16 
17 #include <chrono>
18 #include <thread>
19 
20 #include "src/util/macros.h"
21 
22 namespace shaka {
23 namespace util {
24 
26 const Clock Clock::Instance;
28 
29 uint64_t Clock::GetMonotonicTime() const {
30  return std::chrono::steady_clock::now().time_since_epoch() /
31  std::chrono::milliseconds(1);
32 }
33 
34 uint64_t Clock::GetEpochTime() const {
35  return std::chrono::system_clock::now().time_since_epoch() /
36  std::chrono::milliseconds(1);
37 }
38 
39 void Clock::SleepSeconds(double seconds) const {
40  std::this_thread::sleep_for(
41  std::chrono::milliseconds(static_cast<int64_t>(seconds * 1000)));
42 }
43 
44 } // namespace util
45 } // namespace shaka
#define END_ALLOW_COMPLEX_STATICS
Definition: macros.h:43
#define BEGIN_ALLOW_COMPLEX_STATICS
Definition: macros.h:42
static const Clock Instance
Definition: clock.h:29
virtual void SleepSeconds(double seconds) const
Definition: clock.cc:39
virtual uint64_t GetMonotonicTime() const
Definition: clock.cc:29
virtual uint64_t GetEpochTime() const
Definition: clock.cc:34