qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject svn commit: r959746 - /qpid/trunk/qpid/cpp/src/posix/QpiddBroker.cpp
Date Thu, 01 Jul 2010 18:59:21 GMT
Author: aconway
Date: Thu Jul  1 18:59:20 2010
New Revision: 959746

URL: http://svn.apache.org/viewvc?rev=959746&view=rev
Log:
Ensure broker is deleted in main thread,  not by global destructors.

Finish the fix of r959661 by making it exception safe.

Modified:
    qpid/trunk/qpid/cpp/src/posix/QpiddBroker.cpp

Modified: qpid/trunk/qpid/cpp/src/posix/QpiddBroker.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/posix/QpiddBroker.cpp?rev=959746&r1=959745&r2=959746&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/posix/QpiddBroker.cpp (original)
+++ qpid/trunk/qpid/cpp/src/posix/QpiddBroker.cpp Thu Jul  1 18:59:20 2010
@@ -107,6 +107,17 @@ void QpiddOptions::usage() const {
     cout << "Usage: qpidd [OPTIONS]" << endl << endl << *this <<
endl;
 }
 
+// Set the broker pointer on the signal handler, then reset at end of scope.
+// This is to ensure that the signal handler doesn't keep a broker
+// reference after main() has returned.
+// 
+struct ScopedSetBroker {
+    ScopedSetBroker(const boost::intrusive_ptr<Broker>& broker) {
+        qpid::broker::SignalHandler::setBroker(broker);
+    }
+    ~ScopedSetBroker() { qpid::broker::SignalHandler::setBroker(0); }
+};
+    
 struct QpiddDaemon : public Daemon {
     QpiddPosixOptions *options;
   
@@ -123,12 +134,11 @@ struct QpiddDaemon : public Daemon {
     /** Code for forked child process */
     void child() {
         boost::intrusive_ptr<Broker> brokerPtr(new Broker(options->parent->broker));
-        qpid::broker::SignalHandler::setBroker(brokerPtr);
+        ScopedSetBroker ssb(brokerPtr);
         brokerPtr->accept();
         uint16_t port=brokerPtr->getPort(options->daemon.transport);
         ready(port);            // Notify parent.
         brokerPtr->run();
-        broker::SignalHandler::setBroker(0); // Delete broker in this thread.
     }
 };
 
@@ -170,12 +180,11 @@ int QpiddBroker::execute (QpiddOptions *
     }
     else {                  // Non-daemon broker.
         boost::intrusive_ptr<Broker> brokerPtr(new Broker(options->broker));
-        broker::SignalHandler::setBroker(brokerPtr);
+        ScopedSetBroker ssb(brokerPtr);
         brokerPtr->accept();
         if (options->broker.port == 0 || myOptions->daemon.transport != TCP)
             cout << uint16_t(brokerPtr->getPort(myOptions->daemon.transport))
<< endl;
         brokerPtr->run();
-        broker::SignalHandler::setBroker(0); // Delete broker in this thread.
     }
     return 0;
 }



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org


Mime
View raw message