Changeset 16479
- Timestamp:
- 05/30/13 14:53:51 (12 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/MessageDim.cc
r15088 r16479 38 38 "A general logging service providing a quality of service (severity)" 39 39 "|Message[string]:The message"), 40 MessageImp(out), fDebug(false) 40 MessageImp(out), fDebug(false), 41 fMsgQueue(std::bind(&MessageDimTX::UpdateService, this, placeholders::_1)) 41 42 { 42 43 // This is a message which will never arrive because … … 52 53 MessageDimTX::~MessageDimTX() 53 54 { 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 61 void 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; 55 69 } 56 70 … … 67 81 { 68 82 MessageImp::Write(t, txt, qos); 83 fMsgQueue.emplace(t, txt, qos); 69 84 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; 103 86 } 104 87 -
trunk/FACT++/src/MessageDim.h
r11417 r16479 2 2 #define FACT_MessageDim 3 3 4 #include "queue.h" 4 5 #include "MessageImp.h" 5 6 7 8 6 #include "DimDescriptionService.h" 9 7 //#include <dis.hxx> // DimService … … 13 11 private: 14 12 bool fDebug; 13 14 Queue<std::tuple<Time,std::string,int>> fMsgQueue; 15 16 void UpdateService(const std::tuple<Time,std::string,int> &data); 15 17 16 18 public:
Note:
See TracChangeset
for help on using the changeset viewer.