Skip to content

Commit

Permalink
Merge branch 'main' into far3-dev-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michaellukashov committed Feb 23, 2024
2 parents eda6e26 + 558de46 commit 6c1217c
Show file tree
Hide file tree
Showing 17 changed files with 136 additions and 308 deletions.
14 changes: 14 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@
## [Unreleased] - ReleaseDate


## [24.2.2.591] - 2024-02-23

### Fixes

Thanks to ssvine https://github.com/ssvine
- gh-409 Debug log loses messages
- gh-407 Allow empty netbox prefix to open session list
- gh-405 Fix ClosePanel problems
- gh-403 Return to sessions list from the root directory by pressing Ctrl-PgUp
- gh-401 Assertion on connection when logging is enabled
- gh-399 Elapsed and Left times in copy dialog are broken
- gh-397 Unable to connect to WebDAV


## [24.2.2.590] - 2024-02-20

### Changes
Expand Down
44 changes: 35 additions & 9 deletions libs/tinylog/src/LogStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

namespace tinylog {

LogStream::LogStream(FILE * file, pthread_mutex_t & mutex, pthread_cond_t & cond, bool & already_swap) :
LogStream::LogStream(FILE * file, pthread_mutex_t & mutex, pthread_cond_t & cond, bool & drain_buffer) :
front_buff_(std::make_unique<Buffer>(LOG_BUFFER_SIZE)),
back_buff_(std::make_unique<Buffer>(LOG_BUFFER_SIZE)),
// queue_(std::make_unique<LockFreeQueue>()),
file_(file),
mutex_(mutex),
cond_(cond),
already_swap_(already_swap)
drain_buffer_(drain_buffer)
{
Utils::CurrentTime(&tv_base_, &tm_base_);
// DEBUG_PRINTF("begin");
Expand Down Expand Up @@ -60,8 +60,8 @@ void LogStream::WriteBuffer()
{
if (!file_)
return;
back_buff_->Flush(file_);
back_buff_->Clear();
front_buff_->Flush(file_);
front_buff_->Clear();

/*std::string data;
int ret = queue_->Pop(data);
Expand Down Expand Up @@ -103,14 +103,40 @@ int64_t LogStream::InternalWrite(const char * log_data, int64_t ToWrite)

pthread_mutex_lock(&mutex_);

if (front_buff_->TryAppend(&tm_base_, static_cast<int64_t>(tv_base_.tv_usec), file_name_, line_, func_name_, str_log_level_, log_data) < 0)
while (true)
{
SwapBuffer();
already_swap_ = true;
front_buff_->TryAppend(&tm_base_, static_cast<int64_t>(tv_base_.tv_usec), file_name_, line_, func_name_, str_log_level_, log_data);
auto & buff = drain_buffer_ ? back_buff_ : front_buff_;
// append to the current buffer
if (buff->TryAppend(&tm_base_, static_cast<int64_t>(tv_base_.tv_usec), file_name_, line_, func_name_, str_log_level_, log_data) < 0)
{
if (drain_buffer_)
{
// we are appending to the back_buff_ and there is no more space there
// wait until buffer is drained (very rare situation)
pthread_mutex_unlock(&mutex_);
while (drain_buffer_)
{
// yield execution to another thread
// usially it will require only one iteration
Sleep(1);
}
pthread_mutex_lock(&mutex_);
}
else
{
drain_buffer_ = true;
}
}
else
{
break;
}
}

pthread_cond_signal(&cond_);
if (drain_buffer_)
{
pthread_cond_signal(&cond_);
}
pthread_mutex_unlock(&mutex_);

return Result;
Expand Down
40 changes: 20 additions & 20 deletions libs/tinylog/src/TinyLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ class TinyLogImpl
pthread_mutex_t mutex_;
pthread_cond_t cond_;
bool run_{false};
bool already_swap_{false};
bool drain_buffer_{false};
};

TinyLogImpl::TinyLogImpl(FILE * file) noexcept :
log_level_(Utils::LEVEL_INFO),
thrd_(INVALID_HANDLE_VALUE),
ThreadId_(0),
run_(true),
already_swap_(false)
drain_buffer_(false)
{
pthread_mutex_init(&mutex_, nullptr);
pthread_cond_init(&cond_, nullptr);
logstream_ = std::make_unique<LogStream>(file, mutex_, cond_, already_swap_);
logstream_ = std::make_unique<LogStream>(file, mutex_, cond_, drain_buffer_);
void * Parameter = this;

thrd_ = ::CreateThread(nullptr,
Expand Down Expand Up @@ -108,6 +108,9 @@ void TinyLogImpl::Close()
if (run_)
{
run_ = false;
pthread_mutex_lock(&mutex_);
pthread_cond_signal(&cond_);
pthread_mutex_unlock(&mutex_);
pthread_join(thrd_, nullptr);
logstream_.reset();
}
Expand All @@ -123,34 +126,31 @@ DWORD WINAPI TinyLogImpl::ThreadFunc(void * pt_arg)

int32_t TinyLogImpl::MainLoop()
{
int result;
const DWORD timeout_millisecs = 1000 * TIME_OUT_SECOND;

pthread_mutex_lock(&mutex_);
while (run_)
{
DWORD timeout_millisecs = 1000 * TIME_OUT_SECOND;

pthread_mutex_lock(&mutex_);

while (!already_swap_)
while (run_ && !drain_buffer_)
{
if (pthread_cond_timedwait(&cond_, &mutex_, timeout_millisecs) == WAIT_TIMEOUT)
result = pthread_cond_timedwait(&cond_, &mutex_, timeout_millisecs);
if (result == WAIT_TIMEOUT)
{
if (run_)
{
logstream_->SwapBuffer();
logstream_->UpdateBaseTime();
}
break;
}
}

if (already_swap_)
logstream_->WriteBuffer();

if (drain_buffer_)
{
already_swap_ = false;
logstream_->SwapBuffer();
logstream_->UpdateBaseTime();
drain_buffer_ = false;
}

if (run_) logstream_->WriteBuffer();

pthread_mutex_unlock(&mutex_);
}
pthread_mutex_unlock(&mutex_);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion libs/tinylog/tinylog/LogStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class LogStream
struct tm tm_base_{};
pthread_mutex_t & mutex_;
pthread_cond_t & cond_;
bool & already_swap_;
bool & drain_buffer_;
};

} // namespace tinylog
Loading

0 comments on commit 6c1217c

Please sign in to comment.