summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2024-09-04 14:07:26 -0400
committerNat Goodspeed <nat@lindenlab.com>2024-09-04 14:07:26 -0400
commitea24ac899ca28a587be0e187b77873a25d08a556 (patch)
tree4645577b8c1e3b60079a67c98dd95c9a03a7c8c6
parent03d7f2b84daf9ab991de6cad7d6149abda1ef716 (diff)
Extract coroutine-aware synchronization primitives to new header.
Changes on new main and changes on Lua project branch combined into a header circularity. Resolved by hoisting coroutine-aware synchronization primitives out to a new llcoromutex.h file in the `llcoro` namespace, rather than being literally members of the `LLCoros` class. But retained `using` declarations in `LLCoros` for backwards compatibility.
-rw-r--r--indra/llcommon/CMakeLists.txt1
-rw-r--r--indra/llcommon/llcoromutex.h56
-rw-r--r--indra/llcommon/llcoros.h34
-rw-r--r--indra/llcommon/llevents.cpp10
-rw-r--r--indra/llcommon/llevents.h4
-rw-r--r--indra/llplugin/llpluginprocessparent.cpp16
-rw-r--r--indra/llplugin/llpluginprocessparent.h3
7 files changed, 83 insertions, 41 deletions
diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt
index f893702118..22cc22abba 100644
--- a/indra/llcommon/CMakeLists.txt
+++ b/indra/llcommon/CMakeLists.txt
@@ -153,6 +153,7 @@ set(llcommon_HEADER_FILES
llcommonutils.h
llcond.h
llcoros.h
+ llcoromutex.h
llcrc.h
llcriticaldamp.h
lldate.h
diff --git a/indra/llcommon/llcoromutex.h b/indra/llcommon/llcoromutex.h
new file mode 100644
index 0000000000..e740e494c2
--- /dev/null
+++ b/indra/llcommon/llcoromutex.h
@@ -0,0 +1,56 @@
+/**
+ * @file llcoromutex.h
+ * @author Nat Goodspeed
+ * @date 2024-09-04
+ * @brief Coroutine-aware synchronization primitives
+ *
+ * $LicenseInfo:firstyear=2024&license=viewerlgpl$
+ * Copyright (c) 2024, Linden Research, Inc.
+ * $/LicenseInfo$
+ */
+
+#if ! defined(LL_LLCOROMUTEX_H)
+#define LL_LLCOROMUTEX_H
+
+#include "mutex.h"
+#include <boost/fiber/future/promise.hpp>
+#include <boost/fiber/future/future.hpp>
+
+// e.g. #include LLCOROS_MUTEX_HEADER
+#define LLCOROS_MUTEX_HEADER <boost/fiber/mutex.hpp>
+#define LLCOROS_CONDVAR_HEADER <boost/fiber/condition_variable.hpp>
+
+namespace boost {
+ namespace fibers {
+ class mutex;
+ enum class cv_status;
+ class condition_variable;
+ }
+}
+
+namespace llcoro
+{
+
+/**
+ * Aliases for promise and future. An older underlying future implementation
+ * required us to wrap future; that's no longer needed. However -- if it's
+ * important to restore kill() functionality, we might need to provide a
+ * proxy, so continue using the aliases.
+ */
+template <typename T>
+using Promise = boost::fibers::promise<T>;
+template <typename T>
+using Future = boost::fibers::future<T>;
+template <typename T>
+inline
+static Future<T> getFuture(Promise<T>& promise) { return promise.get_future(); }
+
+// use mutex, lock, condition_variable suitable for coroutines
+using Mutex = boost::fibers::mutex;
+using LockType = std::unique_lock<Mutex>;
+using cv_status = boost::fibers::cv_status;
+using ConditionVariable = boost::fibers::condition_variable;
+
+} // namespace llcoro
+
+#endif /* ! defined(LL_LLCOROMUTEX_H) */
diff --git a/indra/llcommon/llcoros.h b/indra/llcommon/llcoros.h
index f26ed882e8..b7ca1af109 100644
--- a/indra/llcommon/llcoros.h
+++ b/indra/llcommon/llcoros.h
@@ -29,31 +29,17 @@
#if ! defined(LL_LLCOROS_H)
#define LL_LLCOROS_H
+#include "llcoromutex.h"
#include "llevents.h"
#include "llexception.h"
#include "llinstancetracker.h"
#include "llsingleton.h"
-#include "mutex.h"
#include <boost/fiber/fss.hpp>
-#include <boost/fiber/future/promise.hpp>
-#include <boost/fiber/future/future.hpp>
#include <exception>
#include <functional>
#include <queue>
#include <string>
-// e.g. #include LLCOROS_MUTEX_HEADER
-#define LLCOROS_MUTEX_HEADER <boost/fiber/mutex.hpp>
-#define LLCOROS_CONDVAR_HEADER <boost/fiber/condition_variable.hpp>
-
-namespace boost {
- namespace fibers {
- class mutex;
- enum class cv_status;
- class condition_variable;
- }
-}
-
/**
* Registry of named Boost.Coroutine instances
*
@@ -322,23 +308,21 @@ public:
LLVoidListener cleanup);
/**
- * Aliases for promise and future. An older underlying future implementation
- * required us to wrap future; that's no longer needed. However -- if it's
- * important to restore kill() functionality, we might need to provide a
- * proxy, so continue using the aliases.
+ * LLCoros aliases for promise and future, for backwards compatibility.
+ * These have been hoisted out to the llcoro namespace.
*/
template <typename T>
- using Promise = boost::fibers::promise<T>;
+ using Promise = llcoro::Promise<T>;
template <typename T>
- using Future = boost::fibers::future<T>;
+ using Future = llcoro::Future<T>;
template <typename T>
static Future<T> getFuture(Promise<T>& promise) { return promise.get_future(); }
// use mutex, lock, condition_variable suitable for coroutines
- using Mutex = boost::fibers::mutex;
- using LockType = std::unique_lock<Mutex>;
- using cv_status = boost::fibers::cv_status;
- using ConditionVariable = boost::fibers::condition_variable;
+ using Mutex = llcoro::Mutex;
+ using LockType = llcoro::LockType;
+ using cv_status = llcoro::cv_status;
+ using ConditionVariable = llcoro::ConditionVariable;
/// for data local to each running coroutine
template <typename T>
diff --git a/indra/llcommon/llevents.cpp b/indra/llcommon/llevents.cpp
index a694f0dc7f..6531b951b9 100644
--- a/indra/llcommon/llevents.cpp
+++ b/indra/llcommon/llevents.cpp
@@ -389,7 +389,7 @@ std::string LLEventPump::inventName(const std::string& pfx)
void LLEventPump::clear()
{
- LLCoros::LockType lock(mConnectionListMutex);
+ llcoro::LockType lock(mConnectionListMutex);
// Destroy the original LLStandardSignal instance, replacing it with a
// whole new one.
mSignal = std::make_shared<LLStandardSignal>();
@@ -401,7 +401,7 @@ void LLEventPump::reset()
{
// Resetting mSignal is supposed to disconnect everything on its own
// But due to crash on 'reset' added explicit cleanup to get more data
- LLCoros::LockType lock(mConnectionListMutex);
+ llcoro::LockType lock(mConnectionListMutex);
ConnectionMap::const_iterator iter = mConnections.begin();
ConnectionMap::const_iterator end = mConnections.end();
while (iter!=end)
@@ -426,7 +426,7 @@ LLBoundListener LLEventPump::listen_impl(const std::string& name, const LLAwareL
return LLBoundListener();
}
- LLCoros::LockType lock(mConnectionListMutex);
+ llcoro::LockType lock(mConnectionListMutex);
float nodePosition = 1.0;
@@ -589,7 +589,7 @@ LLBoundListener LLEventPump::listen_impl(const std::string& name, const LLAwareL
LLBoundListener LLEventPump::getListener(const std::string& name)
{
- LLCoros::LockType lock(mConnectionListMutex);
+ llcoro::LockType lock(mConnectionListMutex);
ConnectionMap::const_iterator found = mConnections.find(name);
if (found != mConnections.end())
{
@@ -601,7 +601,7 @@ LLBoundListener LLEventPump::getListener(const std::string& name)
void LLEventPump::stopListening(const std::string& name)
{
- LLCoros::LockType lock(mConnectionListMutex);
+ llcoro::LockType lock(mConnectionListMutex);
ConnectionMap::iterator found = mConnections.find(name);
if (found != mConnections.end())
{
diff --git a/indra/llcommon/llevents.h b/indra/llcommon/llevents.h
index 368138a50b..f92257238d 100644
--- a/indra/llcommon/llevents.h
+++ b/indra/llcommon/llevents.h
@@ -50,7 +50,7 @@
#endif
#include <boost/optional/optional.hpp>
-#include "llcoros.h"
+#include "llcoromutex.h"
#include "lldependencies.h"
#include "llexception.h"
#include "llsd.h"
@@ -557,7 +557,7 @@ private:
private:
std::string mName;
- LLCoros::Mutex mConnectionListMutex;
+ llcoro::Mutex mConnectionListMutex;
protected:
template <typename LISTENER>
diff --git a/indra/llplugin/llpluginprocessparent.cpp b/indra/llplugin/llpluginprocessparent.cpp
index 00abcf740f..2035194d69 100644
--- a/indra/llplugin/llpluginprocessparent.cpp
+++ b/indra/llplugin/llpluginprocessparent.cpp
@@ -45,7 +45,7 @@ LLPluginProcessParentOwner::~LLPluginProcessParentOwner()
bool LLPluginProcessParent::sUseReadThread = false;
apr_pollset_t *LLPluginProcessParent::sPollSet = NULL;
bool LLPluginProcessParent::sPollsetNeedsRebuild = false;
-LLCoros::Mutex *LLPluginProcessParent::sInstancesMutex;
+llcoro::Mutex *LLPluginProcessParent::sInstancesMutex;
LLPluginProcessParent::mapInstances_t LLPluginProcessParent::sInstances;
LLThread *LLPluginProcessParent::sReadThread = NULL;
@@ -105,7 +105,7 @@ LLPluginProcessParent::LLPluginProcessParent(LLPluginProcessParentOwner *owner):
{
if(!sInstancesMutex)
{
- sInstancesMutex = new LLCoros::Mutex();
+ sInstancesMutex = new llcoro::Mutex();
}
mOwner = owner;
@@ -175,7 +175,7 @@ LLPluginProcessParent::ptr_t LLPluginProcessParent::create(LLPluginProcessParent
// Don't add to the global list until fully constructed.
{
- LLCoros::LockType lock(*sInstancesMutex);
+ llcoro::LockType lock(*sInstancesMutex);
sInstances.insert(mapInstances_t::value_type(that.get(), that));
}
@@ -185,7 +185,7 @@ LLPluginProcessParent::ptr_t LLPluginProcessParent::create(LLPluginProcessParent
/*static*/
void LLPluginProcessParent::shutdown()
{
- LLCoros::LockType lock(*sInstancesMutex);
+ llcoro::LockType lock(*sInstancesMutex);
mapInstances_t::iterator it;
for (it = sInstances.begin(); it != sInstances.end(); ++it)
@@ -243,7 +243,7 @@ bool LLPluginProcessParent::pollTick()
{
// this grabs a copy of the smart pointer to ourselves to ensure that we do not
// get destroyed until after this method returns.
- LLCoros::LockType lock(*sInstancesMutex);
+ llcoro::LockType lock(*sInstancesMutex);
mapInstances_t::iterator it = sInstances.find(this);
if (it != sInstances.end())
that = (*it).second;
@@ -262,7 +262,7 @@ void LLPluginProcessParent::removeFromProcessing()
// Remove from the global list before beginning destruction.
{
// Make sure to get the global mutex _first_ here, to avoid a possible deadlock against LLPluginProcessParent::poll()
- LLCoros::LockType lock(*sInstancesMutex);
+ llcoro::LockType lock(*sInstancesMutex);
{
LLMutexLock lock2(&mIncomingQueueMutex);
sInstances.erase(this);
@@ -844,7 +844,7 @@ void LLPluginProcessParent::updatePollset()
return;
}
- LLCoros::LockType lock(*sInstancesMutex);
+ llcoro::LockType lock(*sInstancesMutex);
if(sPollSet)
{
@@ -967,7 +967,7 @@ void LLPluginProcessParent::poll(F64 timeout)
mapInstances_t::iterator it;
{
- LLCoros::LockType lock(*sInstancesMutex);
+ llcoro::LockType lock(*sInstancesMutex);
it = sInstances.find(thatId);
if (it != sInstances.end())
that = (*it).second;
diff --git a/indra/llplugin/llpluginprocessparent.h b/indra/llplugin/llpluginprocessparent.h
index d1c4933d81..903be35526 100644
--- a/indra/llplugin/llpluginprocessparent.h
+++ b/indra/llplugin/llpluginprocessparent.h
@@ -33,6 +33,7 @@
#include <boost/enable_shared_from_this.hpp>
#include "llapr.h"
+#include "llcoromutex.h"
#include "llprocess.h"
#include "llpluginmessage.h"
#include "llpluginmessagepipe.h"
@@ -207,7 +208,7 @@ private:
apr_pollfd_t mPollFD;
static apr_pollset_t *sPollSet;
static bool sPollsetNeedsRebuild;
- static LLCoros::Mutex *sInstancesMutex;
+ static llcoro::Mutex *sInstancesMutex;
static mapInstances_t sInstances;
static void dirtyPollSet();
static void updatePollset();