From 73b89de71748a21e102d27b9f3ed1bf658766cb5 Mon Sep 17 00:00:00 2001
From: max42 <max42@yandex-team.com>
Date: Sat, 29 Jul 2023 00:02:16 +0300
Subject: YT-19210: expose YQL shared library for YT.

After this, a new target libyqlplugin.so appears. in open-source cmake build.
Diff in open-source YDB repo looks like the following: https://paste.yandex-team.ru/f302bdb4-7ef2-4362-91c7-6ca45f329264
---
 .../threading/cron/CMakeLists.darwin-x86_64.txt    | 18 ++++++
 .../threading/cron/CMakeLists.linux-aarch64.txt    | 19 ++++++
 .../cpp/threading/cron/CMakeLists.linux-x86_64.txt | 19 ++++++
 library/cpp/threading/cron/CMakeLists.txt          | 17 ++++++
 .../threading/cron/CMakeLists.windows-x86_64.txt   | 18 ++++++
 library/cpp/threading/cron/cron.cpp                | 69 ++++++++++++++++++++++
 library/cpp/threading/cron/cron.h                  | 18 ++++++
 library/cpp/threading/cron/ya.make                 | 11 ++++
 8 files changed, 189 insertions(+)
 create mode 100644 library/cpp/threading/cron/CMakeLists.darwin-x86_64.txt
 create mode 100644 library/cpp/threading/cron/CMakeLists.linux-aarch64.txt
 create mode 100644 library/cpp/threading/cron/CMakeLists.linux-x86_64.txt
 create mode 100644 library/cpp/threading/cron/CMakeLists.txt
 create mode 100644 library/cpp/threading/cron/CMakeLists.windows-x86_64.txt
 create mode 100644 library/cpp/threading/cron/cron.cpp
 create mode 100644 library/cpp/threading/cron/cron.h
 create mode 100644 library/cpp/threading/cron/ya.make

(limited to 'library/cpp/threading/cron')

