From abc9ed2cd90129d41e69d413d2c48ba3f09a090e Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 14 Jul 2022 18:38:48 +0300 Subject: [PATCH] Minor fixes. --- CMake/GetGitRevisionDescription.cmake | 6 ++-- CMake/GetGitRevisionDescription.cmake.in | 36 ++++++++++++------------ example/README.md | 2 +- td/generate/scheme/td_api.tl | 4 +-- td/mtproto/AuthData.cpp | 2 +- td/telegram/net/NetQueryDispatcher.cpp | 5 ++-- tdactor/td/actor/Timeout.h | 2 ++ tdactor/td/actor/impl/Scheduler-decl.h | 1 + tdactor/td/actor/impl/Scheduler.cpp | 1 + tdutils/generate/CMakeLists.txt | 2 +- tdutils/td/utils/AtomicRead.h | 11 ++++---- tdutils/td/utils/MpmcQueue.h | 5 ++-- tdutils/td/utils/MpmcWaiter.h | 1 - tdutils/td/utils/SpinLock.h | 1 - tdutils/td/utils/port/Mutex.h | 8 ++++++ tdutils/td/utils/queue.h | 6 ++-- tdutils/td/utils/tests.h | 2 +- tdutils/test/ConcurrentHashMap.cpp | 1 - 18 files changed, 51 insertions(+), 45 deletions(-) diff --git a/CMake/GetGitRevisionDescription.cmake b/CMake/GetGitRevisionDescription.cmake index 32be4fa85..73fe1cc14 100644 --- a/CMake/GetGitRevisionDescription.cmake +++ b/CMake/GetGitRevisionDescription.cmake @@ -59,11 +59,11 @@ function(get_git_head_revision _refspecvar _hashvar) _git_find_closest_git_dir("${CMAKE_CURRENT_SOURCE_DIR}" GIT_DIR) file(RELATIVE_PATH _relative_to_source_dir "${CMAKE_CURRENT_SOURCE_DIR}" "${GIT_DIR}") - if ("${_relative_to_source_dir}" MATCHES "^[.][.]") + if (_relative_to_source_dir MATCHES "^[.][.]") # We've gone above the CMake root dir. set(GIT_DIR "") endif() - if ("${GIT_DIR}" STREQUAL "") + if (GIT_DIR STREQUAL "") set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE) set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE) return() @@ -83,7 +83,7 @@ function(get_git_head_revision _refspecvar _hashvar) WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" OUTPUT_VARIABLE out ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) - if (NOT "${out}" STREQUAL "") + if (NOT out STREQUAL "") # If out is non-empty, GIT_DIR/CMAKE_CURRENT_SOURCE_DIR is in a submodule file(READ ${GIT_DIR} submodule) string(REGEX REPLACE "gitdir: (.*)$" "\\1" GIT_DIR_RELATIVE ${submodule}) diff --git a/CMake/GetGitRevisionDescription.cmake.in b/CMake/GetGitRevisionDescription.cmake.in index e35156f25..bfc1e54c1 100644 --- a/CMake/GetGitRevisionDescription.cmake.in +++ b/CMake/GetGitRevisionDescription.cmake.in @@ -20,24 +20,24 @@ set(HEAD_HASH) file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024) string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS) -if(HEAD_CONTENTS MATCHES "ref") - # named branch - string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}") - if(EXISTS "@GIT_DIR@/${HEAD_REF}") - configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) - else() - configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY) - file(READ "@GIT_DATA@/packed-refs" PACKED_REFS) - if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}") - set(HEAD_HASH "${CMAKE_MATCH_1}") - endif() - endif() +if (HEAD_CONTENTS MATCHES "ref") + # named branch + string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}") + if (EXISTS "@GIT_DIR@/${HEAD_REF}") + configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) + else() + configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY) + file(READ "@GIT_DATA@/packed-refs" PACKED_REFS) + if (PACKED_REFS MATCHES "([0-9a-z]*) ${HEAD_REF}") + set(HEAD_HASH "${CMAKE_MATCH_1}") + endif() + endif() else() - # detached HEAD - configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY) + # detached HEAD + configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY) endif() -if(NOT HEAD_HASH) - file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024) - string(STRIP "${HEAD_HASH}" HEAD_HASH) -endif() \ No newline at end of file +if (NOT HEAD_HASH) + file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024) + string(STRIP "${HEAD_HASH}" HEAD_HASH) +endif() diff --git a/example/README.md b/example/README.md index ce4b0176b..e3cf1b7ac 100644 --- a/example/README.md +++ b/example/README.md @@ -73,7 +73,7 @@ at [tdl](https://github.com/Bannerets/tdl), which provides a convenient, fully-a You can also see [TdNode](https://github.com/puppy0cam/TdNode), [tglib](https://github.com/nodegin/tglib), [node-tdlib](https://github.com/wfjsw/node-tdlib), [tdlnode](https://github.com/fonbah/tdlnode), [Paper Plane](https://github.com/par6n/paper-plane), or [node-tlg](https://github.com/dilongfa/node-tlg) for other examples of TDLib JSON interface integration with Node.js. -See also the source code of [DIBgram](https://github.com/DIBgram/DIBgram) - an unofficial Telegram web app which looks like Telegram Desktop. +See also the source code of [DIBgram](https://github.com/DIBgram/DIBgram) - an unofficial Telegram web application which looks like Telegram Desktop. TDLib can be used also from NativeScript through the [JSON](https://github.com/tdlib/td#using-json) interface. See [nativescript-tglib](https://github.com/arpit2438735/nativescript-tglib) as an example of a NativeScript library for building Telegram clients. diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 0096fd613..7add74a29 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -4793,7 +4793,7 @@ searchMessages chat_list:ChatList query:string offset_date:int32 offset_chat_id: //@filter Additional filter for messages to search; pass null to search for all messages searchSecretMessages chat_id:int53 query:string offset:string limit:int32 filter:SearchMessagesFilter = FoundMessages; -//@description Searches for call messages. Returns the results in reverse chronological order (i. e., in order of decreasing message_id). For optimal performance, the number of returned messages is chosen by TDLib +//@description Searches for call messages. Returns the results in reverse chronological order (i.e., in order of decreasing message_id). For optimal performance, the number of returned messages is chosen by TDLib //@from_message_id Identifier of the message from which to search; use 0 to get results from the last message //@limit The maximum number of messages to be returned; up to 100. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit //@only_missed Pass true to search only for messages with missed/declined calls @@ -6081,7 +6081,7 @@ getSupergroupMembers supergroup_id:int53 filter:SupergroupMembersFilter offset:i closeSecretChat secret_chat_id:int32 = Ok; -//@description Returns a list of service actions taken by chat members and administrators in the last 48 hours. Available only for supergroups and channels. Requires administrator rights. Returns results in reverse chronological order (i. e., in order of decreasing event_id) +//@description Returns a list of service actions taken by chat members and administrators in the last 48 hours. Available only for supergroups and channels. Requires administrator rights. Returns results in reverse chronological order (i.e., in order of decreasing event_id) //@chat_id Chat identifier @query Search query by which to filter events @from_event_id Identifier of an event from which to return results. Use 0 to get results from the latest events @limit The maximum number of events to return; up to 100 //@filters The types of events to return; pass null to get chat events of all types @user_ids User identifiers by which to filter events. By default, events relating to all users will be returned getChatEventLog chat_id:int53 query:string from_event_id:int64 limit:int32 filters:chatEventLogFilters user_ids:vector = ChatEvents; diff --git a/td/mtproto/AuthData.cpp b/td/mtproto/AuthData.cpp index d37f7a9c1..c87ba6ee8 100644 --- a/td/mtproto/AuthData.cpp +++ b/td/mtproto/AuthData.cpp @@ -21,7 +21,7 @@ Status check_message_id_duplicates(int64 *saved_message_ids, size_t max_size, si // In addition, the identifiers (msg_id) of the last N messages received from the other side must be stored, and if // a message comes in with msg_id lower than all or equal to any of the stored values, that message is to be // ignored. Otherwise, the new message msg_id is added to the set, and, if the number of stored msg_id values is - // greater than N, the oldest (i. e. the lowest) is forgotten. + // greater than N, the oldest (i.e. the lowest) is forgotten. if (end_pos == 2 * max_size) { std::copy_n(&saved_message_ids[max_size], max_size, &saved_message_ids[0]); end_pos = max_size; diff --git a/td/telegram/net/NetQueryDispatcher.cpp b/td/telegram/net/NetQueryDispatcher.cpp index eea49a34b..e94845e72 100644 --- a/td/telegram/net/NetQueryDispatcher.cpp +++ b/td/telegram/net/NetQueryDispatcher.cpp @@ -25,7 +25,6 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/port/sleep.h" -#include "td/utils/port/thread.h" #include "td/utils/Slice.h" #include "td/utils/SliceBuilder.h" @@ -195,7 +194,7 @@ Status NetQueryDispatcher::wait_dc_init(DcId dc_id, bool force) { return Status::Error("Closing"); } #if !TD_THREAD_UNSUPPORTED - td::usleep_for(1); + usleep_for(1); #endif } } @@ -332,7 +331,7 @@ void NetQueryDispatcher::set_main_dc_id(int32 new_main_dc_id) { return; } - // Very rare event. Mutex is ok. + // Very rare event; mutex is ok. std::lock_guard guard(main_dc_id_mutex_); if (new_main_dc_id == main_dc_id_) { return; diff --git a/tdactor/td/actor/Timeout.h b/tdactor/td/actor/Timeout.h index 5c2293b99..cde72657b 100644 --- a/tdactor/td/actor/Timeout.h +++ b/tdactor/td/actor/Timeout.h @@ -8,6 +8,8 @@ #include "td/actor/actor.h" +#include "td/utils/common.h" + namespace td { class Timeout final : public Actor { diff --git a/tdactor/td/actor/impl/Scheduler-decl.h b/tdactor/td/actor/impl/Scheduler-decl.h index 396995e6c..72893e4e8 100644 --- a/tdactor/td/actor/impl/Scheduler-decl.h +++ b/tdactor/td/actor/impl/Scheduler-decl.h @@ -11,6 +11,7 @@ #include "td/actor/impl/EventFull-decl.h" #include "td/utils/Closure.h" +#include "td/utils/common.h" #include "td/utils/FlatHashMap.h" #include "td/utils/Heap.h" #include "td/utils/List.h" diff --git a/tdactor/td/actor/impl/Scheduler.cpp b/tdactor/td/actor/impl/Scheduler.cpp index 9ad7cb72c..b29b5b34d 100644 --- a/tdactor/td/actor/impl/Scheduler.cpp +++ b/tdactor/td/actor/impl/Scheduler.cpp @@ -21,6 +21,7 @@ #include "td/utils/MpscPollableQueue.h" #include "td/utils/ObjectPool.h" #include "td/utils/port/thread_local.h" +#include "td/utils/Promise.h" #include "td/utils/ScopeGuard.h" #include "td/utils/Time.h" diff --git a/tdutils/generate/CMakeLists.txt b/tdutils/generate/CMakeLists.txt index b36a1a4f6..69b42d914 100644 --- a/tdutils/generate/CMakeLists.txt +++ b/tdutils/generate/CMakeLists.txt @@ -25,7 +25,7 @@ add_custom_target(tdmime_auto DEPENDS ${TDMIME_SOURCE}) if (NOT CMAKE_CROSSCOMPILING) find_program(GPERF_EXECUTABLE gperf) if (NOT GPERF_EXECUTABLE) - message(FATAL_ERROR "Could NOT find gperf. Add path to gperf executable to PATH environment variable or specify it manually using GPERF_EXECUTABLE option, i. e. 'cmake -DGPERF_EXECUTABLE:FILEPATH=\"\"'.") + message(FATAL_ERROR "Could NOT find gperf. Add path to gperf executable to PATH environment variable or specify it manually using GPERF_EXECUTABLE option, i.e. 'cmake -DGPERF_EXECUTABLE:FILEPATH=\"\"'.") endif() set(GPERF_FILES diff --git a/tdutils/td/utils/AtomicRead.h b/tdutils/td/utils/AtomicRead.h index 58d96e436..d30e960a8 100644 --- a/tdutils/td/utils/AtomicRead.h +++ b/tdutils/td/utils/AtomicRead.h @@ -8,7 +8,6 @@ #include "td/utils/common.h" #include "td/utils/port/sleep.h" -#include "td/utils/port/thread.h" #include "td/utils/type_traits.h" #include @@ -21,11 +20,11 @@ template class AtomicRead { public: void read(T &dest) const { - int it = 0; - const int wait_each_it = 4; - auto wait = [&]() { - it++; - if (it % wait_each_it == 0) { + uint32 counter = 0; + auto wait = [&] { + counter++; + const int wait_each_count = 4; + if (counter % wait_each_count == 0) { usleep_for(1); } }; diff --git a/tdutils/td/utils/MpmcQueue.h b/tdutils/td/utils/MpmcQueue.h index 9d5708586..f1f12a37f 100644 --- a/tdutils/td/utils/MpmcQueue.h +++ b/tdutils/td/utils/MpmcQueue.h @@ -15,7 +15,6 @@ #include "td/utils/HazardPointers.h" #include "td/utils/logging.h" #include "td/utils/port/sleep.h" -#include "td/utils/port/thread.h" #include "td/utils/ScopeGuard.h" #include @@ -306,7 +305,7 @@ class MpmcQueueOld { if (try_pop(value, thread_id)) { return value; } - td::usleep_for(1); + usleep_for(1); } } @@ -430,7 +429,7 @@ class MpmcQueue { if (try_pop(value, thread_id)) { return value; } - td::usleep_for(1); + usleep_for(1); } } diff --git a/tdutils/td/utils/MpmcWaiter.h b/tdutils/td/utils/MpmcWaiter.h index 7075c3f7c..7ece498ff 100644 --- a/tdutils/td/utils/MpmcWaiter.h +++ b/tdutils/td/utils/MpmcWaiter.h @@ -9,7 +9,6 @@ #include "td/utils/common.h" #include "td/utils/logging.h" #include "td/utils/port/sleep.h" -#include "td/utils/port/thread.h" #include #include diff --git a/tdutils/td/utils/SpinLock.h b/tdutils/td/utils/SpinLock.h index abaee7dff..3413f6c5b 100644 --- a/tdutils/td/utils/SpinLock.h +++ b/tdutils/td/utils/SpinLock.h @@ -7,7 +7,6 @@ #pragma once #include "td/utils/port/sleep.h" -#include "td/utils/port/thread.h" #include #include diff --git a/tdutils/td/utils/port/Mutex.h b/tdutils/td/utils/port/Mutex.h index 2cced68d6..40d9f482d 100644 --- a/tdutils/td/utils/port/Mutex.h +++ b/tdutils/td/utils/port/Mutex.h @@ -1,8 +1,15 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022 +// +// 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) +// #pragma once #include namespace td { + class Mutex { public: struct Guard { @@ -19,4 +26,5 @@ class Mutex { private: std::mutex mutex_; }; + } // namespace td diff --git a/tdutils/td/utils/queue.h b/tdutils/td/utils/queue.h index 6e5b67023..e6d69aae3 100644 --- a/tdutils/td/utils/queue.h +++ b/tdutils/td/utils/queue.h @@ -7,7 +7,7 @@ #pragma once #include "td/utils/port/EventFd.h" -#include "td/utils/port/thread.h" +#include "td/utils/port/sleep.h" #if !TD_THREAD_UNSUPPORTED && !TD_EVENTFD_UNSUPPORTED @@ -32,7 +32,7 @@ class Backoff { if (cnt < 1) { // 50 return true; } else { - td::usleep_for(1); + usleep_for(1); return cnt < 3; // 500 } } @@ -47,7 +47,7 @@ class InfBackoff { if (cnt < 50) { return true; } else { - td::usleep_for(1); + usleep_for(1); return true; } } diff --git a/tdutils/td/utils/tests.h b/tdutils/td/utils/tests.h index 2d1b92877..69b920626 100644 --- a/tdutils/td/utils/tests.h +++ b/tdutils/td/utils/tests.h @@ -11,11 +11,11 @@ #include "td/utils/format.h" #include "td/utils/logging.h" #include "td/utils/port/sleep.h" -#include "td/utils/port/thread.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" #include +#include #include #include #include diff --git a/tdutils/test/ConcurrentHashMap.cpp b/tdutils/test/ConcurrentHashMap.cpp index de8ef9a71..afdb8aea8 100644 --- a/tdutils/test/ConcurrentHashMap.cpp +++ b/tdutils/test/ConcurrentHashMap.cpp @@ -13,7 +13,6 @@ #include "td/utils/tests.h" #include -#include #if !TD_THREAD_UNSUPPORTED