Changeset 16832 for trunk/FACT++


Ignore:
Timestamp:
06/14/13 10:51:45 (11 years ago)
Author:
tbretz
Message:
Using a queue, to be able to decouple writing to the log-files from the disk load, but at the same time ensure that the data is flushed immediately and not buffered for a long time.
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/WindowLog.cc

    r12959 r16832  
    135135    fMuxFile.lock();
    136136    fLogFile.close();
     137    fMuxFile.unlock();
     138}
     139
     140void WindowLog::WriteFile(const string &sout)
     141{
     142    fMuxFile.lock();
     143    fLogFile << sout;
     144    fLogFile.flush();
    137145    fMuxFile.unlock();
    138146}
     
    220228    }
    221229
     230    fQueueFile.emplace(sout);
     231    /*
    222232    // Output everything also to the log-file
    223233    fMuxFile.lock();
    224234    fLogFile << sout;
    225     fLogFile.flush();
     235    //fLogFile.flush();
    226236    fMuxFile.unlock();
    227 
     237    */
    228238    // If we are flushing because of an EOL, we reset also all attributes
    229239}
  • trunk/FACT++/src/WindowLog.h

    r11942 r16832  
    88
    99#include <ncurses.h> // A_NORMAL etc
     10
     11#include "queue.h"
    1012
    1113/// Stream manipulators to change the color of a WindowLog stream
     
    7476    std::mutex fMuxWindow;     /// Mutex securing output to fWindow
    7577
     78    Queue<std::string> fQueueFile;
     79
    7680    static std::string GetAnsiAttr(int m);
    7781
     
    7983    void AddColor(int m);
    8084
     85    void WriteFile(const std::string &);
    8186    void WriteBuffer();
    8287
     
    9398    //! Switch on screen output
    9499    //
    95     WindowLog() : std::ostream(this), fPPtr(fBase), fEPtr(fBase+fgBufferSize), fWindow(0), fIsNull(false), fEnableBacklog(true)
     100    WindowLog() : std::ostream(this), fPPtr(fBase), fEPtr(fBase+fgBufferSize), fWindow(0), fIsNull(false), fEnableBacklog(true),
     101        fQueueFile(std::bind(&WindowLog::WriteFile, this, std::placeholders::_1))
    96102    {
    97         fLogFile.rdbuf()->pubsetbuf(0,0); // Switch off buffering
     103        //fLogFile.rdbuf()->pubsetbuf(0,0); // Switch off buffering
    98104        setp(&fBuffer, &fBuffer+1);
    99105        *this << '\0';
    100106    }
    101     WindowLog(WindowLog const& log) : std::ios(), std::streambuf(), std::ostream((std::streambuf*)&log), fWindow(log.fWindow), fIsNull(false), fEnableBacklog(true)
     107    WindowLog(WindowLog const& log) : std::ios(), std::streambuf(), std::ostream((std::streambuf*)&log), fWindow(log.fWindow), fIsNull(false), fEnableBacklog(true),
     108        fQueueFile(bind(&WindowLog::WriteFile, this, std::placeholders::_1))
    102109    {
    103         fLogFile.rdbuf()->pubsetbuf(0,0); // Switch off buffering
     110        //fLogFile.rdbuf()->pubsetbuf(0,0); // Switch off buffering
     111    }
     112    ~WindowLog()
     113    {
     114        fQueueFile.wait(false);
    104115    }
    105116
Note: See TracChangeset for help on using the changeset viewer.