Ejemplo n.º 1
0
void CRateLimiter::WakeupWaitingObjects(fz::scoped_lock & l)
{
	for (int i = 0; i < 2; ++i) {
		while (!m_wakeupList[i].empty()) {
			CRateLimiterObject* pObject = m_wakeupList[i].front();
			m_wakeupList[i].pop_front();
			if (!pObject->m_waiting[i])
				continue;

			assert(pObject->m_bytesAvailable[i] != 0);
			pObject->m_waiting[i] = false;

			l.unlock(); // Do not hold while executing callback
			pObject->OnRateAvailable((rate_direction)i);
			l.lock();
		}
	}
}
Ejemplo n.º 2
0
bool CLogging::InitLogFile(fz::scoped_lock& l) const
{
	if (m_logfile_initialized)
		return true;

	m_logfile_initialized = true;

	m_file = engine_.GetOptions().GetOption(OPTION_LOGGING_FILE);
	if (m_file.empty())
		return false;

#ifdef __WXMSW__
	m_log_fd = CreateFile(m_file.wc_str(), FILE_APPEND_DATA, FILE_SHARE_DELETE | FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
	if (m_log_fd == INVALID_HANDLE_VALUE)
#else
	m_log_fd = open(m_file.fn_str(), O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC, 0644);
	if (m_log_fd == -1)
#endif
	{
		l.unlock(); //Avoid recursion
		LogMessage(MessageType::Error, _("Could not open log file: %s"), wxSysErrorMsg());
		return false;
	}

	m_prefixes[static_cast<int>(MessageType::Status)] = _("Status:");
	m_prefixes[static_cast<int>(MessageType::Error)] = _("Error:");
	m_prefixes[static_cast<int>(MessageType::Command)] = _("Command:");
	m_prefixes[static_cast<int>(MessageType::Response)] = _("Response:");
	m_prefixes[static_cast<int>(MessageType::Debug_Warning)] = _("Trace:");
	m_prefixes[static_cast<int>(MessageType::Debug_Info)] = m_prefixes[static_cast<int>(MessageType::Debug_Warning)];
	m_prefixes[static_cast<int>(MessageType::Debug_Verbose)] = m_prefixes[static_cast<int>(MessageType::Debug_Warning)];
	m_prefixes[static_cast<int>(MessageType::Debug_Debug)] = m_prefixes[static_cast<int>(MessageType::Debug_Warning)];
	m_prefixes[static_cast<int>(MessageType::RawList)] = _("Listing:");

	m_pid = wxGetProcessId();

	m_max_size = engine_.GetOptions().GetOptionVal(OPTION_LOGGING_FILE_SIZELIMIT);
	if (m_max_size < 0)
		m_max_size = 0;
	else if (m_max_size > 2000)
		m_max_size = 2000;
	m_max_size *= 1024 * 1024;

	return true;
}