Ignore:
Timestamp:
Oct 30, 2015, 11:43:20 AM (10 years ago)
Author:
Frederik Heber <heber@…>
Children:
3681dd
Parents:
dd7c44
git-author:
Frederik Heber <heber@…> (08/04/15 19:57:52)
git-committer:
Frederik Heber <heber@…> (10/30/15 11:43:20)
Message:

ObserverLog is also protected with mutexes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Observer/ObserverLog.cpp

    rdd7c44 r6e2f3b  
    2424#include <sstream>
    2525
     26#include <boost/thread/locks.hpp>
     27
    2628#include "CodePatterns/Observer/ObserverLog.hpp"
    2729#include "CodePatterns/Singleton_impl.hpp"
     
    3335    count(0)
    3436{
     37  boost::lock_guard<boost::recursive_mutex> guard(mutex);
    3538  nullstream = new std::ofstream("/dev/null");
    3639  outstream = nullstream;
     
    3942ObserverLog::~ObserverLog()
    4043{
     44  boost::lock_guard<boost::recursive_mutex> guard(mutex);
    4145  outstream = NULL;
    4246  delete nullstream;
     
    6973void ObserverLog::disableLogging()
    7074{
     75  boost::lock_guard<boost::recursive_mutex> guard(mutex);
    7176  outstream = nullstream;
    7277}
     
    7479void ObserverLog::enableLogging()
    7580{
     81  boost::lock_guard<boost::recursive_mutex> guard(mutex);
    7682  outstream = &std::cout;
    7783}
     
    8086
    8187std::string ObserverLog::getName(void* obj){
     88  boost::lock_guard<boost::recursive_mutex> guard(mutex);
    8289  return names[obj];
    8390}
    8491
    8592bool ObserverLog::isObservable(void* obj){
     93  boost::lock_guard<boost::recursive_mutex> guard(mutex);
    8694  return observables.count(obj);
    8795}
    8896
    8997void ObserverLog::addName(void* obj , std::string name){
     98  boost::lock_guard<boost::recursive_mutex> guard(mutex);
    9099  std::stringstream sstr;
    91100  sstr << name << "_" << count++;
     
    94103
    95104void ObserverLog::addObservable(void* obj){
     105  boost::lock_guard<boost::recursive_mutex> guard(mutex);
    96106  observables.insert(obj);
    97107}
    98108
    99109void ObserverLog::deleteName(void* obj){
     110  boost::lock_guard<boost::recursive_mutex> guard(mutex);
    100111  names.erase(obj);
    101112}
    102113
    103114void ObserverLog::deleteObservable(void* obj){
     115  boost::lock_guard<boost::recursive_mutex> guard(mutex);
    104116  observables.erase(obj);
    105117}
     
    114126 */
    115127boost::shared_ptr<ObserverLog::Log> ObserverLog::addMessage(int depth){
     128  boost::lock_guard<boost::recursive_mutex> guard(mutex);
    116129  boost::shared_ptr<ObserverLog::Log> L(new Log(this));
    117130  for(int i=depth;i--;)
Note: See TracChangeset for help on using the changeset viewer.