Move some implementation to cpp.
GitOrigin-RevId: b554d19ab8d8a6826c7f879d660c75d15c0d944a
This commit is contained in:
parent
f4069240e5
commit
389ff96082
@ -12,7 +12,6 @@
|
||||
#include "td/utils/logging.h"
|
||||
#include "td/utils/Random.h"
|
||||
|
||||
#include <initializer_list>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <utility>
|
||||
|
@ -10,8 +10,6 @@
|
||||
|
||||
#include "td/utils/logging.h"
|
||||
|
||||
#include <initializer_list>
|
||||
|
||||
REGISTER_TESTS(actors_workers);
|
||||
|
||||
namespace {
|
||||
|
@ -31,6 +31,7 @@ if (CLANG)
|
||||
endif()
|
||||
|
||||
set(TDUTILS_SOURCE
|
||||
td/utils/port/Clocks.cpp
|
||||
td/utils/port/Fd.cpp
|
||||
td/utils/port/FileFd.cpp
|
||||
td/utils/port/IPAddress.cpp
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <cstring>
|
||||
|
||||
namespace td {
|
||||
|
||||
template <int buffer_size = 32 * (1 << 10)>
|
||||
class MemoryLog : public LogInterface {
|
||||
static constexpr size_t MAX_OUTPUT_SIZE = buffer_size / 16 < (8 << 10) ? buffer_size / 16 : (8 << 10);
|
||||
@ -78,4 +79,5 @@ class MemoryLog : public LogInterface {
|
||||
char buffer_[buffer_size];
|
||||
std::atomic<uint32> pos_;
|
||||
};
|
||||
|
||||
} // namespace td
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <mutex>
|
||||
|
||||
namespace td {
|
||||
|
||||
class MpmcWaiter {
|
||||
public:
|
||||
int wait(int yields, uint32 worker_id) {
|
||||
@ -101,4 +102,5 @@ class MpmcWaiter {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace td
|
||||
|
@ -8,17 +8,16 @@
|
||||
|
||||
#include "td/utils/misc.h"
|
||||
#include "td/utils/port/EventFd.h"
|
||||
#include "td/utils/SpinLock.h"
|
||||
|
||||
#if !TD_EVENTFD_UNSUPPORTED
|
||||
#if !TD_WINDOWS
|
||||
#include <poll.h> // for pollfd, poll, POLLIN
|
||||
#include <poll.h>
|
||||
#include <sched.h>
|
||||
#endif
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include <td/utils/SpinLock.h>
|
||||
|
||||
namespace td {
|
||||
// interface like in PollableQueue
|
||||
template <class ValueT>
|
||||
|
@ -20,6 +20,7 @@
|
||||
#endif
|
||||
|
||||
namespace td {
|
||||
|
||||
class OptionsParser {
|
||||
public:
|
||||
class Option {
|
||||
@ -145,4 +146,5 @@ class OptionsParser {
|
||||
std::vector<Option> options_;
|
||||
std::string description_;
|
||||
};
|
||||
|
||||
} // namespace td
|
||||
|
@ -6,8 +6,14 @@
|
||||
//
|
||||
#include "td/utils/Time.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace td {
|
||||
|
||||
std::atomic<double> Time::now_;
|
||||
|
||||
bool operator==(Timestamp a, Timestamp b) {
|
||||
return std::abs(a.at() - b.at()) < 1e-6;
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include "td/utils/port/Clocks.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <cmath>
|
||||
|
||||
namespace td {
|
||||
|
||||
@ -83,9 +82,7 @@ class Timestamp {
|
||||
}
|
||||
}
|
||||
|
||||
friend bool operator==(Timestamp a, Timestamp b) {
|
||||
return std::abs(a.at() - b.at()) < 1e-6;
|
||||
}
|
||||
friend bool operator==(Timestamp a, Timestamp b);
|
||||
|
||||
private:
|
||||
double at_{0};
|
||||
|
@ -12,10 +12,7 @@
|
||||
#include "td/utils/Status.h"
|
||||
#include "td/utils/StringBuilder.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <initializer_list>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
@ -99,7 +96,9 @@ auto append(vector<T> &destination, vector<T> &&source) {
|
||||
return;
|
||||
}
|
||||
destination.reserve(destination.size() + source.size());
|
||||
std::move(source.begin(), source.end(), std::back_inserter(destination));
|
||||
for (auto &elem:source) {
|
||||
destination.push_back(std::move(elem));
|
||||
}
|
||||
reset_to_empty(source);
|
||||
}
|
||||
|
||||
|
23
tdutils/td/utils/port/Clocks.cpp
Normal file
23
tdutils/td/utils/port/Clocks.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
//
|
||||
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#include "td/utils/port/Clocks.h"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
namespace td {
|
||||
|
||||
ClocksDefault::Duration ClocksDefault::monotonic() {
|
||||
auto duration = std::chrono::steady_clock::now().time_since_epoch();
|
||||
return static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count()) * 1e-9;
|
||||
}
|
||||
|
||||
ClocksDefault::Duration ClocksDefault::system() {
|
||||
auto duration = std::chrono::system_clock::now().time_since_epoch();
|
||||
return static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count()) * 1e-9;
|
||||
}
|
||||
|
||||
} // namespace td
|
@ -6,8 +6,6 @@
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
|
||||
namespace td {
|
||||
|
||||
class ClocksBase {
|
||||
@ -19,14 +17,10 @@ class ClocksBase {
|
||||
class ClocksDefault {
|
||||
public:
|
||||
using Duration = ClocksBase::Duration;
|
||||
static Duration monotonic() {
|
||||
auto duration = std::chrono::steady_clock::now().time_since_epoch();
|
||||
return static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count()) * 1e-9;
|
||||
}
|
||||
static Duration system() {
|
||||
auto duration = std::chrono::system_clock::now().time_since_epoch();
|
||||
return static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count()) * 1e-9;
|
||||
}
|
||||
|
||||
static Duration monotonic();
|
||||
|
||||
static Duration system();
|
||||
};
|
||||
|
||||
using Clocks = ClocksDefault;
|
||||
|
@ -12,7 +12,7 @@
|
||||
#if !TD_THREAD_UNSUPPORTED && !TD_EVENTFD_UNSUPPORTED
|
||||
|
||||
#if !TD_WINDOWS
|
||||
#include <poll.h> // for pollfd, poll, POLLIN
|
||||
#include <poll.h>
|
||||
#include <sched.h>
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user