From 9ae2891a3afefcbf0c72cadaef203426cb0e5954 Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Tue, 9 Nov 2010 15:04:44 -0800 Subject: start of a thread safe queue --- indra/newview/llmainlooprepeater.cpp | 82 ++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 indra/newview/llmainlooprepeater.cpp (limited to 'indra/newview/llmainlooprepeater.cpp') diff --git a/indra/newview/llmainlooprepeater.cpp b/indra/newview/llmainlooprepeater.cpp new file mode 100644 index 0000000000..c2eba97641 --- /dev/null +++ b/indra/newview/llmainlooprepeater.cpp @@ -0,0 +1,82 @@ +/** + * @file llmachineid.cpp + * @brief retrieves unique machine ids + * + * $LicenseInfo:firstyear=2009&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "llviewerprecompiledheaders.h" +#include "llapr.h" +#include "llevents.h" +#include "llmainlooprepeater.h" + + + +// LLMainLoopRepeater +//----------------------------------------------------------------------------- + + +LLMainLoopRepeater::LLMainLoopRepeater(void): + mQueue(gAPRPoolp, 1024) +{ + ; // No op. +} + + +void LLMainLoopRepeater::start(void) +{ + mMainLoopConnection = LLEventPumps::instance(). + obtain("mainloop").listen("stupid name here", boost::bind(&LLMainLoopRepeater::onMainLoop, this, _1)); + mRepeaterConnection = LLEventPumps::instance(). + obtain("mainlooprepeater").listen("other stupid name here", boost::bind(&LLMainLoopRepeater::onMessage, this, _1)); +} + + +void LLMainLoopRepeater::stop(void) +{ + mMainLoopConnection.release(); + mRepeaterConnection.release(); +} + + +bool LLMainLoopRepeater::onMainLoop(LLSD const &) +{ + LLSD message; + while(mQueue.tryPopBack(message)) { + std::string pump = message["pump"].asString(); + if(pump.length() == 0 ) continue; // No pump. + LLEventPumps::instance().obtain(pump).post(message["payload"]); + } + return false; +} + + +bool LLMainLoopRepeater::onMessage(LLSD const & event) +{ + try { + mQueue.pushFront(event); + } catch(LLThreadSafeQueueError & e) { + llwarns << "could not repeat message (" << e.what() << ")" << + event.asString() << LL_ENDL; + } + return false; +} -- cgit v1.2.3 From 7a7f89db6d9c5e6b2c6c89ea39c0302907a0442b Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Thu, 11 Nov 2010 11:46:24 -0800 Subject: fix termination issues with thread safe queue in main loop repeater service. --- indra/newview/llmainlooprepeater.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'indra/newview/llmainlooprepeater.cpp') diff --git a/indra/newview/llmainlooprepeater.cpp b/indra/newview/llmainlooprepeater.cpp index c2eba97641..ddc925a73b 100644 --- a/indra/newview/llmainlooprepeater.cpp +++ b/indra/newview/llmainlooprepeater.cpp @@ -36,7 +36,7 @@ LLMainLoopRepeater::LLMainLoopRepeater(void): - mQueue(gAPRPoolp, 1024) + mQueue(0) { ; // No op. } @@ -44,6 +44,9 @@ LLMainLoopRepeater::LLMainLoopRepeater(void): void LLMainLoopRepeater::start(void) { + if(mQueue != 0) return; + + mQueue = new LLThreadSafeQueue(gAPRPoolp, 1024); mMainLoopConnection = LLEventPumps::instance(). obtain("mainloop").listen("stupid name here", boost::bind(&LLMainLoopRepeater::onMainLoop, this, _1)); mRepeaterConnection = LLEventPumps::instance(). @@ -55,13 +58,16 @@ void LLMainLoopRepeater::stop(void) { mMainLoopConnection.release(); mRepeaterConnection.release(); + + delete mQueue; + mQueue = 0; } bool LLMainLoopRepeater::onMainLoop(LLSD const &) { LLSD message; - while(mQueue.tryPopBack(message)) { + while(mQueue->tryPopBack(message)) { std::string pump = message["pump"].asString(); if(pump.length() == 0 ) continue; // No pump. LLEventPumps::instance().obtain(pump).post(message["payload"]); @@ -73,7 +79,7 @@ bool LLMainLoopRepeater::onMainLoop(LLSD const &) bool LLMainLoopRepeater::onMessage(LLSD const & event) { try { - mQueue.pushFront(event); + mQueue->pushFront(event); } catch(LLThreadSafeQueueError & e) { llwarns << "could not repeat message (" << e.what() << ")" << event.asString() << LL_ENDL; -- cgit v1.2.3 From cf3ded4491751231056b220525970e125d813e6a Mon Sep 17 00:00:00 2001 From: brad kittenbrink Date: Thu, 18 Nov 2010 12:15:49 -0800 Subject: First draft of CHOP-106 downloaded update ready notification. Reviewed by mani. --- indra/newview/llmainlooprepeater.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/llmainlooprepeater.cpp') diff --git a/indra/newview/llmainlooprepeater.cpp b/indra/newview/llmainlooprepeater.cpp index ddc925a73b..5c020e6d98 100644 --- a/indra/newview/llmainlooprepeater.cpp +++ b/indra/newview/llmainlooprepeater.cpp @@ -48,9 +48,9 @@ void LLMainLoopRepeater::start(void) mQueue = new LLThreadSafeQueue(gAPRPoolp, 1024); mMainLoopConnection = LLEventPumps::instance(). - obtain("mainloop").listen("stupid name here", boost::bind(&LLMainLoopRepeater::onMainLoop, this, _1)); + obtain("mainloop").listen(LLEventPump::inventName(), boost::bind(&LLMainLoopRepeater::onMainLoop, this, _1)); mRepeaterConnection = LLEventPumps::instance(). - obtain("mainlooprepeater").listen("other stupid name here", boost::bind(&LLMainLoopRepeater::onMessage, this, _1)); + obtain("mainlooprepeater").listen(LLEventPump::inventName(), boost::bind(&LLMainLoopRepeater::onMessage, this, _1)); } -- cgit v1.2.3