11 #include <boost/date_time/posix_time/posix_time.hpp> 12 #include <boost/thread/thread.hpp> 16 : buffer_(bufferSize, NULL),
26 for (std::size_t i = 0; i <
buffer_.size(); ++i)
delete buffer_[i];
30 if (
empty())
return false;
33 std::string str = data->
buf.str();
37 for (std::size_t i = 0; i <
outputs_.size(); ++i)
46 return RTLoggerStream(NULL,
oss_);
48 bool alone =
wmutex.try_lock();
52 return RTLoggerStream(NULL,
oss_);
57 data->
buf.pubseekpos(0);
59 return RTLoggerStream(
this,
oss_);
70 : requestShutdown_(false),
71 threadPolicy_(SCHED_OTHER),
73 changedThreadParams(true),
74 t_(&
thread::spin, this, logger) {}
91 struct sched_param threadParam;
92 if (pthread_getschedparam(pthread_self(), &threadPolicy, &threadParam) ==
94 threadPolicy = threadPolicy_;
95 threadParam.sched_priority = threadPriority_;
96 if (threadParam.sched_priority < sched_get_priority_min(threadPolicy))
97 threadParam.sched_priority = sched_get_priority_min(threadPolicy);
99 pthread_setschedparam(pthread_self(), threadPolicy, &threadParam);
100 changedThreadParams =
false;
108 while (!requestShutdown_ || !logger->
empty()) {
112 boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
113 if (changedThreadParams) changeThreadParams();
std::size_t frontIdx_
Index of the next value to be read.
std::vector< Data * > buffer_
std::vector< LoggerStreamPtr_t > outputs_
Main class of the real-time logger.
void changeThreadParams()
thread(RealTimeLogger *logger)
void spin(RealTimeLogger *logger)
boost::mutex wmutex
The writer mutex.
static RealTimeLogger * instance_
RealTimeLogger(const std::size_t &bufferSize)
static RealTimeLogger & instance()