CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/FWCore/MessageService/src/MessageServicePresence.cc

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------
00002 //
00003 // MessageService Presence.cc
00004 //
00005 // Changes:
00006 //
00007 //   1 - 2/11/07  mf    Added a call to edm::disableAllSigs(&oldset)
00008 //                      to disable signals so that they are all handled 
00009 //                      by the event processor thread
00010 // 
00011 //   2 - 8/10/09  mf    Mods to support the use of abstract scribes
00012 //                cdj   so that standalones can work easily
00013 //                      
00014 // 
00015 //   2 - 8/12/09  mf    Mods to get ownership of mlscribe better
00016 //                cdj   
00017 //                      
00018 // 
00019 
00020 #include "FWCore/MessageService/interface/MainThreadMLscribe.h"
00021 #include "FWCore/MessageService/interface/MessageServicePresence.h"
00022 #include "FWCore/MessageService/interface/MessageLoggerScribe.h"
00023 #include "FWCore/MessageService/interface/ThreadQueue.h"
00024 
00025 #include "FWCore/MessageLogger/interface/MessageLoggerQ.h"
00026 #include "FWCore/Utilities/interface/UnixSignalHandlers.h"
00027 
00028 #include <boost/bind.hpp>
00029 
00030 using namespace edm::service;
00031 
00032 
00033 namespace  {
00034 void
00035   runMessageLoggerScribe(boost::shared_ptr<ThreadQueue> queue)
00036 {
00037   sigset_t oldset;
00038   edm::disableAllSigs(&oldset);
00039   MessageLoggerScribe  m(queue);  
00040   m.run();
00041   // explicitly DO NOT reenableSigs(oldset) because -
00042   // 1) When this terminates, the main thread may not yet have done a join() and we
00043   //    don't want to handle the sigs at that point in this thread
00044   // 2) If we re-enable sigs, we will get the entire stack of accumulated ones (if any) 
00045 }
00046 }  // namespace
00047 
00048 namespace edm {
00049 namespace service {
00050 
00051 
00052 MessageServicePresence::MessageServicePresence()
00053   : Presence()
00054   , m_queue (new ThreadQueue)
00055   , m_scribeThread
00056          ( ( (void) MessageLoggerQ::instance() // ensure Q's static data init'd
00057             , boost::bind(&runMessageLoggerScribe, m_queue)
00058                                 // start a new thread, run rMLS(m_queue)
00059                                 // ChangeLog 2
00060           ) ) 
00061           // Note that m_scribeThread, which is a boost::thread, has a single-argument ctor - 
00062           // just the function to be run.  But we need to do something first, namely,
00063           // ensure that the MessageLoggerQ is in a valid state - and that requires
00064           // a statement.  So we bundle that statement in parenthesis, separated by 
00065           // a comma, with the argument we really want (runMessageLoggerScribe).  This
00066           // creates a single argument, wheich evaluates to runMessageLoggerScribe after
00067           // first executing the before-the-comma statement. 
00068 {
00069   MessageLoggerQ::setMLscribe_ptr(
00070     boost::shared_ptr<edm::service::AbstractMLscribe>
00071         (new MainThreadMLscribe(m_queue))); 
00072                                                                 // change log 3
00073   //std::cout << "MessageServicePresence ctor\n";
00074 }
00075 
00076 
00077 MessageServicePresence::~MessageServicePresence()
00078 {
00079   MessageLoggerQ::MLqEND();
00080   m_scribeThread.join();
00081   MessageLoggerQ::setMLscribe_ptr
00082     (boost::shared_ptr<edm::service::AbstractMLscribe>());   // change log 3
00083 }
00084 
00085 } // end of namespace service  
00086 } // end of namespace edm