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/logging.h"
|
||||||
#include "td/utils/Random.h"
|
#include "td/utils/Random.h"
|
||||||
|
|
||||||
#include <initializer_list>
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
|
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
|
|
||||||
#include <initializer_list>
|
|
||||||
|
|
||||||
REGISTER_TESTS(actors_workers);
|
REGISTER_TESTS(actors_workers);
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -31,6 +31,7 @@ if (CLANG)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(TDUTILS_SOURCE
|
set(TDUTILS_SOURCE
|
||||||
|
td/utils/port/Clocks.cpp
|
||||||
td/utils/port/Fd.cpp
|
td/utils/port/Fd.cpp
|
||||||
td/utils/port/FileFd.cpp
|
td/utils/port/FileFd.cpp
|
||||||
td/utils/port/IPAddress.cpp
|
td/utils/port/IPAddress.cpp
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
template <int buffer_size = 32 * (1 << 10)>
|
template <int buffer_size = 32 * (1 << 10)>
|
||||||
class MemoryLog : public LogInterface {
|
class MemoryLog : public LogInterface {
|
||||||
static constexpr size_t MAX_OUTPUT_SIZE = buffer_size / 16 < (8 << 10) ? buffer_size / 16 : (8 << 10);
|
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];
|
char buffer_[buffer_size];
|
||||||
std::atomic<uint32> pos_;
|
std::atomic<uint32> pos_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
class MpmcWaiter {
|
class MpmcWaiter {
|
||||||
public:
|
public:
|
||||||
int wait(int yields, uint32 worker_id) {
|
int wait(int yields, uint32 worker_id) {
|
||||||
@ -101,4 +102,5 @@ class MpmcWaiter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -8,17 +8,16 @@
|
|||||||
|
|
||||||
#include "td/utils/misc.h"
|
#include "td/utils/misc.h"
|
||||||
#include "td/utils/port/EventFd.h"
|
#include "td/utils/port/EventFd.h"
|
||||||
|
#include "td/utils/SpinLock.h"
|
||||||
|
|
||||||
#if !TD_EVENTFD_UNSUPPORTED
|
#if !TD_EVENTFD_UNSUPPORTED
|
||||||
#if !TD_WINDOWS
|
#if !TD_WINDOWS
|
||||||
#include <poll.h> // for pollfd, poll, POLLIN
|
#include <poll.h>
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include <td/utils/SpinLock.h>
|
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
// interface like in PollableQueue
|
// interface like in PollableQueue
|
||||||
template <class ValueT>
|
template <class ValueT>
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
class OptionsParser {
|
class OptionsParser {
|
||||||
public:
|
public:
|
||||||
class Option {
|
class Option {
|
||||||
@ -145,4 +146,5 @@ class OptionsParser {
|
|||||||
std::vector<Option> options_;
|
std::vector<Option> options_;
|
||||||
std::string description_;
|
std::string description_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -6,8 +6,14 @@
|
|||||||
//
|
//
|
||||||
#include "td/utils/Time.h"
|
#include "td/utils/Time.h"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
std::atomic<double> Time::now_;
|
std::atomic<double> Time::now_;
|
||||||
|
|
||||||
|
bool operator==(Timestamp a, Timestamp b) {
|
||||||
|
return std::abs(a.at() - b.at()) < 1e-6;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
#include "td/utils/port/Clocks.h"
|
#include "td/utils/port/Clocks.h"
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
@ -83,9 +82,7 @@ class Timestamp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
friend bool operator==(Timestamp a, Timestamp b) {
|
friend bool operator==(Timestamp a, Timestamp b);
|
||||||
return std::abs(a.at() - b.at()) < 1e-6;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double at_{0};
|
double at_{0};
|
||||||
|
@ -12,10 +12,7 @@
|
|||||||
#include "td/utils/Status.h"
|
#include "td/utils/Status.h"
|
||||||
#include "td/utils/StringBuilder.h"
|
#include "td/utils/StringBuilder.h"
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <initializer_list>
|
|
||||||
#include <iterator>
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
@ -99,7 +96,9 @@ auto append(vector<T> &destination, vector<T> &&source) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
destination.reserve(destination.size() + source.size());
|
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);
|
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
|
#pragma once
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
class ClocksBase {
|
class ClocksBase {
|
||||||
@ -19,14 +17,10 @@ class ClocksBase {
|
|||||||
class ClocksDefault {
|
class ClocksDefault {
|
||||||
public:
|
public:
|
||||||
using Duration = ClocksBase::Duration;
|
using Duration = ClocksBase::Duration;
|
||||||
static Duration monotonic() {
|
|
||||||
auto duration = std::chrono::steady_clock::now().time_since_epoch();
|
static Duration monotonic();
|
||||||
return static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count()) * 1e-9;
|
|
||||||
}
|
static Duration system();
|
||||||
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;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using Clocks = ClocksDefault;
|
using Clocks = ClocksDefault;
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#if !TD_THREAD_UNSUPPORTED && !TD_EVENTFD_UNSUPPORTED
|
#if !TD_THREAD_UNSUPPORTED && !TD_EVENTFD_UNSUPPORTED
|
||||||
|
|
||||||
#if !TD_WINDOWS
|
#if !TD_WINDOWS
|
||||||
#include <poll.h> // for pollfd, poll, POLLIN
|
#include <poll.h>
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user