Skip to content

Commit

Permalink
refactoring, renamings
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Feb 18, 2017
1 parent 7680108 commit 534b103
Show file tree
Hide file tree
Showing 38 changed files with 367 additions and 386 deletions.
4 changes: 4 additions & 0 deletions 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
Expand Down
4 changes: 2 additions & 2 deletions far/common/enumerator.hpp
Expand Up @@ -91,7 +91,7 @@ class enumerator
enumerator() { TERSE_STATIC_ASSERT(std::is_base_of<enumerator, Derived>::value); }
};

#define IMPLEMENTS_ENUMERATOR(type) friend typename type::enumerator_type;
#define IMPLEMENTS_ENUMERATOR(type) friend typename type::enumerator_type

template<typename value_type, typename callable>
class inline_enumerator: public enumerator<inline_enumerator<value_type, callable>, value_type>
Expand All @@ -110,7 +110,7 @@ class inline_enumerator: public enumerator<inline_enumerator<value_type, callabl
return m_Callable(Index, Value);
}

callable m_Callable;
mutable callable m_Callable;
};

template<typename value_type, typename callable>
Expand Down
76 changes: 38 additions & 38 deletions far/configdb.cpp
Expand Up @@ -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<Event>(GetPath(), GetName()).data())
AsyncDone(os::event::type::manual, os::event::state::signaled, os::make_name<os::event>(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
Expand Down Expand Up @@ -706,7 +706,7 @@ class HierarchicalConfigDb: public HierarchicalConfig, public SQLiteDb
stmt_count
};

Event AsyncDone;
os::event AsyncDone;
};

static constexpr std::pair<FARCOLORFLAGS, const wchar_t*> ColorFlagNames[] =
Expand Down Expand Up @@ -1615,7 +1615,7 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb
virtual ~HistoryConfigCustom() override
{
WaitAllAsync();
StopEvent.Set();
StopEvent.set();
}

private:
Expand All @@ -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
{
Expand All @@ -1644,38 +1644,38 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb
string strData;
};

SyncedQueue<std::unique_ptr<AsyncWorkItem>> WorkQueue;
os::synced_queue<std::unique_ptr<AsyncWorkItem>> 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<Event>(GetPath(), GetName());
EventName = os::make_name<os::event>(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;
Expand Down Expand Up @@ -1704,9 +1704,9 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb
}
}
if (bAddDelete)
AsyncDeleteAddDone.Set();
AsyncDeleteAddDone.set();
if (bCommit)
AsyncCommitDone.Set();
AsyncCommitDone.set();
}
}

Expand Down Expand Up @@ -1749,8 +1749,8 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb
{
WorkQueue.emplace(nullptr);
WaitAllAsync();
AsyncCommitDone.Reset();
AsyncWork.Set();
AsyncCommitDone.reset();
AsyncWork.set();
return true;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
}

Expand All @@ -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);
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions far/configdb.hpp
Expand Up @@ -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();

Expand Down Expand Up @@ -393,7 +393,7 @@ class config_provider: noncopyable
void CheckDatabase(class SQLiteDb *pDb);

int m_LoadResult;
std::vector<Thread> m_Threads;
std::vector<os::thread> m_Threads;
std::vector<string> m_Problems;
std::unique_ptr<representation_source> m_TemplateSource;
mode m_Mode;
Expand Down
4 changes: 2 additions & 2 deletions far/constitle.cpp
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion far/dirmix.cpp
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions far/editcontrol.cpp
Expand Up @@ -251,7 +251,7 @@ static bool EnumFiles(VMenu2& Menu, const string& Str)

return EnumWithQuoutes(Menu, Str, [](VMenu2& Menu, const string& Token, const std::function<void(const string&)>& 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));
Expand Down Expand Up @@ -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)
{
Expand Down
26 changes: 13 additions & 13 deletions far/elevation.cpp
Expand Up @@ -175,7 +175,7 @@ T elevation::RetrieveLastErrorAndResult() const
template<typename T, typename F1, typename F2>
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;

Expand Down Expand Up @@ -292,20 +292,20 @@ 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();
if (LastError != ERROR_IO_PENDING && LastError != ERROR_PIPE_CONNECTED)
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;
Expand All @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<EAData*>(Payload));
SyncEvent.Set();
SyncEvent.set();
});
MessageManager().notify(Listener.GetEventName(), &Data);
SyncEvent.Wait();
SyncEvent.wait();
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion far/elevation.hpp
Expand Up @@ -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;
};

Expand Down
2 changes: 1 addition & 1 deletion far/farexcpt.cpp
Expand Up @@ -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)
{
Expand Down

0 comments on commit 534b103

Please sign in to comment.