diff --git a/far/changelog b/far/changelog index 175b75d485..9841663872 100644 --- a/far/changelog +++ b/far/changelog @@ -1,3 +1,7 @@ +drkns 18.02.2017 19:05:09 +0000 - build 4899 + +1. Рефакторинг, переименования. + svs 14.02.2017 20:19:16 +0300 - build 4898 1. SQLite 3.17.0 diff --git a/far/common/enumerator.hpp b/far/common/enumerator.hpp index 8550f7f126..71e86ad260 100644 --- a/far/common/enumerator.hpp +++ b/far/common/enumerator.hpp @@ -91,7 +91,7 @@ class enumerator enumerator() { TERSE_STATIC_ASSERT(std::is_base_of::value); } }; -#define IMPLEMENTS_ENUMERATOR(type) friend typename type::enumerator_type; +#define IMPLEMENTS_ENUMERATOR(type) friend typename type::enumerator_type template class inline_enumerator: public enumerator, value_type> @@ -110,7 +110,7 @@ class inline_enumerator: public enumerator diff --git a/far/configdb.cpp b/far/configdb.cpp index 5982dacc91..f622a15b6c 100644 --- a/far/configdb.cpp +++ b/far/configdb.cpp @@ -384,23 +384,23 @@ class HierarchicalConfigDb: public HierarchicalConfig, public SQLiteDb public: explicit HierarchicalConfigDb(const string& DbName, bool Local = false): // If a thread with same event name is running, we will open that event here - AsyncDone(Event::manual, Event::signaled, make_name(GetPath(), GetName()).data()) + AsyncDone(os::event::type::manual, os::event::state::signaled, os::make_name(GetPath(), GetName()).data()) { // and wait for the signal - AsyncDone.Wait(); + AsyncDone.wait(); Initialize(DbName, Local); } virtual ~HierarchicalConfigDb() override { - HierarchicalConfigDb::EndTransaction(); AsyncDone.Set(); + HierarchicalConfigDb::EndTransaction(); AsyncDone.set(); } protected: virtual void AsyncFinish() override { - AsyncDone.Reset(); - ConfigProvider().AddThread(Thread(&Thread::detach, &HierarchicalConfigDb::AsyncDelete, this)); + AsyncDone.reset(); + ConfigProvider().AddThread(os::thread(&os::thread::detach, &HierarchicalConfigDb::AsyncDelete, this)); } virtual bool InitializeImpl(const string& DbName, bool Local) override @@ -706,7 +706,7 @@ class HierarchicalConfigDb: public HierarchicalConfig, public SQLiteDb stmt_count }; - Event AsyncDone; + os::event AsyncDone; }; static constexpr std::pair ColorFlagNames[] = @@ -1615,7 +1615,7 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb virtual ~HistoryConfigCustom() override { WaitAllAsync(); - StopEvent.Set(); + StopEvent.set(); } private: @@ -1624,12 +1624,12 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb return Days * 24ull * 60ull * 60ull * 10000000ull; } - Thread WorkThread; - Event StopEvent; - Event AsyncDeleteAddDone; - Event AsyncCommitDone; - Event AsyncWork; - MultiWaiter AllWaiter; + os::thread WorkThread; + os::event StopEvent; + os::event AsyncDeleteAddDone; + os::event AsyncCommitDone; + os::event AsyncWork; + os::multi_waiter AllWaiter; struct AsyncWorkItem { @@ -1644,38 +1644,38 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb string strData; }; - SyncedQueue> WorkQueue; + os::synced_queue> WorkQueue; - void WaitAllAsync() const { AllWaiter.Wait(); } - void WaitCommitAsync() const { AsyncCommitDone.Wait(); } + void WaitAllAsync() const { AllWaiter.wait(); } + void WaitCommitAsync() const { AsyncCommitDone.wait(); } bool StartThread() { - StopEvent = Event(Event::automatic, Event::nonsignaled); + StopEvent = os::event(os::event::type::automatic, os::event::state::nonsignaled); string EventName; if (GetPath() != L":memory:") { - EventName = make_name(GetPath(), GetName()); + EventName = os::make_name(GetPath(), GetName()); } - AsyncDeleteAddDone = Event(Event::manual, Event::signaled, (EventName + L"_Delete").data()); - AsyncCommitDone = Event(Event::manual, Event::signaled, (EventName + L"_Commit").data()); - AllWaiter.Add(AsyncDeleteAddDone); - AllWaiter.Add(AsyncCommitDone); - AsyncWork = Event(Event::automatic, Event::nonsignaled); - WorkThread = Thread(&Thread::join, &HistoryConfigCustom::ThreadProc, this); + AsyncDeleteAddDone = os::event(os::event::type::manual, os::event::state::signaled, (EventName + L"_Delete").data()); + AsyncCommitDone = os::event(os::event::type::manual, os::event::state::signaled, (EventName + L"_Commit").data()); + AllWaiter.add(AsyncDeleteAddDone); + AllWaiter.add(AsyncCommitDone); + AsyncWork = os::event(os::event::type::automatic, os::event::state::nonsignaled); + WorkThread = os::thread(&os::thread::join, &HistoryConfigCustom::ThreadProc, this); return true; } void ThreadProc() { // TODO: try/catch & exception_ptr - MultiWaiter Waiter; - Waiter.Add(AsyncWork); - Waiter.Add(StopEvent); + os::multi_waiter Waiter; + Waiter.add(AsyncWork); + Waiter.add(StopEvent); for (;;) { - DWORD wait = Waiter.Wait(MultiWaiter::wait_any); + const auto wait = Waiter.wait(os::multi_waiter::mode::any); if (wait != WAIT_OBJECT_0) break; @@ -1704,9 +1704,9 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb } } if (bAddDelete) - AsyncDeleteAddDone.Set(); + AsyncDeleteAddDone.set(); if (bCommit) - AsyncCommitDone.Set(); + AsyncCommitDone.set(); } } @@ -1749,8 +1749,8 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb { WorkQueue.emplace(nullptr); WaitAllAsync(); - AsyncCommitDone.Reset(); - AsyncWork.Set(); + AsyncCommitDone.reset(); + AsyncWork.set(); return true; } @@ -1858,8 +1858,8 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb WorkQueue.emplace(std::move(item)); WaitAllAsync(); - AsyncDeleteAddDone.Reset(); - AsyncWork.Set(); + AsyncDeleteAddDone.reset(); + AsyncWork.set(); return true; } @@ -2264,7 +2264,7 @@ config_provider::config_provider(mode Mode): config_provider::~config_provider() { - MultiWaiter(ALL_CONST_RANGE(m_Threads)).Wait(); + os::multi_waiter(ALL_CONST_RANGE(m_Threads)).wait(); SQLiteDb::library_free(); } @@ -2291,7 +2291,7 @@ bool config_provider::Export(const string& File) { //TODO: export local plugin settings auto& e = CreateChild(root, "pluginsconfig"); - for(auto& i: os::fs::enum_file(Global->Opt->ProfilePath + L"\\PluginsData\\*.db")) + for(auto& i: os::fs::enum_files(Global->Opt->ProfilePath + L"\\PluginsData\\*.db")) { i.strFileName.resize(i.strFileName.size()-3); InplaceUpper(i.strFileName); @@ -2369,10 +2369,10 @@ bool config_provider::ShowProblems() const return Message(MSG_WARNING, MSG(lng::MProblemDb), m_Problems, { MSG(lng::MShowConfigFolders), MSG(lng::MIgnore) }) == Message::first_button; } -void config_provider::AddThread(Thread&& thread) +void config_provider::AddThread(os::thread&& thread) { m_Threads.emplace_back(std::move(thread)); - m_Threads.erase(std::remove_if(ALL_RANGE(m_Threads), std::mem_fn(&Thread::Signaled)), m_Threads.end()); + m_Threads.erase(std::remove_if(ALL_RANGE(m_Threads), std::mem_fn(&os::thread::is_signaled)), m_Threads.end()); } config_provider& ConfigProvider() diff --git a/far/configdb.hpp b/far/configdb.hpp index 11e1305ee8..a97a6ec051 100644 --- a/far/configdb.hpp +++ b/far/configdb.hpp @@ -365,7 +365,7 @@ class config_provider: noncopyable bool ShowProblems() const; bool ServiceMode(const string& File); - void AddThread(Thread&& thread); + void AddThread(os::thread&& thread); static void ClearPluginsCache(); @@ -393,7 +393,7 @@ class config_provider: noncopyable void CheckDatabase(class SQLiteDb *pDb); int m_LoadResult; - std::vector m_Threads; + std::vector m_Threads; std::vector m_Problems; std::unique_ptr m_TemplateSource; mode m_Mode; diff --git a/far/constitle.cpp b/far/constitle.cpp index f890547bf5..e34dc947e6 100644 --- a/far/constitle.cpp +++ b/far/constitle.cpp @@ -98,11 +98,11 @@ void ConsoleTitle::SetUserTitle(const string& Title) UserTitle() = Title; } -CriticalSection TitleCS; +os::critical_section TitleCS; void ConsoleTitle::SetFarTitle(const string& Title, bool Flush) { - SCOPED_ACTION(CriticalSectionLock)(TitleCS); + SCOPED_ACTION(os::critical_section_lock)(TitleCS); FarTitle() = Title; Global->ScrBuf->SetTitle(UserTitle().empty()? FarTitle() + GetFarTitleAddons() : UserTitle()); diff --git a/far/dirmix.cpp b/far/dirmix.cpp index 7e5017e5f3..9b0c7c5426 100644 --- a/far/dirmix.cpp +++ b/far/dirmix.cpp @@ -135,7 +135,7 @@ int TestFolder(const string& Path) strFindPath += L"*"; // первая проверка - че-нить считать можем? - os::fs::enum_file Find(strFindPath); + const auto Find = os::fs::enum_files(strFindPath); if (Find.begin() != Find.end()) { return TSTFLD_NOTEMPTY; diff --git a/far/editcontrol.cpp b/far/editcontrol.cpp index aa614b8ba1..d03fee4935 100644 --- a/far/editcontrol.cpp +++ b/far/editcontrol.cpp @@ -251,7 +251,7 @@ static bool EnumFiles(VMenu2& Menu, const string& Str) return EnumWithQuoutes(Menu, Str, [](VMenu2& Menu, const string& Token, const std::function& Inserter) { - for (const auto& i: os::fs::enum_file(os::env::expand_strings(Token) + L"*")) + for (const auto& i: os::fs::enum_files(os::env::expand_strings(Token) + L"*")) { const auto FileName = PointToName(Token); const auto NameMatch = !StrCmpNI(FileName, i.strFileName.data(), StrLength(FileName)); @@ -295,7 +295,7 @@ static bool EnumModules(VMenu2& Menu, const string& Module) str = Path; AddEndSlash(str); append(str, Token, L'*'); - for (const auto& FindData: os::fs::enum_file(str)) + for (const auto& FindData: os::fs::enum_files(str)) { for (const auto& Ext: PathExtList) { diff --git a/far/elevation.cpp b/far/elevation.cpp index 04e60e5949..c7df9c9793 100644 --- a/far/elevation.cpp +++ b/far/elevation.cpp @@ -175,7 +175,7 @@ T elevation::RetrieveLastErrorAndResult() const template auto elevation::execute(lng Why, const string& Object, T Fallback, const F1& PrivilegedHander, const F2& ElevatedHandler) { - SCOPED_ACTION(CriticalSectionLock)(m_CS); + SCOPED_ACTION(os::critical_section_lock)(m_CS); if (!ElevationApproveDlg(Why, Object)) return Fallback; @@ -292,9 +292,9 @@ static os::handle create_elevated_process(const string& Parameters) static bool connect_pipe_to_process(const os::handle& Process, const os::handle& Pipe) { - Event AEvent(Event::automatic, Event::nonsignaled); + os::event AEvent(os::event::type::automatic, os::event::state::nonsignaled); OVERLAPPED Overlapped; - AEvent.Associate(Overlapped); + AEvent.associate(Overlapped); if (!ConnectNamedPipe(Pipe.native_handle(), &Overlapped)) { const auto LastError = GetLastError(); @@ -302,10 +302,10 @@ static bool connect_pipe_to_process(const os::handle& Process, const os::handle& return false; } - MultiWaiter Waiter; - Waiter.Add(AEvent); - Waiter.Add(Process.native_handle()); - if (Waiter.Wait(MultiWaiter::wait_any, 15'000) != WAIT_OBJECT_0) + os::multi_waiter Waiter; + Waiter.add(AEvent); + Waiter.add(Process.native_handle()); + if (Waiter.wait(os::multi_waiter::mode::any, 15'000) != WAIT_OBJECT_0) return false; DWORD NumberOfBytesTransferred; @@ -314,7 +314,7 @@ static bool connect_pipe_to_process(const os::handle& Process, const os::handle& void elevation::TerminateChildProcess() const { - if (!m_Process.signaled()) + if (!m_Process.is_signaled()) { TerminateProcess(m_Process.native_handle(), ERROR_PROCESS_ABORTED); SetLastError(ERROR_PROCESS_ABORTED); @@ -323,7 +323,7 @@ void elevation::TerminateChildProcess() const bool elevation::Initialize() { - if (m_Process && !m_Process.signaled()) + if (m_Process && !m_Process.is_signaled()) return true; if (!m_Pipe) @@ -356,7 +356,7 @@ bool elevation::Initialize() if (!connect_pipe_to_process(m_Process, m_Pipe)) { - if (m_Process.signaled()) + if (m_Process.is_signaled()) { DWORD ExitCode; SetLastError(GetExitCodeProcess(m_Process.native_handle(), &ExitCode)? ExitCode : ERROR_GEN_FAILURE); @@ -486,14 +486,14 @@ bool elevation::ElevationApproveDlg(lng Why, const string& Object) if(!Global->IsMainThread()) { - Event SyncEvent(Event::automatic, Event::nonsignaled); + os::event SyncEvent(os::event::type::automatic, os::event::state::nonsignaled); listener_ex Listener([&SyncEvent](const any& Payload) { ElevationApproveDlgSync(*any_cast(Payload)); - SyncEvent.Set(); + SyncEvent.set(); }); MessageManager().notify(Listener.GetEventName(), &Data); - SyncEvent.Wait(); + SyncEvent.wait(); } else { diff --git a/far/elevation.hpp b/far/elevation.hpp index 41281244f1..f1772c9888 100644 --- a/far/elevation.hpp +++ b/far/elevation.hpp @@ -121,7 +121,7 @@ class elevation: noncopyable bool m_Elevation; bool m_DontAskAgain; int m_Recurse; - CriticalSection m_CS; + os::critical_section m_CS; string m_PipeName; }; diff --git a/far/farexcpt.cpp b/far/farexcpt.cpp index 85c87a4a5a..e5a111fb7c 100644 --- a/far/farexcpt.cpp +++ b/far/farexcpt.cpp @@ -729,7 +729,7 @@ int SehFilter(int Code, EXCEPTION_POINTERS* Info, const wchar_t* Function, Plugi { bool Result = false; { - Thread(&Thread::join, [&] { Result = ProcessGenericException(Info, nullptr, nullptr, nullptr); }); + os::thread(&os::thread::join, [&] { Result = ProcessGenericException(Info, nullptr, nullptr, nullptr); }); } if (Result) { diff --git a/far/farwinapi.cpp b/far/farwinapi.cpp index 1ab05af673..8f24000bb8 100644 --- a/far/farwinapi.cpp +++ b/far/farwinapi.cpp @@ -334,63 +334,65 @@ namespace fs bool is_not_empty_directory(const string& Object) { - enum_file Find(Object + L"\\*"); + const auto Find = enum_files(Object + L"\\*"); return Find.begin() != Find.end(); } -enum_file::enum_file(const string& Object, bool ScanSymLink): - m_Object(NTPath(Object)), - m_ScanSymLink(ScanSymLink) +//------------------------------------------------------------------------- + +string detail::enum_files_prepare(const string& Object) { - bool Root = false; - const auto Type = ParsePath(m_Object, nullptr, &Root); - if(Root && (Type == PATH_DRIVELETTER || Type == PATH_DRIVELETTERUNC || Type == PATH_VOLUMEGUID)) + auto PreparedObject = NTPath(Object); + auto Root = false; + const auto Type = ParsePath(PreparedObject, nullptr, &Root); + if (Root && (Type == PATH_DRIVELETTER || Type == PATH_DRIVELETTERUNC || Type == PATH_VOLUMEGUID)) { - AddEndSlash(m_Object); + AddEndSlash(PreparedObject); } else { - DeleteEndSlash(m_Object); + DeleteEndSlash(PreparedObject); } + return PreparedObject; } -bool enum_file::get(size_t index, value_type& FindData) const +bool detail::get_file_impl(find_file_handle& Handle, const string& Object, size_t index, FAR_FIND_DATA& FindData, bool ScanSymLink) { - bool Result = false; + auto Result = false; if (!index) { // temporary disable elevation to try "real" name first { SCOPED_ACTION(elevation::suppress); - m_Handle = FindFirstFileInternal(m_Object, FindData); + Handle = FindFirstFileInternal(Object, FindData); } - if (!m_Handle && GetLastError() == ERROR_ACCESS_DENIED) + if (!Handle && GetLastError() == ERROR_ACCESS_DENIED) { - if(m_ScanSymLink) + if (ScanSymLink) { - string strReal(m_Object); + auto strReal = Object; // only links in path should be processed, not the object name itself CutToSlash(strReal); strReal = ConvertNameToReal(strReal); AddEndSlash(strReal); - strReal+=PointToName(m_Object); + strReal += PointToName(Object); strReal = NTPath(strReal); - m_Handle = FindFirstFileInternal(strReal, FindData); + Handle = FindFirstFileInternal(strReal, FindData); } - if (!m_Handle && ElevationRequired(ELEVATION_READ_REQUEST)) + if (!Handle && ElevationRequired(ELEVATION_READ_REQUEST)) { - m_Handle = FindFirstFileInternal(m_Object, FindData); + Handle = FindFirstFileInternal(Object, FindData); } } - Result = m_Handle? true : false; + Result = Handle != nullptr; } else { - if (m_Handle) + if (Handle) { - Result = FindNextFileInternal(m_Handle, FindData); + Result = FindNextFileInternal(Handle, FindData); } } @@ -401,56 +403,56 @@ bool enum_file::get(size_t index, value_type& FindData) const (FindData.strAlternateFileName.empty() || FindData.strAlternateFileName == FindData.strFileName)) { // index not important here, anything but 0 is fine - Result = get(1, FindData); + Result = get_file_impl(Handle, Object, 1, FindData, ScanSymLink); } return Result; } //------------------------------------------------------------------------- -bool enum_name::get(size_t index, value_type& value) const +bool detail::get_name_impl(find_handle& Handle, const string& Object, size_t Index, string& Value) { - if (!index) + if (!Index) { - m_Handle = FindFirstFileName(m_Object, 0, value); - return m_Handle? true : false; + Handle = FindFirstFileName(Object, 0, Value); + return Handle != nullptr; } - return FindNextFileName(m_Handle, value); + return FindNextFileName(Handle, Value); } //------------------------------------------------------------------------- -bool enum_stream::get(size_t index, value_type& value) const +bool detail::get_stream_impl(find_file_handle& Handle, const string& Object, size_t Index, WIN32_FIND_STREAM_DATA& Value) { - if (!index) + if (!Index) { - m_Handle = FindFirstStream(m_Object, FindStreamInfoStandard, &value); - return m_Handle? true : false; + Handle = os::FindFirstStream(Object, FindStreamInfoStandard, &Value); + return Handle != nullptr; } - return FindNextStream(m_Handle, &value); + return FindNextStream(Handle, &Value); } //------------------------------------------------------------------------- -bool enum_volume::get(size_t index, value_type& value) const +bool detail::get_volume_impl(find_volume_handle& Handle, size_t Index, string& Value) { wchar_t VolumeName[50]; - if (!index) + if (!Index) { - m_Handle.reset(FindFirstVolume(VolumeName, static_cast(std::size(VolumeName)))); - if (!m_Handle) + Handle.reset(FindFirstVolume(VolumeName, static_cast(std::size(VolumeName)))); + if (!Handle) { return false; } } else { - if (!FindNextVolume(m_Handle.native_handle(), VolumeName, static_cast(std::size(VolumeName)))) + if (!FindNextVolume(Handle.native_handle(), VolumeName, static_cast(std::size(VolumeName)))) { return false; } } - value = VolumeName; + Value = VolumeName; return true; } @@ -1162,7 +1164,7 @@ bool GetVolumeInformation( bool GetFindDataEx(const string& FileName, FAR_FIND_DATA& FindData,bool ScanSymLink) { - fs::enum_file Find(FileName, ScanSymLink); + const auto Find = fs::enum_files(FileName, ScanSymLink); auto ItemIterator = Find.begin(); if (ItemIterator != Find.end()) { @@ -1578,7 +1580,7 @@ static bool internalNtQueryGetFinalPathNameByHandle(HANDLE hFile, string& FinalF } // try to convert NT path (\Device\HarddiskVolume1) to \\?\Volume{...} path - for (auto& VolumeName: os::fs::enum_volume()) + for (auto& VolumeName: os::fs::enum_volumes()) { if (const auto Len = MatchNtPathRoot(NtPath, VolumeName.substr(4, VolumeName.size() - 5))) // w/o prefix and trailing slash { diff --git a/far/farwinapi.hpp b/far/farwinapi.hpp index 9aba480957..2bd9e47eba 100644 --- a/far/farwinapi.hpp +++ b/far/farwinapi.hpp @@ -39,36 +39,25 @@ namespace os { namespace detail { - template - class handle_t: public conditional> + template + class handle_t: public std::unique_ptr, deleter> { + using base = std::unique_ptr, deleter>; + public: - NONCOPYABLE(handle_t); TRIVIALLY_MOVABLE(handle_t); - using pointer = HANDLE; constexpr handle_t() = default; constexpr handle_t(nullptr_t) {} - explicit handle_t(HANDLE Handle) { reset(Handle); } - - bool operator!() const noexcept { return !m_Handle; } - - void reset(HANDLE Handle = nullptr) { m_Handle.reset(normalise(Handle)); } - - void close() { m_Handle.reset(); } - - HANDLE native_handle() const { return m_Handle.get(); } - - HANDLE release() { return m_Handle.release(); } - - bool wait(DWORD Milliseconds = INFINITE) const { return WaitForSingleObject(m_Handle.get(), Milliseconds) == WAIT_OBJECT_0; } - - bool signaled() const { return wait(0); } + explicit handle_t(HANDLE Handle): base(normalise(Handle)) {} + void reset(HANDLE Handle = nullptr) { base::reset(normalise(Handle)); } + HANDLE native_handle() const { return base::get(); } + void close() { reset(); } + bool wait(DWORD Milliseconds = INFINITE) const { return WaitForSingleObject(native_handle(), Milliseconds) == WAIT_OBJECT_0; } + bool is_signaled() const { return wait(0); } private: static HANDLE normalise(HANDLE Handle) { return Handle == INVALID_HANDLE_VALUE? nullptr : Handle; } - - std::unique_ptr, T> m_Handle; }; struct handle_closer { void operator()(HANDLE Handle) const; }; @@ -175,73 +164,66 @@ namespace os namespace fs { - class enum_file: public enumerator + namespace detail { - IMPLEMENTS_ENUMERATOR(enum_file); - - public: - NONCOPYABLE(enum_file); - TRIVIALLY_MOVABLE(enum_file); - - enum_file(const string& Object, bool ScanSymLink = true); - - private: - bool get(size_t index, value_type& value) const; - - string m_Object; - mutable find_file_handle m_Handle; - bool m_ScanSymLink; - }; + string enum_files_prepare(const string&); + bool get_file_impl(find_file_handle&, const string&, size_t, FAR_FIND_DATA&, bool); + } - class enum_name: public enumerator + inline auto enum_files(const string& Object, bool ScanSymLink = true) { - IMPLEMENTS_ENUMERATOR(enum_name); - - public: - NONCOPYABLE(enum_name); - TRIVIALLY_MOVABLE(enum_name); - - enum_name(const string& Object): m_Object(Object) {} - - private: - bool get(size_t index, value_type& value) const; - - string m_Object; - mutable find_handle m_Handle; - }; + using value_type = FAR_FIND_DATA; + find_file_handle Handle; + return make_inline_enumerator([=, m_Object = detail::enum_files_prepare(Object), m_Handle = std::move(Handle)](size_t Index, value_type& Value) mutable + { + return detail::get_file_impl(m_Handle, m_Object, Index, Value, ScanSymLink); + }); + } - class enum_stream: public enumerator + namespace detail { - IMPLEMENTS_ENUMERATOR(enum_stream); - - public: - NONCOPYABLE(enum_stream); - TRIVIALLY_MOVABLE(enum_stream); - - enum_stream(const string& Object): m_Object(Object) {} - - private: - bool get(size_t index, value_type& value) const; - - string m_Object; - mutable find_file_handle m_Handle; - }; + bool get_name_impl(find_handle&, const string&, size_t, string&); + } - class enum_volume: public enumerator + inline auto enum_names(const string& Object) { - IMPLEMENTS_ENUMERATOR(enum_volume); + using value_type = string; + find_handle Handle; + return make_inline_enumerator([=, m_Handle = std::move(Handle)](size_t Index, value_type& Value) mutable + { + return detail::get_name_impl(m_Handle, Object, Index, Value); + }); + } - public: - NONCOPYABLE(enum_volume); - TRIVIALLY_MOVABLE(enum_volume); + namespace detail + { + bool get_stream_impl(find_file_handle&, const string&, size_t, WIN32_FIND_STREAM_DATA&); + } - enum_volume() {}; + inline auto enum_streams(const string& Object) + { + using value_type = WIN32_FIND_STREAM_DATA; + find_file_handle Handle; + return make_inline_enumerator([=, m_Handle = std::move(Handle)](size_t Index, value_type& Value) mutable + { + return detail::get_stream_impl(m_Handle, Object, Index, Value); + }); + } - private: - bool get(size_t index, value_type& value) const; + namespace detail + { + bool get_volume_impl(find_volume_handle&, size_t, string&); + } - mutable find_volume_handle m_Handle; - }; + inline auto enum_volumes() + { + using value_type = string; + find_volume_handle Handle; + return make_inline_enumerator([m_Handle = std::move(Handle)](size_t Index, value_type& Value) mutable + { + return detail::get_volume_impl(m_Handle, Index, Value); + }); + } class file: public conditional { diff --git a/far/filelist.cpp b/far/filelist.cpp index 3813b55227..b3251ec575 100644 --- a/far/filelist.cpp +++ b/far/filelist.cpp @@ -1974,7 +1974,7 @@ int FileList::ProcessKey(const Manager::Key& Key) strPath = strTempName; CutToSlash(strPath, false); strFindName = strPath+L"*"; - os::fs::enum_file Find(strFindName); + const auto Find = os::fs::enum_files(strFindName); const auto ItemIterator = std::find_if(CONST_RANGE(Find, i) { return !(i.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); }); if (ItemIterator != Find.cend()) strTempName = strPath + ItemIterator->strFileName; @@ -6700,7 +6700,7 @@ void FileList::ReadFileNames(int KeepSelection, int UpdateEvenIfPanelInvisible, string strFind(m_CurDir); AddEndSlash(strFind); strFind+=L'*'; - os::fs::enum_file Find(strFind, true); + const auto Find = os::fs::enum_files(strFind, true); DWORD FindErrorCode = ERROR_SUCCESS; bool UseFilter=m_Filter->IsEnabledOnPanel(); diff --git a/far/filesystemwatcher.cpp b/far/filesystemwatcher.cpp index 4a7601a7da..72df425c5c 100644 --- a/far/filesystemwatcher.cpp +++ b/far/filesystemwatcher.cpp @@ -43,10 +43,10 @@ FileSystemWatcher::FileSystemWatcher(): m_CurrentLastWriteTime(), m_bOpen(false), m_WatchSubtree(false), - m_WatchRegistered(Event::manual, Event::signaled), - m_Done(Event::manual, Event::nonsignaled), - m_DoneDone(Event::manual, Event::nonsignaled), - m_Changed(Event::manual, Event::nonsignaled) + m_WatchRegistered(os::event::type::manual, os::event::state::signaled), + m_Done(os::event::type::manual, os::event::state::nonsignaled), + m_DoneDone(os::event::type::manual, os::event::state::nonsignaled), + m_Changed(os::event::type::manual, os::event::state::nonsignaled) { } @@ -58,7 +58,7 @@ FileSystemWatcher::~FileSystemWatcher() void FileSystemWatcher::Set(const string& Directory, bool WatchSubtree) { - m_WatchRegistered.Wait(); + m_WatchRegistered.wait(); m_Directory = Directory; m_WatchSubtree = WatchSubtree; @@ -74,18 +74,18 @@ void FileSystemWatcher::WatchRegister() const FILE_NOTIFY_CHANGE_ATTRIBUTES| FILE_NOTIFY_CHANGE_SIZE| FILE_NOTIFY_CHANGE_LAST_WRITE)); - m_WatchRegistered.Set(); + m_WatchRegistered.set(); - MultiWaiter waiter; - waiter.Add(Handle.native_handle()); - waiter.Add(m_Done); - if (waiter.Wait(MultiWaiter::wait_any) == WAIT_OBJECT_0) + os::multi_waiter waiter; + waiter.add(Handle.native_handle()); + waiter.add(m_Done); + if (waiter.wait(os::multi_waiter::mode::any) == WAIT_OBJECT_0) { - m_Changed.Set(); - m_Done.Wait(); + m_Changed.set(); + m_Done.wait(); } - m_DoneDone.Set(); + m_DoneDone.set(); } void FileSystemWatcher::Watch(bool got_focus, bool check_time) @@ -95,10 +95,10 @@ void FileSystemWatcher::Watch(bool got_focus, bool check_time) if(!m_bOpen) { m_bOpen = true; - m_Done.Reset(); - m_DoneDone.Reset(); - m_WatchRegistered.Reset(); - Thread(&Thread::detach, &FileSystemWatcher::WatchRegister, this); + m_Done.reset(); + m_DoneDone.reset(); + m_WatchRegistered.reset(); + os::thread(&os::thread::detach, &FileSystemWatcher::WatchRegister, this); } if (got_focus) @@ -134,15 +134,15 @@ void FileSystemWatcher::Release() { if (m_bOpen) { - m_Done.Set(); - m_DoneDone.Wait(); + m_Done.set(); + m_DoneDone.wait(); m_bOpen = false; - m_Changed.Reset(); + m_Changed.reset(); } m_PreviousLastWriteTime = m_CurrentLastWriteTime; } bool FileSystemWatcher::Signaled() const { - return m_Changed.Signaled() || m_PreviousLastWriteTime != m_CurrentLastWriteTime; + return m_Changed.is_signaled() || m_PreviousLastWriteTime != m_CurrentLastWriteTime; } diff --git a/far/filesystemwatcher.hpp b/far/filesystemwatcher.hpp index 029018b550..c1207420d5 100644 --- a/far/filesystemwatcher.hpp +++ b/far/filesystemwatcher.hpp @@ -54,10 +54,10 @@ class FileSystemWatcher: noncopyable FILETIME m_CurrentLastWriteTime; bool m_bOpen; bool m_WatchSubtree; - Event m_WatchRegistered; - Event m_Done; - Event m_DoneDone; - Event m_Changed; + os::event m_WatchRegistered; + os::event m_Done; + os::event m_DoneDone; + os::event m_Changed; }; #endif // FILESYSTEMWATCHER_HPP_A4DC2834_A694_4E86_B8BA_FDA8DBF728CD diff --git a/far/findfile.cpp b/far/findfile.cpp index 5d9723b6f2..f027bc92cd 100644 --- a/far/findfile.cpp +++ b/far/findfile.cpp @@ -93,7 +93,7 @@ struct FindListItem class InterThreadData { private: - mutable CriticalSection DataCS; + mutable os::critical_section DataCS; FindFiles::ArcListItem* FindFileArcItem; int Percent; @@ -107,7 +107,7 @@ class InterThreadData void Init() { - SCOPED_ACTION(CriticalSectionLock)(DataCS); + SCOPED_ACTION(os::critical_section_lock)(DataCS); FindFileArcItem = nullptr; Percent=0; FindList.clear(); @@ -118,13 +118,13 @@ class InterThreadData FindFiles::ArcListItem* GetFindFileArcItem() const { - SCOPED_ACTION(CriticalSectionLock)(DataCS); + SCOPED_ACTION(os::critical_section_lock)(DataCS); return FindFileArcItem; } void SetFindFileArcItem(FindFiles::ArcListItem* Value) { - SCOPED_ACTION(CriticalSectionLock)(DataCS); + SCOPED_ACTION(os::critical_section_lock)(DataCS); FindFileArcItem = Value; } @@ -132,31 +132,31 @@ class InterThreadData void SetPercent(int Value) { - SCOPED_ACTION(CriticalSectionLock)(DataCS); + SCOPED_ACTION(os::critical_section_lock)(DataCS); Percent = Value; } size_t GetFindListCount() const { - SCOPED_ACTION(CriticalSectionLock)(DataCS); + SCOPED_ACTION(os::critical_section_lock)(DataCS); return FindList.size(); } void GetFindMessage(string& To) const { - SCOPED_ACTION(CriticalSectionLock)(DataCS); + SCOPED_ACTION(os::critical_section_lock)(DataCS); To=strFindMessage; } void SetFindMessage(const string& From) { - SCOPED_ACTION(CriticalSectionLock)(DataCS); + SCOPED_ACTION(os::critical_section_lock)(DataCS); strFindMessage=From; } void ClearAllLists() { - SCOPED_ACTION(CriticalSectionLock)(DataCS); + SCOPED_ACTION(os::critical_section_lock)(DataCS); FindFileArcItem = nullptr; if (!FindList.empty()) @@ -181,7 +181,7 @@ class InterThreadData FindFiles::ArcListItem& AddArcListItem(const string& ArcName, plugin_panel* hPlugin, UINT64 dwFlags, const string& RootPath) { - SCOPED_ACTION(CriticalSectionLock)(DataCS); + SCOPED_ACTION(os::critical_section_lock)(DataCS); FindFiles::ArcListItem NewItem; NewItem.strArcName = ArcName; @@ -195,7 +195,7 @@ class InterThreadData FindListItem& AddFindListItem(const os::FAR_FIND_DATA& FindData, void* Data, FARPANELITEMFREECALLBACK FreeData) { - SCOPED_ACTION(CriticalSectionLock)(DataCS); + SCOPED_ACTION(os::critical_section_lock)(DataCS); FindListItem NewItem; NewItem.FindData = FindData; @@ -209,7 +209,7 @@ class InterThreadData template void ForEachFindItem(const Visitor& visitor) const { - SCOPED_ACTION(CriticalSectionLock)(DataCS); + SCOPED_ACTION(os::critical_section_lock)(DataCS); for (const auto& i: FindList) visitor(i); } @@ -217,7 +217,7 @@ class InterThreadData template void ForEachFindItem(const Visitor& visitor) { - SCOPED_ACTION(CriticalSectionLock)(DataCS); + SCOPED_ACTION(os::critical_section_lock)(DataCS); for (auto& i: FindList) visitor(i); } @@ -524,14 +524,14 @@ void FindFiles::SetPluginDirectory(const string& DirName, plugin_panel* hPlugin, size_t FileCount=0; PluginPanelItem *PanelData=nullptr; - SCOPED_ACTION(CriticalSectionLock)(PluginCS); + SCOPED_ACTION(os::critical_section_lock)(PluginCS); if (Global->CtrlObject->Plugins->GetFindData(hPlugin,&PanelData,&FileCount,OPM_SILENT)) Global->CtrlObject->Plugins->FreeFindData(hPlugin,PanelData,FileCount,true); } DeleteEndSlash(Dir); - SCOPED_ACTION(CriticalSectionLock)(PluginCS); + SCOPED_ACTION(os::critical_section_lock)(PluginCS); Global->CtrlObject->Plugins->SetDirectory(hPlugin, Dir.empty()? L"\\" : Dir.data(), OPM_SILENT, Dir.empty()? nullptr : UserData); } @@ -751,7 +751,7 @@ intptr_t FindFiles::MainDlgProc(Dialog* Dlg, intptr_t Msg, intptr_t Param1, void } case DN_CONTROLINPUT: { - const INPUT_RECORD* record=(const INPUT_RECORD *)Param2; + const auto record = static_cast(Param2); if (record->EventType!=KEY_EVENT) break; int key = InputRecordToKey(record); switch (Param1) @@ -883,7 +883,7 @@ intptr_t FindFiles::MainDlgProc(Dialog* Dlg, intptr_t Msg, intptr_t Param1, void bool FindFiles::GetPluginFile(ArcListItem* ArcItem, const os::FAR_FIND_DATA& FindData, const string& DestPath, string &strResultName, UserDataItem *UserData) { - SCOPED_ACTION(CriticalSectionLock)(PluginCS); + SCOPED_ACTION(os::critical_section_lock)(PluginCS); _ALGO(CleverSysLog clv(L"FindFiles::GetPluginFile()")); OpenPanelInfo Info; @@ -952,9 +952,9 @@ int background_searcher::FindStringBMH(const wchar_t* searchBuffer, size_t searc }); } -int background_searcher::FindStringBMH(const unsigned char* searchBuffer, size_t searchBufferCount) const +int background_searcher::FindStringBMH(const char* searchBuffer, size_t searchBufferCount) const { - return FindStringBMH_Impl(searchBuffer, searchBufferCount, hexFindString.size(), skipCharsTable, [&](const unsigned char* Buffer, size_t index) + return FindStringBMH_Impl(searchBuffer, searchBufferCount, hexFindString.size(), skipCharsTable, [&](const char* Buffer, size_t index) { return Buffer[index] == hexFindString[index]; }); @@ -1029,7 +1029,7 @@ bool background_searcher::LookForString(const string& Name) return false; // Ищем - if (FindStringBMH((unsigned char *)readBufferA.data(), readBlockSize)!=-1) + if (FindStringBMH(readBufferA.data(), readBlockSize) != -1) return true; } else @@ -1103,7 +1103,7 @@ bool background_searcher::LookForString(const string& Name) else { // Если поиск в UTF-16 (little endian), то используем исходный буфер - buffer = (wchar_t *)readBufferA.data(); + buffer = reinterpret_cast(readBufferA.data()); } } else @@ -1427,7 +1427,7 @@ intptr_t FindFiles::FindDlgProc(Dialog* Dlg, intptr_t Msg, intptr_t Param1, void case DN_CONTROLINPUT: { - const INPUT_RECORD* record=(const INPUT_RECORD *)Param2; + const auto record = static_cast(Param2); if (record->EventType!=KEY_EVENT) break; int key = InputRecordToKey(record); switch (key) @@ -1591,7 +1591,7 @@ intptr_t FindFiles::FindDlgProc(Dialog* Dlg, intptr_t Msg, intptr_t Param1, void int SavePluginsOutput=Global->DisablePluginsOutput; Global->DisablePluginsOutput=TRUE; { - SCOPED_ACTION(CriticalSectionLock)(PluginCS); + SCOPED_ACTION(os::critical_section_lock)(PluginCS); FindItem->Arc->hPlugin = Global->CtrlObject->Plugins->OpenFilePlugin(&strFindArcName, OPM_NONE, OFP_SEARCH); } Global->DisablePluginsOutput=SavePluginsOutput; @@ -1615,7 +1615,7 @@ intptr_t FindFiles::FindDlgProc(Dialog* Dlg, intptr_t Msg, intptr_t Param1, void if (ClosePanel) { - SCOPED_ACTION(CriticalSectionLock)(PluginCS); + SCOPED_ACTION(os::critical_section_lock)(PluginCS); Global->CtrlObject->Plugins->ClosePanel(FindItem->Arc->hPlugin); FindItem->Arc->hPlugin = nullptr; } @@ -1625,7 +1625,7 @@ intptr_t FindFiles::FindDlgProc(Dialog* Dlg, intptr_t Msg, intptr_t Param1, void { if (ClosePanel) { - SCOPED_ACTION(CriticalSectionLock)(PluginCS); + SCOPED_ACTION(os::critical_section_lock)(PluginCS); Global->CtrlObject->Plugins->ClosePanel(FindItem->Arc->hPlugin); FindItem->Arc->hPlugin = nullptr; } @@ -2225,7 +2225,7 @@ void background_searcher::DoScanTree(const string& strRoot) os::find_file_handle FindStream; Sleep(0); - PauseEvent.Wait(); + PauseEvent.wait(); bool bContinue=false; WIN32_FIND_STREAM_DATA sd; @@ -2368,7 +2368,7 @@ void background_searcher::ScanPluginTree(plugin_panel* hPlugin, UINT64 Flags, in for (size_t I=0; IFileName); @@ -2487,7 +2487,7 @@ void background_searcher::DoPrepareFileList() } }); - for (const auto& VolumeName: os::fs::enum_volume()) + for (const auto& VolumeName: os::fs::enum_volumes()) { int DriveType=FAR_GetDriveType(VolumeName); @@ -2578,7 +2578,7 @@ void background_searcher::Search() void background_searcher::Stop() const { - StopEvent.Set(); + StopEvent.set(); } bool FindFiles::FindFilesProcess() @@ -2683,7 +2683,7 @@ bool FindFiles::FindFilesProcess() Dlg->InitDialog(); Dlg->Show(); - Thread FindThread(&Thread::join, &background_searcher::Search, &BC); + os::thread FindThread(&os::thread::join, &background_searcher::Search, &BC); Dlg->Process(); // BUGBUG @@ -2741,7 +2741,7 @@ bool FindFiles::FindFilesProcess() } }); - SCOPED_ACTION(CriticalSectionLock)(PluginCS); + SCOPED_ACTION(os::critical_section_lock)(PluginCS); { if (const auto hNewPlugin = Global->CtrlObject->Plugins->OpenFindListPlugin(PanelItems.data(), PanelItems.size())) { @@ -2787,7 +2787,7 @@ bool FindFiles::FindFilesProcess() { OpenPanelInfo Info; { - SCOPED_ACTION(CriticalSectionLock)(PluginCS); + SCOPED_ACTION(os::critical_section_lock)(PluginCS); Global->CtrlObject->Plugins->GetOpenPanelInfo(FindExitItem->Arc->hPlugin, &Info); if (SearchMode == FINDAREA_ROOT || @@ -2916,7 +2916,7 @@ FindFiles::FindFiles(): Filter(std::make_unique(Global->CtrlObject->Cp()->ActivePanel().get(), FFT_FINDFILE)), itd(std::make_unique()), m_TimeCheck(time_check::mode::immediate, GetRedrawTimeout()), - m_MessageEvent(Event::manual, Event::signaled) + m_MessageEvent(os::event::type::manual, os::event::state::signaled) { _ALGO(CleverSysLog clv(L"FindFiles::FindFiles()")); @@ -3174,7 +3174,7 @@ background_searcher::background_searcher( NotContaining(NotContaining), UseFilter(UseFilter), m_PluginMode(PluginMode), - PauseEvent(Event::manual, Event::signaled), - StopEvent(Event::manual, Event::nonsignaled) + PauseEvent(os::event::type::manual, os::event::state::signaled), + StopEvent(os::event::type::manual, os::event::state::nonsignaled) { } diff --git a/far/findfile.hpp b/far/findfile.hpp index 4e02ab4658..045b9ccffc 100644 --- a/far/findfile.hpp +++ b/far/findfile.hpp @@ -158,7 +158,7 @@ class FindFiles: noncopyable public: std::unique_ptr itd; - SyncedQueue m_Messages; + os::synced_queue m_Messages; // BUGBUG void Lock() { PluginCS.lock(); } @@ -166,7 +166,7 @@ class FindFiles: noncopyable auto ScopedLock() { return make_raii_wrapper(this, &FindFiles::Lock, &FindFiles::Unlock); } private: - CriticalSection PluginCS; + os::critical_section PluginCS; time_check m_TimeCheck; // BUGBUG @@ -176,7 +176,7 @@ class FindFiles: noncopyable string m_LastDirName; Dialog* m_ResultsDialogPtr; bool m_EmptyArc; - Event m_MessageEvent; + os::event m_MessageEvent; }; class background_searcher: noncopyable @@ -197,10 +197,10 @@ class background_searcher: noncopyable ); void Search(); - void Pause() const { PauseEvent.Reset(); } - void Resume() const { PauseEvent.Set(); } + void Pause() const { PauseEvent.reset(); } + void Resume() const { PauseEvent.set(); } void Stop() const; - bool Stopped() const { return StopEvent.Signaled(); } + bool Stopped() const { return StopEvent.is_signaled(); } auto ExceptionPtr() const { return m_ExceptionPtr; } @@ -210,7 +210,7 @@ class background_searcher: noncopyable void ReleaseInFileSearch(); int FindStringBMH(const wchar_t* searchBuffer, size_t searchBufferCount) const; - int FindStringBMH(const unsigned char* searchBuffer, size_t searchBufferCount) const; + int FindStringBMH(const char* searchBuffer, size_t searchBufferCount) const; bool LookForString(const string& Name); bool IsFileIncluded(PluginPanelItem* FileItem, const string& FullName, DWORD FileAttr, const string &strDisplayName); void DoPrepareFileList(); @@ -249,8 +249,8 @@ class background_searcher: noncopyable const bool UseFilter; const bool m_PluginMode; - Event PauseEvent; - Event StopEvent; + os::event PauseEvent; + os::event StopEvent; std::exception_ptr m_ExceptionPtr; }; diff --git a/far/flink.cpp b/far/flink.cpp index c7f9047383..defe6cc1f5 100644 --- a/far/flink.cpp +++ b/far/flink.cpp @@ -350,7 +350,7 @@ bool EnumStreams(const string& FileName,UINT64 &StreamsSize,DWORD &StreamsCount) UINT64 Size = 0; DWORD Count = 0; - for (const auto& i: os::fs::enum_stream(FileName)) + for (const auto& i: os::fs::enum_streams(FileName)) { ++Count; Size += i.StreamSize.QuadPart; diff --git a/far/hmenu.cpp b/far/hmenu.cpp index c9fbdee505..8bed7ffefa 100644 --- a/far/hmenu.cpp +++ b/far/hmenu.cpp @@ -471,7 +471,7 @@ void HMenu::ResizeConsole() wchar_t HMenu::GetHighlights(const HMenuData& MenuItem) { - SCOPED_ACTION(CriticalSectionLock)(CS); + SCOPED_ACTION(os::critical_section_lock)(CS); wchar_t Ch=0; const wchar_t *Name = MenuItem.Name; @@ -489,7 +489,7 @@ wchar_t HMenu::GetHighlights(const HMenuData& MenuItem) size_t HMenu::CheckHighlights(WORD CheckSymbol, int StartPos) { - SCOPED_ACTION(CriticalSectionLock)(CS); + SCOPED_ACTION(os::critical_section_lock)(CS); if (StartPos < 0) StartPos=0; diff --git a/far/hmenu.hpp b/far/hmenu.hpp index 7919d608e8..cf51f19715 100644 --- a/far/hmenu.hpp +++ b/far/hmenu.hpp @@ -85,7 +85,7 @@ class HMenu: public SimpleModal range Item; size_t SelectPos; int m_VExitCode; - CriticalSection CS; + os::critical_section CS; bool m_SubmenuOpened; }; diff --git a/far/interf.cpp b/far/interf.cpp index f9a2b34671..ab3a4d12a4 100644 --- a/far/interf.cpp +++ b/far/interf.cpp @@ -148,16 +148,16 @@ DWORD InitialConsoleMode=0; SMALL_RECT InitWindowRect; COORD InitialSize; -static Event& CancelIoInProgress() +static os::event& CancelIoInProgress() { - static Event s_CancelIoInProgress; + static os::event s_CancelIoInProgress; return s_CancelIoInProgress; } unsigned int CancelSynchronousIoWrapper(void* Thread) { unsigned int Result = Imports().CancelSynchronousIo(Thread); - CancelIoInProgress().Reset(); + CancelIoInProgress().reset(); return Result; } @@ -169,10 +169,10 @@ BOOL WINAPI CtrlHandler(DWORD CtrlType) return TRUE; case CTRL_BREAK_EVENT: - if(!CancelIoInProgress().Signaled()) + if(!CancelIoInProgress().is_signaled()) { - CancelIoInProgress().Set(); - Thread(&Thread::detach, &CancelSynchronousIoWrapper, Global->MainThreadHandle()); + CancelIoInProgress().set(); + os::thread(&os::thread::detach, &CancelSynchronousIoWrapper, Global->MainThreadHandle()); } WriteInput(KEY_BREAK); @@ -292,7 +292,7 @@ void InitConsole(int FirstInit) if (FirstInit) { - CancelIoInProgress() = Event(Event::manual, Event::nonsignaled); + CancelIoInProgress() = os::event(os::event::type::manual, os::event::state::nonsignaled); DWORD Mode; if(!Console().GetMode(Console().GetInputHandle(), Mode)) @@ -390,7 +390,7 @@ void CloseConsole() ClearKeyQueue(); ConsoleIcons().restorePreviousIcons(); - CancelIoInProgress().Close(); + CancelIoInProgress().close(); } diff --git a/far/language.cpp b/far/language.cpp index 23c31ec163..e3961d8662 100644 --- a/far/language.cpp +++ b/far/language.cpp @@ -56,7 +56,7 @@ bool OpenLangFile(os::fs::file& LangFile, const string& Path,const string& Mask, auto PathWithSlash = Path; AddEndSlash(PathWithSlash); - for (const auto& FindData: os::fs::enum_file(PathWithSlash + Mask)) + for (const auto& FindData: os::fs::enum_files(PathWithSlash + Mask)) { strFileName = PathWithSlash + FindData.strFileName; @@ -184,7 +184,7 @@ static bool SelectLanguage(bool HelpLanguage) auto PathWithSlash = Global->g_strFarPath; AddEndSlash(PathWithSlash); - for (const auto& FindData: os::fs::enum_file(PathWithSlash + Mask)) + for (const auto& FindData: os::fs::enum_files(PathWithSlash + Mask)) { os::fs::file LangFile(PathWithSlash + FindData.strFileName, FILE_READ_DATA, FILE_SHARE_READ, nullptr, OPEN_EXISTING); if (!LangFile) diff --git a/far/mix.cpp b/far/mix.cpp index bb14041f43..439bc53fe4 100644 --- a/far/mix.cpp +++ b/far/mix.cpp @@ -80,8 +80,8 @@ bool FarMkTempEx(string &strDest, const wchar_t *Prefix, BOOL WithTempPath, cons if (GetTempFileName(strPath.data(), Prefix, uniq, Buffer.get())) { - os::fs::enum_file f(Buffer.get(), false); - if (f.begin() == f.end()) + const auto Find = os::fs::enum_files(Buffer.get(), false); + if (Find.begin() == Find.end()) break; } diff --git a/far/notification.cpp b/far/notification.cpp index 63964dc738..5ed17c6401 100644 --- a/far/notification.cpp +++ b/far/notification.cpp @@ -54,19 +54,19 @@ message_manager::message_manager(): message_manager::handlers_map::iterator message_manager::subscribe(event_id EventId, const detail::i_event_handler& EventHandler) { - SCOPED_ACTION(CriticalSectionLock)(m_QueueCS); + SCOPED_ACTION(os::critical_section_lock)(m_QueueCS); return m_Handlers.emplace(EventNames[EventId], &EventHandler); } message_manager::handlers_map::iterator message_manager::subscribe(const string& EventName, const detail::i_event_handler& EventHandler) { - SCOPED_ACTION(CriticalSectionLock)(m_QueueCS); + SCOPED_ACTION(os::critical_section_lock)(m_QueueCS); return m_Handlers.emplace(EventName, &EventHandler); } void message_manager::unsubscribe(handlers_map::iterator HandlerIterator) { - SCOPED_ACTION(CriticalSectionLock)(m_QueueCS); + SCOPED_ACTION(os::critical_section_lock)(m_QueueCS); m_Handlers.erase(HandlerIterator); } @@ -86,7 +86,7 @@ bool message_manager::dispatch() message_queue::value_type EventData; while (m_Messages.try_pop(EventData)) { - SCOPED_ACTION(CriticalSectionLock)(m_QueueCS); + SCOPED_ACTION(os::critical_section_lock)(m_QueueCS); const auto RelevantListeners = m_Handlers.equal_range(EventData.first); std::for_each(RelevantListeners.first, RelevantListeners.second, [&](const handlers_map::value_type& i) { diff --git a/far/notification.hpp b/far/notification.hpp index 61b50dcdb8..10342d88ca 100644 --- a/far/notification.hpp +++ b/far/notification.hpp @@ -122,11 +122,11 @@ class message_manager: noncopyable private: friend message_manager& MessageManager(); - using message_queue = SyncedQueue>; + using message_queue = os::synced_queue>; message_manager(); - CriticalSection m_QueueCS; + os::critical_section m_QueueCS; message_queue m_Messages; handlers_map m_Handlers; std::unique_ptr m_Window; diff --git a/far/plugins.cpp b/far/plugins.cpp index f642ec06c7..9042d4cb36 100644 --- a/far/plugins.cpp +++ b/far/plugins.cpp @@ -962,7 +962,7 @@ int PluginManager::GetFile(const plugin_panel* hPlugin, PluginPanelItem *PanelIt string strFindPath = Info.DestPath; AddEndSlash(strFindPath); strFindPath += L"*"; - os::fs::enum_file Find(strFindPath); + const auto Find = os::fs::enum_files(strFindPath); const auto ItemIterator = std::find_if(CONST_RANGE(Find, i) { return !(i.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); }); if (ItemIterator != Find.cend()) { diff --git a/far/qview.hpp b/far/qview.hpp index 782df5a3e0..9daddda8d5 100644 --- a/far/qview.hpp +++ b/far/qview.hpp @@ -73,7 +73,7 @@ class QuickView:public Panel string strCurFileName; string strCurFileType; - CriticalSection CS; + os::critical_section CS; int Directory; DirInfoData Data; diff --git a/far/scantree.cpp b/far/scantree.cpp index 9e93462026..3f556c1bed 100644 --- a/far/scantree.cpp +++ b/far/scantree.cpp @@ -50,8 +50,9 @@ struct ScanTree::scantree_item scantree_item() = default; BitFlags Flags; - std::unique_ptr Find; - os::fs::enum_file::iterator Iterator; + using enum_files_type = FN_RETURN_TYPE(os::fs::enum_files); + std::unique_ptr Find; + enum_files_type::iterator Iterator; string RealPath; std::unordered_set ActiveDirectories; }; @@ -116,7 +117,7 @@ bool ScanTree::GetNextName(os::FAR_FIND_DATA& fdata,string &strFullName) { if (!LastItem.Find) { - LastItem.Find = std::make_unique(strFindPath); + LastItem.Find = std::make_unique(std::move(os::fs::enum_files(strFindPath))); LastItem.Iterator = LastItem.Find->end(); } diff --git a/far/scrbuf.cpp b/far/scrbuf.cpp index da1391228c..99c49d0edb 100644 --- a/far/scrbuf.cpp +++ b/far/scrbuf.cpp @@ -91,7 +91,7 @@ void ScreenBuf::DebugDump() const void ScreenBuf::AllocBuf(size_t rows, size_t cols) { - SCOPED_ACTION(CriticalSectionLock)(CS); + SCOPED_ACTION(os::critical_section_lock)(CS); if (rows == Buf.height() && cols == Buf.width()) return; @@ -104,7 +104,7 @@ void ScreenBuf::AllocBuf(size_t rows, size_t cols) */ void ScreenBuf::FillBuf() { - SCOPED_ACTION(CriticalSectionLock)(CS); + SCOPED_ACTION(os::critical_section_lock)(CS); SMALL_RECT ReadRegion={0, 0, static_cast(Buf.width() - 1), static_cast(Buf.height() - 1)}; Console().ReadOutput(Buf, ReadRegion); @@ -119,7 +119,7 @@ void ScreenBuf::FillBuf() */ void ScreenBuf::Write(int X,int Y,const FAR_CHAR_INFO *Text, size_t Size) { - SCOPED_ACTION(CriticalSectionLock)(CS); + SCOPED_ACTION(os::critical_section_lock)(CS); if (X<0) { @@ -157,7 +157,7 @@ void ScreenBuf::Write(int X,int Y,const FAR_CHAR_INFO *Text, size_t Size) */ void ScreenBuf::Read(int X1, int Y1, int X2, int Y2, matrix& Dest) { - SCOPED_ACTION(CriticalSectionLock)(CS); + SCOPED_ACTION(os::critical_section_lock)(CS); fix_coordinates(X1, Y1, X2, Y2); @@ -176,7 +176,7 @@ void ScreenBuf::ApplyShadow(int X1,int Y1,int X2,int Y2) if (!is_visible(X1, Y1, X2, Y2)) return; - SCOPED_ACTION(CriticalSectionLock)(CS); + SCOPED_ACTION(os::critical_section_lock)(CS); fix_coordinates(X1, Y1, X2, Y2); @@ -220,7 +220,7 @@ void ScreenBuf::ApplyColor(int X1,int Y1,int X2,int Y2,const FarColor& Color, bo if (!is_visible(X1, Y1, X2, Y2)) return; - SCOPED_ACTION(CriticalSectionLock)(CS); + SCOPED_ACTION(os::critical_section_lock)(CS); fix_coordinates(X1, Y1, X2, Y2); @@ -257,7 +257,7 @@ void ScreenBuf::ApplyColor(int X1,int Y1,int X2,int Y2,const FarColor& Color,con if (!is_visible(X1, Y1, X2, Y2)) return; - SCOPED_ACTION(CriticalSectionLock)(CS); + SCOPED_ACTION(os::critical_section_lock)(CS); fix_coordinates(X1, Y1, X2, Y2); @@ -288,7 +288,7 @@ void ScreenBuf::FillRect(int X1,int Y1,int X2,int Y2,WCHAR Ch,const FarColor& Co if (!is_visible(X1, Y1, X2, Y2)) return; - SCOPED_ACTION(CriticalSectionLock)(CS); + SCOPED_ACTION(os::critical_section_lock)(CS); FAR_CHAR_INFO CI; CI.Attributes=Color; @@ -315,7 +315,7 @@ void ScreenBuf::FillRect(int X1,int Y1,int X2,int Y2,WCHAR Ch,const FarColor& Co */ void ScreenBuf::Flush(flush_type FlushType) { - SCOPED_ACTION(CriticalSectionLock)(CS); + SCOPED_ACTION(os::critical_section_lock)(CS); if (!LockCount) { @@ -537,7 +537,7 @@ void ScreenBuf::SetLockCount(int Count) void ScreenBuf::MoveCursor(int X,int Y) { - SCOPED_ACTION(CriticalSectionLock)(CS); + SCOPED_ACTION(os::critical_section_lock)(CS); if (!is_visible(CurX, CurY, CurX, CurY)) { @@ -611,7 +611,7 @@ void ScreenBuf::RestoreElevationChar() // проскроллировать буфер на одну строку вверх. void ScreenBuf::Scroll(size_t Count) { - SCOPED_ACTION(CriticalSectionLock)(CS); + SCOPED_ACTION(os::critical_section_lock)(CS); const FAR_CHAR_INFO Fill{ L' ', colors::PaletteColorToFarColor(COL_COMMANDLINEUSERSCREEN) }; diff --git a/far/scrbuf.hpp b/far/scrbuf.hpp index 9404afd880..2d397474d0 100644 --- a/far/scrbuf.hpp +++ b/far/scrbuf.hpp @@ -93,7 +93,7 @@ class ScreenBuf: noncopyable void Flush(flush_type FlushType = flush_type::all); private: - CriticalSection CS; + os::critical_section CS; FAR_CHAR_INFO MacroChar; FAR_CHAR_INFO ElevationChar; matrix Buf; diff --git a/far/setattr.cpp b/far/setattr.cpp index 67cfb13ae0..79ae0a1a16 100644 --- a/far/setattr.cpp +++ b/far/setattr.cpp @@ -1016,7 +1016,7 @@ bool ShellSetFileAttributes(Panel *SrcPanel, const string* Object) DeleteEndSlash(strRoot); Links.reserve(NameList.ItemsNumber); - for (const auto& i: os::fs::enum_name(strSelName)) + for (const auto& i: os::fs::enum_names(strSelName)) { Links.emplace_back(strRoot + i); } diff --git a/far/sqlitedb.cpp b/far/sqlitedb.cpp index 25c19667bc..0a7634af11 100644 --- a/far/sqlitedb.cpp +++ b/far/sqlitedb.cpp @@ -280,8 +280,8 @@ bool SQLiteDb::Open(const string& DbFile, bool Local, bool WAL) void SQLiteDb::Initialize(const string& DbName, bool Local) { - Mutex m(make_name(Local? Global->Opt->LocalProfilePath : Global->Opt->ProfilePath, DbName).data()); - SCOPED_ACTION(std::lock_guard)(m); + os::mutex m(os::make_name(Local? Global->Opt->LocalProfilePath : Global->Opt->ProfilePath, DbName).data()); + SCOPED_ACTION(std::lock_guard)(m); m_Name = DbName; init_status = 0; diff --git a/far/synchro.hpp b/far/synchro.hpp index 53781fb282..c7a1c0d968 100644 --- a/far/synchro.hpp +++ b/far/synchro.hpp @@ -38,12 +38,17 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pathmix.hpp" #include "exception.hpp" -class CriticalSection: noncopyable +namespace os { +class critical_section +{ public: - CriticalSection() { InitializeCriticalSection(&m_object); } - ~CriticalSection() { DeleteCriticalSection(&m_object); } + NONCOPYABLE(critical_section); + TRIVIALLY_MOVABLE(critical_section); + + critical_section() { InitializeCriticalSection(&m_object); } + ~critical_section() { DeleteCriticalSection(&m_object); } void lock() { EnterCriticalSection(&m_object); } void unlock() { LeaveCriticalSection(&m_object); } @@ -52,49 +57,33 @@ class CriticalSection: noncopyable CRITICAL_SECTION m_object; }; -using CriticalSectionLock = std::lock_guard; +using critical_section_lock = std::lock_guard; template string make_name(const S& HashPart, const S& TextPart) { - auto Str = T::GetNamespace() + str(make_hash(HashPart)) + L"_" + TextPart; + auto Str = T::get_namespace() + str(make_hash(HashPart)) + L"_" + TextPart; ReplaceBackslashToSlash(Str); return Str; } -class waitable -{ -public: - NONCOPYABLE(waitable); - TRIVIALLY_MOVABLE(waitable); - - bool Wait(DWORD Milliseconds = INFINITE) const { return m_Handle.wait(Milliseconds); } - bool Signaled() const { return m_Handle.signaled(); } - void Close() { m_Handle.close(); } - auto native_handle() const { return m_Handle.native_handle(); } - -protected: - explicit waitable(HANDLE Handle = nullptr): m_Handle(Handle) {} - os::handle m_Handle; -}; - -class Thread: public waitable +class thread: public handle { public: - NONCOPYABLE(Thread); - TRIVIALLY_MOVABLE(Thread); + NONCOPYABLE(thread); + TRIVIALLY_MOVABLE(thread); - using mode = void (Thread::*)(); + using mode = void (thread::*)(); - Thread(): m_Mode(), m_ThreadId() {} + thread(): m_Mode(), m_ThreadId() {} template - Thread(mode Mode, callable&& Callable, args&&... Args): m_Mode(Mode) + thread(mode Mode, callable&& Callable, args&&... Args): m_Mode(Mode) { - Starter(std::bind(std::forward(Callable), std::forward(Args)...)); + starter(std::bind(std::forward(Callable), std::forward(Args)...)); } - ~Thread() + ~thread() { if (joinable()) { @@ -104,20 +93,20 @@ class Thread: public waitable unsigned int get_id() const { return m_ThreadId; } - bool joinable() const { return !!m_Handle; } + bool joinable() const { return *this != nullptr; } void detach() { check_joinable(); - m_Handle.close(); + close(); m_ThreadId = 0; } void join() { check_joinable(); - m_Handle.wait(); - m_Handle.close(); + wait(); + close(); m_ThreadId = 0; } @@ -129,11 +118,11 @@ class Thread: public waitable } template - void Starter(T&& f) + void starter(T&& f) { auto Param = std::make_unique(std::move(f)); - m_Handle.reset(reinterpret_cast(_beginthreadex(nullptr, 0, Wrapper, Param.get(), 0, &m_ThreadId))); - if (m_Handle) + reset(reinterpret_cast(_beginthreadex(nullptr, 0, wrapper, Param.get(), 0, &m_ThreadId))); + if (*this) { Param.release(); } @@ -144,7 +133,7 @@ class Thread: public waitable } template - static unsigned int WINAPI Wrapper(void* RawPtr) + static unsigned int WINAPI wrapper(void* RawPtr) { std::invoke(*std::unique_ptr(reinterpret_cast(RawPtr))); return 0; @@ -154,84 +143,85 @@ class Thread: public waitable unsigned int m_ThreadId; }; -class Mutex: public waitable +class mutex: public handle { public: - NONCOPYABLE(Mutex); - TRIVIALLY_MOVABLE(Mutex); + NONCOPYABLE(mutex); + TRIVIALLY_MOVABLE(mutex); - Mutex(const wchar_t* Name = nullptr): waitable(CreateMutex(nullptr, false, EmptyToNull(Name))) {} + mutex(const wchar_t* Name = nullptr): os::handle(CreateMutex(nullptr, false, EmptyToNull(Name))) {} - static constexpr const wchar_t *GetNamespace() { return L"Far_Manager_Mutex_"; } + static constexpr auto get_namespace() { return L"Far_Manager_Mutex_"; } - bool lock() const { return m_Handle.wait(); } + bool lock() const { return wait(); } - bool unlock() const { return ReleaseMutex(m_Handle.native_handle()) != FALSE; } + bool unlock() const { return ReleaseMutex(native_handle()) != FALSE; } }; -class Event: public waitable +class event: public handle { public: - NONCOPYABLE(Event); - TRIVIALLY_MOVABLE(Event); + NONCOPYABLE(event); + TRIVIALLY_MOVABLE(event); - enum event_type { automatic, manual }; - enum event_state { nonsignaled, signaled }; + enum class type { automatic, manual }; + enum class state { nonsignaled, signaled }; - Event() = default; - Event(event_type Type, event_state InitialState, const wchar_t* Name = nullptr): waitable(CreateEvent(nullptr, Type == manual, InitialState == signaled, EmptyToNull(Name))) {} + event() = default; + event(type Type, state InitialState, const wchar_t* Name = nullptr): os::handle(CreateEvent(nullptr, Type == type::manual, InitialState == state::signaled, EmptyToNull(Name))) {} - static constexpr const wchar_t *GetNamespace() { return L"Far_Manager_Event_"; } + static constexpr auto get_namespace() { return L"Far_Manager_Event_"; } - bool Set() const { check_valid(); return SetEvent(m_Handle.native_handle()) != FALSE; } + bool set() const { check_valid(); return SetEvent(get()) != FALSE; } - bool Reset() const { check_valid(); return ResetEvent(m_Handle.native_handle()) != FALSE; } + bool reset() const { check_valid(); return ResetEvent(get()) != FALSE; } - void Associate(OVERLAPPED& o) const { check_valid(); o.hEvent = m_Handle.native_handle(); } + void associate(OVERLAPPED& o) const { check_valid(); o.hEvent = get(); } private: void check_valid() const { - if (!m_Handle) + if (!*this) { throw MAKE_FAR_EXCEPTION(L"Event not initialized properly"); } } }; -template class SyncedQueue: noncopyable +template +class synced_queue: noncopyable { public: using value_type = T; bool empty() const { - SCOPED_ACTION(CriticalSectionLock)(m_QueueCS); + SCOPED_ACTION(critical_section_lock)(m_QueueCS); return m_Queue.empty(); } void push(const T& item) { - SCOPED_ACTION(CriticalSectionLock)(m_QueueCS); + SCOPED_ACTION(critical_section_lock)(m_QueueCS); m_Queue.push(item); } template void emplace(args... Args) { - SCOPED_ACTION(CriticalSectionLock)(m_QueueCS); + SCOPED_ACTION(critical_section_lock)(m_QueueCS); m_Queue.emplace(std::forward(Args)...); } void push(T&& item) { - SCOPED_ACTION(CriticalSectionLock)(m_QueueCS); + SCOPED_ACTION(critical_section_lock)(m_QueueCS); m_Queue.push(std::forward(item)); } bool try_pop(T& To) { - SCOPED_ACTION(CriticalSectionLock)(m_QueueCS); + SCOPED_ACTION(critical_section_lock)(m_QueueCS); if (!m_Queue.empty()) { To = std::move(m_Queue.front()); @@ -243,44 +233,46 @@ template class SyncedQueue: noncopyable size_t size() const { - SCOPED_ACTION(CriticalSectionLock)(m_QueueCS); + SCOPED_ACTION(critical_section_lock)(m_QueueCS); return m_Queue.size(); } void clear() { - SCOPED_ACTION(CriticalSectionLock)(m_QueueCS); + SCOPED_ACTION(critical_section_lock)(m_QueueCS); clear_and_shrink(m_Queue); } - auto scoped_lock() { return make_raii_wrapper(this, &SyncedQueue::lock, &SyncedQueue::unlock); } + auto scoped_lock() { return make_raii_wrapper(this, &synced_queue::lock, &synced_queue::unlock); } private: void lock() { return m_QueueCS.lock(); } void unlock() { return m_QueueCS.unlock(); } std::queue m_Queue; - mutable CriticalSection m_QueueCS; + mutable critical_section m_QueueCS; }; -class MultiWaiter: noncopyable +class multi_waiter: noncopyable { public: - enum wait_mode + enum class mode { - wait_any, - wait_all + any, + all }; - MultiWaiter() { Objects.reserve(10); } + multi_waiter() { m_Objects.reserve(10); } template - MultiWaiter(T Begin, T End) { std::for_each(Begin, End, [this](const auto& i){ this->Add(i); }); } - void Add(const waitable& Object) { assert(Objects.size() < MAXIMUM_WAIT_OBJECTS); Objects.emplace_back(Object.native_handle()); } - void Add(HANDLE handle) { assert(Objects.size() < MAXIMUM_WAIT_OBJECTS); Objects.emplace_back(handle); } - DWORD Wait(wait_mode Mode = wait_all, DWORD Milliseconds = INFINITE) const { return WaitForMultipleObjects(static_cast(Objects.size()), Objects.data(), Mode == wait_all, Milliseconds); } - void Clear() {Objects.clear();} + multi_waiter(T Begin, T End) { std::for_each(Begin, End, [this](const auto& i){ this->add(i); }); } + void add(const os::handle& Object) { assert(m_Objects.size() < MAXIMUM_WAIT_OBJECTS); m_Objects.emplace_back(Object.native_handle()); } + void add(HANDLE handle) { assert(m_Objects.size() < MAXIMUM_WAIT_OBJECTS); m_Objects.emplace_back(handle); } + DWORD wait(mode Mode = mode::all, DWORD Milliseconds = INFINITE) const { return WaitForMultipleObjects(static_cast(m_Objects.size()), m_Objects.data(), Mode == mode::all, Milliseconds); } + void clear() {m_Objects.clear();} private: - std::vector Objects; + std::vector m_Objects; }; +} + #endif // SYNCHRO_HPP_ED4F0813_C518_409B_8576_F2E7CF4166CC diff --git a/far/tracer.cpp b/far/tracer.cpp index a07851654b..9a3796ef8a 100644 --- a/far/tracer.cpp +++ b/far/tracer.cpp @@ -143,7 +143,7 @@ tracer::~tracer() void tracer::store(const void* CppObject, const EXCEPTION_POINTERS* ExceptionInfo) { - SCOPED_ACTION(CriticalSectionLock)(m_CS); + SCOPED_ACTION(os::critical_section_lock)(m_CS); exception_context Context = { *ExceptionInfo->ExceptionRecord, *ExceptionInfo->ContextRecord }; if (m_CppMap.size() > 2048) { @@ -155,7 +155,7 @@ void tracer::store(const void* CppObject, const EXCEPTION_POINTERS* ExceptionInf bool tracer::get_context(const void* CppObject, exception_context& Context) const { - SCOPED_ACTION(CriticalSectionLock)(m_CS); + SCOPED_ACTION(os::critical_section_lock)(m_CS); auto Iter = m_CppMap.find(CppObject); if (Iter == m_CppMap.end()) { diff --git a/far/tracer.hpp b/far/tracer.hpp index 3135288a12..08c1213469 100644 --- a/far/tracer.hpp +++ b/far/tracer.hpp @@ -63,7 +63,7 @@ class tracer: noncopyable static void SymCleanup(); static tracer* sTracer; - mutable CriticalSection m_CS; + mutable os::critical_section m_CS; std::unordered_map m_CppMap; class veh_handler: noncopyable diff --git a/far/vbuild.m4 b/far/vbuild.m4 index 4a92913073..8230a5879a 100644 --- a/far/vbuild.m4 +++ b/far/vbuild.m4 @@ -1 +1 @@ -m4_define(BUILD,4898)m4_dnl +m4_define(BUILD,4899)m4_dnl diff --git a/far/wm_listener.cpp b/far/wm_listener.cpp index 282eaf2f8d..aece12a7cc 100644 --- a/far/wm_listener.cpp +++ b/far/wm_listener.cpp @@ -123,14 +123,14 @@ static LRESULT CALLBACK WndProc(HWND Hwnd, UINT Msg, WPARAM wParam, LPARAM lPara wm_listener::wm_listener(): m_Hwnd(nullptr), - m_exitEvent(Event::automatic, Event::nonsignaled) + m_exitEvent(os::event::type::automatic, os::event::state::nonsignaled) { Check(); } wm_listener::~wm_listener() { - m_exitEvent.Set(); + m_exitEvent.set(); if(m_Hwnd) { SendMessage(m_Hwnd,WM_CLOSE, 0, 0); @@ -139,16 +139,16 @@ wm_listener::~wm_listener() void wm_listener::Check() { - if (!m_Thread.joinable() || m_Thread.Signaled()) + if (!m_Thread.joinable() || m_Thread.is_signaled()) { RethrowIfNeeded(m_ExceptionPtr); - Event ReadyEvent(Event::automatic, Event::nonsignaled); - m_Thread = Thread(&Thread::join, &wm_listener::WindowThreadRoutine, this, &ReadyEvent); - ReadyEvent.Wait(); + os::event ReadyEvent(os::event::type::automatic, os::event::state::nonsignaled); + m_Thread = os::thread(&os::thread::join, &wm_listener::WindowThreadRoutine, this, &ReadyEvent); + ReadyEvent.wait(); } } -void wm_listener::WindowThreadRoutine(const Event* ReadyEvent) +void wm_listener::WindowThreadRoutine(const os::event* ReadyEvent) { WNDCLASSEX wc={sizeof(wc)}; wc.lpfnWndProc = WndProc; @@ -160,7 +160,7 @@ void wm_listener::WindowThreadRoutine(const Event* ReadyEvent) SCOPE_EXIT{ UnregisterClass(wc.lpszClassName, nullptr); }; m_Hwnd = CreateWindowEx(0, wc.lpszClassName, nullptr, 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, nullptr, nullptr, nullptr, nullptr); - ReadyEvent->Set(); + ReadyEvent->set(); if (!m_Hwnd) return; @@ -170,7 +170,7 @@ void wm_listener::WindowThreadRoutine(const Event* ReadyEvent) MSG Msg; WndProcExceptionPtr = &m_ExceptionPtr; - while(!m_exitEvent.Signaled() && !m_ExceptionPtr && GetMessage(&Msg, nullptr, 0, 0) > 0) + while(!m_exitEvent.is_signaled() && !m_ExceptionPtr && GetMessage(&Msg, nullptr, 0, 0) > 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); diff --git a/far/wm_listener.hpp b/far/wm_listener.hpp index 13962053f3..acb4db2e62 100644 --- a/far/wm_listener.hpp +++ b/far/wm_listener.hpp @@ -44,11 +44,11 @@ class wm_listener: noncopyable void Check(); private: - void WindowThreadRoutine(const Event* ReadyEvent); + void WindowThreadRoutine(const os::event* ReadyEvent); - Thread m_Thread; + os::thread m_Thread; HWND m_Hwnd; - Event m_exitEvent; + os::event m_exitEvent; std::exception_ptr m_ExceptionPtr; };