From a1cb80446649bc3401bcb638d5ce53548bf6719e Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Fri, 1 Dec 2006 17:18:54 +0000 Subject: Re-enable signal handling. Make APRAcceptor::shutdown() threadsafe. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@481305 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/lib/common/sys/apr/APRAcceptor.cpp | 27 +++++++++++++++++++-------- cpp/src/qpidd.cpp | 6 ++++-- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/cpp/lib/common/sys/apr/APRAcceptor.cpp b/cpp/lib/common/sys/apr/APRAcceptor.cpp index c998b33625..6853833797 100644 --- a/cpp/lib/common/sys/apr/APRAcceptor.cpp +++ b/cpp/lib/common/sys/apr/APRAcceptor.cpp @@ -36,12 +36,16 @@ class APRAcceptor : public Acceptor virtual void run(qpid::sys::SessionHandlerFactory* factory); virtual void shutdown(); + private: + void shutdownImpl(); + private: int16_t port; bool trace; LFProcessor processor; apr_socket_t* socket; volatile bool running; + Mutex shutdownLock; }; // Define generic Acceptor::create() to return APRAcceptor. @@ -88,23 +92,30 @@ void APRAcceptor::run(SessionHandlerFactory* factory) { LFSessionContext* session = new LFSessionContext(APRPool::get(), client, &processor, trace); session->init(factory->create(session)); }else{ - running = false; - if(status != APR_EINTR){ - std::cout << "ERROR: " << get_desc(status) << std::endl; + Mutex::ScopedLock locker(shutdownLock); + if(running) { + if(status != APR_EINTR){ + std::cout << "ERROR: " << get_desc(status) << std::endl; + } + shutdownImpl(); } } } - shutdown(); } void APRAcceptor::shutdown() { - // TODO aconway 2006-10-12: Cleanup, this is not thread safe. + Mutex::ScopedLock locker(shutdownLock); if (running) { - running = false; - processor.stop(); - CHECK_APR_SUCCESS(apr_socket_close(socket)); + shutdownImpl(); } } +void APRAcceptor::shutdownImpl() { + Mutex::ScopedLock locker(shutdownLock); + running = false; + processor.stop(); + CHECK_APR_SUCCESS(apr_socket_close(socket)); +} + }} diff --git a/cpp/src/qpidd.cpp b/cpp/src/qpidd.cpp index 7e3b1b8006..525e2efe34 100644 --- a/cpp/src/qpidd.cpp +++ b/cpp/src/qpidd.cpp @@ -20,7 +20,8 @@ */ #include #include -// FIXME #include +// FIXME +#include #include #include @@ -43,7 +44,8 @@ int main(int argc, char** argv) config.usage(); }else{ broker = Broker::create(config); -// FIXME qpid::sys::signal(SIGINT, handle_signal); +// FIXME + signal(SIGINT, handle_signal); broker->run(); } return 0; -- cgit v1.2.1