Changeset 16479


Ignore:
Timestamp:
05/30/13 14:53:51 (12 years ago)
Author:
tbretz
Message:
Use the new Queue class to queue the Messages. This avoids Dim introduced delays during update, but we might loose log messages when a progam crashes or is shut down... we will see how it works.
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

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

    r15088 r16479  
    3838                          "A general logging service providing a quality of service (severity)"
    3939                          "|Message[string]:The message"),
    40 MessageImp(out), fDebug(false)
     40    MessageImp(out), fDebug(false),
     41    fMsgQueue(std::bind(&MessageDimTX::UpdateService, this, placeholders::_1))
    4142{
    4243    // This is a message which will never arrive because
     
    5253MessageDimTX::~MessageDimTX()
    5354{
    54     Message("MessageDimTX shutting down.");
     55    // Everything here will never be sent by dim because the
     56    // dim services have been stopped already. This is necessary,
     57    // to have them available already during startup
     58    Message("MessageDimTX shutting down ["+to_string(fMsgQueue.size())+"]");
     59}
     60
     61void MessageDimTX::UpdateService(const tuple<Time,string,int> &data)
     62{
     63    setData(get<1>(data));
     64    setQuality(get<2>(data));
     65
     66    const int rc = DimDescribedService::Update(get<0>(data));
     67    if (rc==0 && fDebug)
     68        Out() << " !! " << get<0>(data).GetAsStr() << " - Sending failed!" << endl;
    5569}
    5670
     
    6781{
    6882    MessageImp::Write(t, txt, qos);
     83    fMsgQueue.emplace(t, txt, qos);
    6984
    70 
    71     // We cannot use our own mutex here because it can create dead-locks
    72     // in a hand-shake with the global dim-mutex if a service is
    73     // updated from within a dimHandler (dim-mutex already locked)
    74     // and at the same time another thread tries to lock the mutex.
    75     //
    76     // Thread 1: Lock global Dim mutex and call infoHandler
    77     //
    78     // Thread 2: CALL Write
    79     // Thread 2: LOCK Write-mutex
    80     // Thread 2: setQuality will try to lock global Dim mutex
    81     //           (since Thread1!=Thread2 this results in a wait)
    82     //
    83     // Thread 1: CALL Write from within the infoHandler
    84     // Thread 1: LOCK Write-mutex
    85     //           (since Thread2 now waits for the infoHandler to finish
    86     //            and the infoHandler has to wait for the Write-mutex
    87     //            we have a dead-lock)
    88     //
    89     dim_lock();
    90 
    91     // We have to use setData to make sure the DimService will
    92     // hold a local copy of the data.
    93     setQuality(qos);
    94 
    95     const int rc = DimDescribedService::Update(txt);
    96 
    97     dim_unlock();
    98 
    99     if (rc==0 && fDebug)
    100         Out() << " !! " << t.GetAsStr() << " - Sending failed!" << endl;
    101 
    102     return rc;
     85    return 1;
    10386}
    10487
  • trunk/FACT++/src/MessageDim.h

    r11417 r16479  
    22#define FACT_MessageDim
    33
     4#include "queue.h"
    45#include "MessageImp.h"
    5 
    6 
    7 
    86#include "DimDescriptionService.h"
    97//#include <dis.hxx> // DimService
     
    1311private:
    1412    bool fDebug;
     13
     14    Queue<std::tuple<Time,std::string,int>> fMsgQueue;
     15
     16    void UpdateService(const std::tuple<Time,std::string,int> &data);
    1517
    1618public:
Note: See TracChangeset for help on using the changeset viewer.