diff options
author | monster <monster@ydb.tech> | 2022-07-07 14:41:37 +0300 |
---|---|---|
committer | monster <monster@ydb.tech> | 2022-07-07 14:41:37 +0300 |
commit | 06e5c21a835c0e923506c4ff27929f34e00761c2 (patch) | |
tree | 75efcbc6854ef9bd476eb8bf00cc5c900da436a2 /library/cpp/deprecated | |
parent | 03f024c4412e3aa613bb543cf1660176320ba8f4 (diff) | |
download | ydb-06e5c21a835c0e923506c4ff27929f34e00761c2.tar.gz |
fix ya.make
Diffstat (limited to 'library/cpp/deprecated')
-rw-r--r-- | library/cpp/deprecated/mapped_file/mapped_file.h | 72 | ||||
-rw-r--r-- | library/cpp/deprecated/threadable/threadable.cpp | 1 | ||||
-rw-r--r-- | library/cpp/deprecated/threadable/threadable.h | 81 |
3 files changed, 154 insertions, 0 deletions
diff --git a/library/cpp/deprecated/mapped_file/mapped_file.h b/library/cpp/deprecated/mapped_file/mapped_file.h new file mode 100644 index 00000000000..45859ed65a0 --- /dev/null +++ b/library/cpp/deprecated/mapped_file/mapped_file.h @@ -0,0 +1,72 @@ +#pragma once + +#include <util/generic/flags.h> +#include <util/generic/ptr.h> +#include <util/generic/string.h> +#include <util/generic/utility.h> +#include <util/generic/yexception.h> +#include <util/system/align.h> +#include <util/system/file.h> +#include <util/system/filemap.h> +#include <util/system/yassert.h> + +#include <cstdio> +#include <new> + +/// Deprecated (by pg@), use TFileMap or TMemoryMap instead +class TMappedFile { +private: + TFileMap* Map_; + +private: + TMappedFile(TFileMap* map, const char* dbgName); + +public: + TMappedFile() { + Map_ = nullptr; + } + + ~TMappedFile() { + term(); + } + + explicit TMappedFile(const TString& name) { + Map_ = nullptr; + init(name, TFileMap::oRdOnly); + } + + TMappedFile(const TFile& file, TFileMap::EOpenMode om = TFileMap::oRdOnly, const char* dbgName = "unknown"); + + void init(const TString& name); + + void init(const TString& name, TFileMap::EOpenMode om); + + void init(const TString& name, size_t length, TFileMap::EOpenMode om); + + void init(const TFile&, TFileMap::EOpenMode om = TFileMap::oRdOnly, const char* dbgName = "unknown"); + + void flush(); + + void term() { + if (Map_) { + Map_->Unmap(); + delete Map_; + Map_ = nullptr; + } + } + + size_t getSize() const { + return (Map_ ? Map_->MappedSize() : 0); + } + + void* getData(size_t pos = 0) const { + Y_ASSERT(!Map_ || (pos <= getSize())); + return (Map_ ? (void*)((unsigned char*)Map_->Ptr() + pos) : nullptr); + } + + void precharge(size_t pos = 0, size_t size = (size_t)-1) const; + + void swap(TMappedFile& file) noexcept { + DoSwap(Map_, file.Map_); + } +}; diff --git a/library/cpp/deprecated/threadable/threadable.cpp b/library/cpp/deprecated/threadable/threadable.cpp new file mode 100644 index 00000000000..73ed2e62089 --- /dev/null +++ b/library/cpp/deprecated/threadable/threadable.cpp @@ -0,0 +1 @@ +#include "threadable.h" diff --git a/library/cpp/deprecated/threadable/threadable.h b/library/cpp/deprecated/threadable/threadable.h new file mode 100644 index 00000000000..77fb5878ffe --- /dev/null +++ b/library/cpp/deprecated/threadable/threadable.h @@ -0,0 +1,81 @@ +#pragma once + +#include <util/system/thread.h> +#include <util/system/defaults.h> +#include <util/generic/ptr.h> + +//deprecated. use future.h instead +template <class T> +class TThreadable: public T { +public: + using TThreadProc = TThread::TThreadProc; + + inline TThreadable() + : Arg(nullptr) + , ThreadInit(nullptr) + { + } + + inline int Run(void* arg = nullptr, size_t stackSize = 0, TThreadProc init = DefInit) { + if (Thread_) { + return 1; + } + + Arg = arg; + ThreadInit = init; + + try { + THolder<TThread> thread(new TThread(TThread::TParams(Dispatch, this, stackSize))); + + thread->Start(); + Thread_.Swap(thread); + } catch (...) { + return 1; + } + + return 0; + } + + inline int Join(void** result = nullptr) { + if (!Thread_) { + return 1; + } + + try { + void* ret = Thread_->Join(); + + if (result) { + *result = ret; + } + + Thread_.Destroy(); + + return 0; + } catch (...) { + } + + return 1; + } + +protected: + static TThreadable<T>* This(void* ptr) { + return (TThreadable<T>*)ptr; + } + + static void* Dispatch(void* ptr) { + void* result = This(ptr)->ThreadInit(This(ptr)->Arg); + + return result ? result : (void*)(size_t)This(ptr)->T::Run(This(ptr)->Arg); + } + + static void* DefInit(void*) { + return nullptr; + } + +public: + void* Arg; + TThreadProc ThreadInit; + +private: + THolder<TThread> Thread_; +}; |