Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions source/common/common/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ class LockingStderrOrFileSink : public spdlog::sinks::sink {
void log(const spdlog::details::log_msg& msg) override;
void flush() override;

/**
* @return bool whether a lock has been established.
*/
bool hasLock() const { return lock_ != nullptr; }

private:
Thread::BasicLockable* lock_{};
Filesystem::FileSharedPtr log_file_;
Expand Down Expand Up @@ -132,6 +137,11 @@ class Registry {
*/
static const std::vector<Logger>& loggers() { return allLoggers(); }

/**
* @Return bool whether the registry has been initialized.
*/
static bool initialized() { return getSink()->hasLock(); }

private:
/*
* @return std::vector<Logger>& return the installed loggers.
Expand Down
2 changes: 2 additions & 0 deletions source/common/common/thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
#include <functional>

#include "common/common/assert.h"
#include "common/common/logger.h"
#include "common/common/macros.h"

namespace Envoy {
namespace Thread {

Thread::Thread(std::function<void()> thread_routine) : thread_routine_(thread_routine) {
RELEASE_ASSERT(Logger::Registry::initialized());
int rc = pthread_create(&thread_id_, nullptr,
[](void* arg) -> void* {
static_cast<Thread*>(arg)->thread_routine_();
Expand Down