diff --git a/library/cpp/threading/cron/CMakeLists.darwin-x86_64.txt b/library/cpp/threading/cron/CMakeLists.darwin-x86_64.txt
new file mode 100644
index 0000000000..429d3b0b0d
--- /dev/null
+++ b/library/cpp/threading/cron/CMakeLists.darwin-x86_64.txt
@@ -0,0 +1,18 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(cpp-threading-cron)
+target_link_libraries(cpp-threading-cron PUBLIC
+  contrib-libs-cxxsupp
+  yutil
+  cpp-deprecated-atomic
+)
+target_sources(cpp-threading-cron PRIVATE
+  ${CMAKE_SOURCE_DIR}/library/cpp/threading/cron/cron.cpp
+)
diff --git a/library/cpp/threading/cron/CMakeLists.linux-aarch64.txt b/library/cpp/threading/cron/CMakeLists.linux-aarch64.txt
new file mode 100644
index 0000000000..d5bb429c63
--- /dev/null
+++ b/library/cpp/threading/cron/CMakeLists.linux-aarch64.txt
@@ -0,0 +1,19 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(cpp-threading-cron)
+target_link_libraries(cpp-threading-cron PUBLIC
+  contrib-libs-linux-headers
+  contrib-libs-cxxsupp
+  yutil
+  cpp-deprecated-atomic
+)
+target_sources(cpp-threading-cron PRIVATE
+  ${CMAKE_SOURCE_DIR}/library/cpp/threading/cron/cron.cpp
+)
diff --git a/library/cpp/threading/cron/CMakeLists.linux-x86_64.txt b/library/cpp/threading/cron/CMakeLists.linux-x86_64.txt
new file mode 100644
index 0000000000..d5bb429c63
--- /dev/null
+++ b/library/cpp/threading/cron/CMakeLists.linux-x86_64.txt
@@ -0,0 +1,19 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(cpp-threading-cron)
+target_link_libraries(cpp-threading-cron PUBLIC
+  contrib-libs-linux-headers
+  contrib-libs-cxxsupp
+  yutil
+  cpp-deprecated-atomic
+)
+target_sources(cpp-threading-cron PRIVATE
+  ${CMAKE_SOURCE_DIR}/library/cpp/threading/cron/cron.cpp
+)
diff --git a/library/cpp/threading/cron/CMakeLists.txt b/library/cpp/threading/cron/CMakeLists.txt
new file mode 100644
index 0000000000..f8b31df0c1
--- /dev/null
+++ b/library/cpp/threading/cron/CMakeLists.txt
@@ -0,0 +1,17 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" AND NOT HAVE_CUDA)
+  include(CMakeLists.linux-aarch64.txt)
+elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
+  include(CMakeLists.darwin-x86_64.txt)
+elseif (WIN32 AND CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" AND NOT HAVE_CUDA)
+  include(CMakeLists.windows-x86_64.txt)
+elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND NOT HAVE_CUDA)
+  include(CMakeLists.linux-x86_64.txt)
+endif()
diff --git a/library/cpp/threading/cron/CMakeLists.windows-x86_64.txt b/library/cpp/threading/cron/CMakeLists.windows-x86_64.txt
new file mode 100644
index 0000000000..429d3b0b0d
--- /dev/null
+++ b/library/cpp/threading/cron/CMakeLists.windows-x86_64.txt
@@ -0,0 +1,18 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(cpp-threading-cron)
+target_link_libraries(cpp-threading-cron PUBLIC
+  contrib-libs-cxxsupp
+  yutil
+  cpp-deprecated-atomic
+)
+target_sources(cpp-threading-cron PRIVATE
+  ${CMAKE_SOURCE_DIR}/library/cpp/threading/cron/cron.cpp
+)
diff --git a/library/cpp/threading/cron/cron.cpp b/library/cpp/threading/cron/cron.cpp
new file mode 100644
index 0000000000..e7c1c59735
--- /dev/null
+++ b/library/cpp/threading/cron/cron.cpp
@@ -0,0 +1,69 @@
+#include "cron.h"
+
+#include <library/cpp/deprecated/atomic/atomic.h>
+
+#include <util/system/thread.h>
+#include <util/system/event.h>
+
+using namespace NCron;
+
+namespace {
+    struct TPeriodicHandle: public IHandle {
+        inline TPeriodicHandle(TJob job, TDuration interval, const TString& threadName)
+            : Job(job)
+            , Interval(interval)
+            , Done(false)
+        {
+            TThread::TParams params(DoRun, this);
+            if (!threadName.empty()) {
+                params.SetName(threadName);
+            }
+            Thread = MakeHolder<TThread>(params);
+            Thread->Start();
+        }
+
+        static inline void* DoRun(void* data) noexcept {
+            ((TPeriodicHandle*)data)->Run();
+
+            return nullptr;
+        }
+
+        inline void Run() noexcept {
+            while (true) {
+                Job();
+
+                Event.WaitT(Interval);
+
+                if (AtomicGet(Done)) {
+                    return;
+                }
+            }
+        }
+
+        ~TPeriodicHandle() override {
+            AtomicSet(Done, true);
+            Event.Signal();
+            Thread->Join();
+        }
+
+        TJob Job;
+        TDuration Interval;
+        TManualEvent Event;
+        TAtomic Done;
+        THolder<TThread> Thread;
+    };
+}
+
+IHandlePtr NCron::StartPeriodicJob(TJob job) {
+    return NCron::StartPeriodicJob(job, TDuration::Seconds(0), "");
+}
+
+IHandlePtr NCron::StartPeriodicJob(TJob job, TDuration interval) {
+    return NCron::StartPeriodicJob(job, interval, "");
+}
+
+IHandlePtr NCron::StartPeriodicJob(TJob job, TDuration interval, const TString& threadName) {
+    return new TPeriodicHandle(job, interval, threadName);
+}
+
+IHandle::~IHandle() = default;
diff --git a/library/cpp/threading/cron/cron.h b/library/cpp/threading/cron/cron.h
new file mode 100644
index 0000000000..77fa40c5e2
--- /dev/null
+++ b/library/cpp/threading/cron/cron.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#include <util/generic/ptr.h>
+#include <util/generic/function.h>
+#include <util/datetime/base.h>
+
+namespace NCron {
+    struct IHandle {
+        virtual ~IHandle();
+    };
+
+    using TJob = std::function<void()>;
+    using IHandlePtr = TAutoPtr<IHandle>;
+
+    IHandlePtr StartPeriodicJob(TJob job);
+    IHandlePtr StartPeriodicJob(TJob job, TDuration interval);
+    IHandlePtr StartPeriodicJob(TJob job, TDuration interval, const TString& threadName);
+}
diff --git a/library/cpp/threading/cron/ya.make b/library/cpp/threading/cron/ya.make
new file mode 100644
index 0000000000..ead272e837
--- /dev/null
+++ b/library/cpp/threading/cron/ya.make
@@ -0,0 +1,11 @@
+LIBRARY()
+
+SRCS(
+    cron.cpp
+)
+
+PEERDIR(
+    library/cpp/deprecated/atomic
+)
+
+END()
-- 
cgit v1.2.3