mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-25 10:01:33 +08:00
fixed dist_sink in gcc
This commit is contained in:
parent
916a686f8f
commit
aa0f62292b
@ -11,6 +11,7 @@
|
|||||||
#include <spdlog/sinks/sink.h>
|
#include <spdlog/sinks/sink.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <mutex>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -23,7 +24,7 @@ namespace sinks
|
|||||||
template<class Mutex>
|
template<class Mutex>
|
||||||
class dist_sink: public base_sink<Mutex>
|
class dist_sink: public base_sink<Mutex>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit dist_sink() :_sinks() {}
|
explicit dist_sink() :_sinks() {}
|
||||||
dist_sink(const dist_sink&) = delete;
|
dist_sink(const dist_sink&) = delete;
|
||||||
dist_sink& operator=(const dist_sink&) = delete;
|
dist_sink& operator=(const dist_sink&) = delete;
|
||||||
@ -42,20 +43,20 @@ protected:
|
|||||||
public:
|
public:
|
||||||
void flush() override
|
void flush() override
|
||||||
{
|
{
|
||||||
std::lock_guard<Mutex> lock(_mutex);
|
std::lock_guard<Mutex> lock(base_sink<Mutex>::_mutex);
|
||||||
for (auto &sink : _sinks)
|
for (auto &sink : _sinks)
|
||||||
sink->flush();
|
sink->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_sink(std::shared_ptr<sink> sink)
|
void add_sink(std::shared_ptr<sink> sink)
|
||||||
{
|
{
|
||||||
std::lock_guard<Mutex> lock(_mutex);
|
std::lock_guard<Mutex> lock(base_sink<Mutex>::_mutex);
|
||||||
_sinks.push_back(sink);
|
_sinks.push_back(sink);
|
||||||
}
|
}
|
||||||
|
|
||||||
void remove_sink(std::shared_ptr<sink> sink)
|
void remove_sink(std::shared_ptr<sink> sink)
|
||||||
{
|
{
|
||||||
std::lock_guard<Mutex> lock(_mutex);
|
std::lock_guard<Mutex> lock(base_sink<Mutex>::_mutex);
|
||||||
_sinks.erase(std::remove(_sinks.begin(), _sinks.end(), sink), _sinks.end());
|
_sinks.erase(std::remove(_sinks.begin(), _sinks.end(), sink), _sinks.end());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user