Item::Item(SC_HANDLE scm, const wchar_t* name, ACCESS_MASK access) : m_hndl() { LogTraceObj(L"begin (%p, '%s', 0x%X)", scm, name, access); m_hndl = CheckPointerErr(::OpenServiceW(scm, name, access)); LogTraceObj("end -> %p", m_hndl); }
Scheduler::Scheduler(const char* name, ssize_t stackSize) { LogTraceObj("('%s', %Id)", name, stackSize); impl = simstd::make_unique<SchedulerImpl>(name, stackSize); LogTraceObj("('%s', %Id) finished", name, stackSize); impl->resume(); }
HashImpl::HashImpl(const Provider& provider) { LogTraceObj("begin"); bool ok = ::CryptCreateHash(reinterpret_cast<HCRYPTPROV>(provider->get_native_handle()), CALG_SHA1, 0, 0, &m_handle); LogErrorIf(!ok, "-> %s", totext::api_error().c_str()); LogTraceObj("end"); UNUSED(ok); }
HashImpl::~HashImpl() { LogTraceObj("begin"); if (m_handle) { bool ok = ::CryptDestroyHash(m_handle); LogErrorIf(!ok, "-> %s", totext::api_error().c_str()); UNUSED(ok); } LogTraceObj("end"); }
FacadeImpl::FacadeImpl(bool activePanel) : m_hndl(activePanel ? PANEL_ACTIVE : PANEL_PASSIVE) , m_ppi(nullptr) , m_dir(nullptr) { LogTraceObj(L"begin\n"); LogTrace(L"[%d, %p]\n", activePanel, m_hndl); memory::zero(m_pi); m_pi.StructSize = sizeof(m_pi); m_pi.StructSize = psi().PanelControl(m_hndl, FCTL_GETPANELINFO, 0, &m_pi); LogTraceObj(L"end\n"); }
Item& Item::operator =(this_type&& other) { LogTraceObj(); m_hndl = other.m_hndl; other.m_hndl = nullptr; return *this; }
~DebugSymbols() { LogTraceObj(); bool ret = os::Dbghelp_dll::inst().SymCleanup(::GetCurrentProcess()); LogErrorIf(!ret, "%s", totext::api_error().c_str()); UNUSED(ret); }
void Plugin::GetPluginInfo(PluginInfo* info) { LogTraceObj(); info->Flags = PF_NONE; static GUID PluginMenuGuids[] = {MenuGuid, }; static const wchar_t* PluginMenuStrings[1]; PluginMenuStrings[0] = far3::message::get(far3::message::MenuTitle); if (get_global_info()->addToPluginsMenu) { info->PluginMenu.Guids = PluginMenuGuids; info->PluginMenu.Strings = PluginMenuStrings; info->PluginMenu.Count = lengthof(PluginMenuStrings); } static const wchar_t* DiskStrings[1]; DiskStrings[0] = far3::message::get(far3::message::DiskTitle); if (get_global_info()->addToDisksMenu) { info->DiskMenu.Guids = PluginMenuGuids; info->DiskMenu.Strings = DiskStrings; info->DiskMenu.Count = lengthof(DiskStrings); } info->PluginConfig.Guids = PluginMenuGuids; info->PluginConfig.Strings = PluginMenuStrings; info->PluginConfig.Count = lengthof(PluginMenuStrings); info->CommandPrefix = get_global_info()->prefix.c_str(); }
void Scheduler::unregister_interest(IEventHandler* callback) { UNUSED(callback); LogTraceObj("%p", callback); CRT_ASSERT(callback); // impl->del_mapping(callback); }
QueueImpl::QueueImpl(const char* name) : cs(name), se(name), name(name) { LogTraceObj("(%s)", name); }
ImplNodeEx::ImplNodeEx(const ustring& name) : name_(name) { LogTraceObj(); LogTrace2(L"('%s', '%s')", this->name(), parent_ ? parent_->name() : L""); memory::zero(data_); update(); }
bool Scheduler::SchedulerImpl::cancel_task(ITask* task) { LogTraceObj("(%p)", task); auto deleted = del_task(task); if (!deleted && task == currentTask) { LogDebug("we are trying to cancel task already running: %p", task); if (thread::get_id() == thread->get_id()) { LogInfo("cancelling task from itself: %p", task); } else { LogAtten("waiting till task is finished: %p", task); while (task == currentTask) sync::sleep(0); } } LogTraceObj("(%p) -> %d", task, deleted); return deleted; }
bool Scheduler::SchedulerImpl::add_task(ITask* task, int64_t activateTime) { LogTraceObj("(%p, %I64d)", task, activateTime); auto guard = simstd::auto_lock(*this); auto position = simstd::upper_bound(tasksOrder.cbegin(), tasksOrder.cend(), activateTime, TaskPlanGreater()); auto firstOnExecute = position == tasksOrder.cend(); // sort is descending tasksOrder.emplace(position, activateTime, task); return firstOnExecute; }
Item::~Item() { LogTraceObj(); // LogTrace2("%p", m_hndl); if (m_hndl) { ::CloseServiceHandle(m_hndl); m_hndl = nullptr; } }
explicit DebugSymbols(const char* path) { LogTraceObj(); os::Dbghelp_dll::inst().SymSetOptions(os::Dbghelp_dll::inst().SymGetOptions() | /*SYMOPT_DEFERRED_LOADS | */SYMOPT_FAIL_CRITICAL_ERRORS | SYMOPT_LOAD_LINES); bool ret = os::Dbghelp_dll::inst().SymInitializeW(::GetCurrentProcess(), sstr::a2w(path).c_str(), TRUE); LogDebugIf(ret, "['%s']", path); LogErrorIf(!ret, "['%s'] -> %s", path, totext::api_error().c_str()); UNUSED(ret); }
void QueueImpl::put(Message&& message) { LogTraceObj("['%s'] Message(0x%IX(%Iu, %Iu, %Iu))", name.c_str(), message->get_code(), message->get_a(), message->get_b(), message->get_c()); { auto guard = simstd::auto_lock(cs); emplace_back(simstd::move(message)); } se.unlock(); }
ImplNodeEx::ImplNodeEx(const ustring& name, const Node& parent) : name_(name) , parent_(parent) { LogTraceObj(); LogTrace2(L"('%s')", this->name()); memory::zero(data_); update(); }
traceback::Bfd::Context::~Context() { if (image) LogTraceObj(L"[%s]", image); HostFree(memory::heap::DefaultStat, symbol); if (handle) bfd_close(handle); HostFree(memory::heap::DefaultStat, image); }
bool Scheduler::arrange(ITask* task, int64_t timeout) { LogTraceObj("(%p, %I64d)", task, timeout); if (impl->destroying) return false; if (impl->is_exist(task)) return true; auto nowTime = sync::now(); auto activateTime = nowTime + timeout; LogTraceObj("nowTime: %I64d, activateTime: %I64d", nowTime, activateTime); if (impl->add_task(task, activateTime)) { LogDebug("task is first in queue, updating wait time"); impl->messg_queue->put_message(message::Dt::SCHEDULER | message::Et::UPDATE); } return true; }
void Scheduler::SchedulerImpl::fire_tasks() { LogTraceObj(); while (get_task_to_activate(currentTask, sync::now())) { LogDebug("task starting: %p, '%s'", currentTask, currentTask->get_name()); currentTask->execute(false); LogDebug("task ended: %p", currentTask); currentTask = nullptr; } }
void Scheduler::terminate() { LogTraceObj(); if (!impl->destroying) { impl->destroying = true; impl->messg_queue->put_message(message::Dt::SCHEDULER | message::Et::STOP); } impl->wait(); }
WaitResult_t QueueImpl::get(Message& message, int64_t timeout_msec) { LogTraceObj("['%s'] (0x%I64X%s)", name.c_str(), timeout_msec, timeout_msec == TIMEOUT_INFINITE ? " INFINITE" : ""); auto waitResult = se.try_lock_ex(timeout_msec); if (waitResult == WaitResult_t::SUCCESS) { auto guard = simstd::auto_lock(cs); message = simstd::move(front()); erase(cbegin()); } LogAttenIf(waitResult != WaitResult_t::SUCCESS, "['%s'] -> '%S'", name.c_str(), totext::c_str(waitResult)); LogDebugIf(waitResult == WaitResult_t::SUCCESS, "['%s'] -> '%S' Message(0x%IX(%Iu, %Iu, %Iu))", name.c_str(), totext::c_str(waitResult), message->get_code(), message->get_a(), message->get_b(), message->get_c()); return waitResult; }
void Scheduler::register_interest(IEventHandler* callback, message::param_type /*type*/, message::param_type /*mask*/, bool /*broadcastAlso*/) { UNUSED(callback); LogTraceObj("%p", callback); CRT_ASSERT(callback); if (impl->destroying) return; // auto subId = (broadcastAlso) ? delivery::subscribe(impl->messg_queue, type, mask) : delivery::SubscribtionId(); // impl->add_handler(callback, type, mask, subId); }
ImplNodeEx::ImplNodeEx(const fsys::IFindStat& stat, const Node& parent) noexcept : name_(stat.name()) , parent_(parent) { LogTraceObj(); LogTrace2(L"('%s', '%s')", this->name(), parent ? parent->name() : L""); memory::zero(data_); data_.dwFileAttributes = static_cast<decltype(data_.dwFileAttributes)>(stat.attr()); data_.ftCreationTime.dwHighDateTime = static_cast<decltype(data_.ftCreationTime.dwHighDateTime)>(high_part_64(stat.ctime())); data_.ftCreationTime.dwLowDateTime = static_cast<decltype(data_.ftCreationTime.dwLowDateTime)>(low_part_64(stat.ctime())); data_.ftLastAccessTime.dwHighDateTime = static_cast<decltype(data_.ftLastAccessTime.dwHighDateTime)>(high_part_64(stat.atime())); data_.ftLastAccessTime.dwLowDateTime = static_cast<decltype(data_.ftLastAccessTime.dwLowDateTime)>(low_part_64(stat.atime())); data_.ftLastWriteTime.dwHighDateTime = static_cast<decltype(data_.ftLastWriteTime.dwHighDateTime)>(high_part_64(stat.mtime())); data_.ftLastWriteTime.dwLowDateTime = static_cast<decltype(data_.ftLastWriteTime.dwLowDateTime)>(low_part_64(stat.mtime())); data_.nFileSizeHigh = static_cast<decltype(data_.nFileSizeHigh)>(high_part_64(stat.size())); data_.nFileSizeLow = static_cast<decltype(data_.nFileSizeLow)>(low_part_64(stat.size())); }
traceback::Bfd::Context::Context(const char* image) : image(cstr::dup(image)), handle(), symbol() { LogTraceObj("(%s)", image); bfd* b = bfd_openr(image, 0); if (!b) { LogError("Failed to open bfd from (%s)", image); return; } auto r1 = bfd_check_format(b, bfd_object); auto r2 = bfd_check_format_matches(b, bfd_object, NULL); auto r3 = bfd_get_file_flags(b) & HAS_SYMS; if (!(r1 && r2 && r3)) { bfd_close(b); LogError("Failed to init bfd from (%d, %d, %d) (%s)", r1, r2, r3, image); return; } void* symbol_table = nullptr; unsigned dummy = 0; if (bfd_read_minisymbols(b, FALSE, &symbol_table, &dummy) == 0) { if (bfd_read_minisymbols(b, TRUE, &symbol_table, &dummy) < 0) { free(symbol_table); bfd_close(b); LogError("Failed to read symbols from (%s)", image); return; } } handle = b; symbol = (asymbol**)symbol_table; }
ssize_t Scheduler::SchedulerImpl::run(void* data) { UNUSED(data); LogTraceObj(); while (true) { auto activateClock = get_activate_time(); // LogTraceObj(L"activateClock: %I64d", activateClock); auto activateTimeout = (activateClock == TIMEOUT_INFINITE) ? TIMEOUT_INFINITE : activateClock - simstd::min(activateClock, sync::now()); // LogTraceObj(L"activateTimeout: %I64d", activateTimeout); Message msg; auto reason = messg_queue->get(msg, activateTimeout); if (reason == WaitResult_t::SUCCESS) { if (msg->check(message::Dt::MASK, message::Dt::SCHEDULER)) { if (msg->check(message::Et::MASK, message::Et::STOP)) { break; } if (msg->check(message::Et::MASK, message::Et::UPDATE)) { LogDebug2("update message received"); fire_tasks(); } } else { notify(msg); } } else if (reason == WaitResult_t::TIMEOUT) { fire_tasks(); } else { break; } } LogInfo("finishing thread"); ::TerminateThread(::GetCurrentThread(), 0); return 0; }
Scheduler::SchedulerImpl::~SchedulerImpl() { LogTraceObj("() [%Id]", messg_queue.use_count()); CRT_ASSERT(messg_queue.unique()); }
Queue Scheduler::queue() const { LogTraceObj(); return impl->messg_queue; }
bool Scheduler::disarrange(ITask* task) { LogTraceObj("(%p)", task); return impl->cancel_task(task); }
Scheduler::~Scheduler() { LogTraceObj(); terminate(); LogTraceObj(); }