Skip to content
Snippets Groups Projects
Commit 68f42e4e authored by Nat Goodspeed's avatar Nat Goodspeed
Browse files

MAINT-5351: Finish cleaning up messy merge from backing out backout

parent 9bde72f7
No related branches found
No related tags found
No related merge requests found
...@@ -61,7 +61,7 @@ LLCoros::coro::self& LLCoros::get_self() ...@@ -61,7 +61,7 @@ LLCoros::coro::self& LLCoros::get_self()
return *current->mSelf; return *current->mSelf;
} }
LLCoros::Suspending::Suspending(): llcoro::Suspending::Suspending():
mSuspended(LLCoros::sCurrentCoro.get()) mSuspended(LLCoros::sCurrentCoro.get())
{ {
// Revert mCurrentCoro to the value it had at the moment we last switched // Revert mCurrentCoro to the value it had at the moment we last switched
...@@ -69,7 +69,7 @@ LLCoros::Suspending::Suspending(): ...@@ -69,7 +69,7 @@ LLCoros::Suspending::Suspending():
LLCoros::sCurrentCoro.reset(mSuspended->mPrev); LLCoros::sCurrentCoro.reset(mSuspended->mPrev);
} }
LLCoros::Suspending::~Suspending() llcoro::Suspending::~Suspending()
{ {
// Okay, we're back, update our mPrev // Okay, we're back, update our mPrev
mSuspended->mPrev = LLCoros::sCurrentCoro.get(); mSuspended->mPrev = LLCoros::sCurrentCoro.get();
......
...@@ -144,18 +144,6 @@ class LL_COMMON_API LLCoros: public LLSingleton<LLCoros> ...@@ -144,18 +144,6 @@ class LL_COMMON_API LLCoros: public LLSingleton<LLCoros>
*/ */
std::string getName() const; std::string getName() const;
/// get the current coro::self& for those who really really care
static coro::self& get_self();
/// Instantiate one of these in a block surrounding any leaf point when
/// control literally switches away from this coroutine.
class Suspending
public:
Suspending();
~Suspending();
private:
coro::self* mSuspended;
};
/// for delayed initialization /// for delayed initialization
void setStackSize(S32 stacksize); void setStackSize(S32 stacksize);
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
#include "llerror.h" #include "llerror.h"
#include "llcoros.h" #include "llcoros.h"
std::string LLEventDetail::listenerNameForCoro() namespace
{ {
/** /**
...@@ -143,14 +143,24 @@ void storeToLLSDPath(LLSD& dest, const LLSD& rawPath, const LLSD& value) ...@@ -143,14 +143,24 @@ void storeToLLSDPath(LLSD& dest, const LLSD& rawPath, const LLSD& value)
*pdest = value; *pdest = value;
} }
LLSD postAndWait(const LLSD& event, const LLEventPumpOrPumpName& requestPump, } // anonymous
void llcoro::yield()
{
// By viewer convention, we post an event on the "mainloop" LLEventPump
// each iteration of the main event-handling loop. So waiting for a single
// event on "mainloop" gives us a one-frame yield.
waitForEventOn("mainloop");
}
LLSD llcoro::postAndWait(const LLSD& event, const LLEventPumpOrPumpName& requestPump,
const LLEventPumpOrPumpName& replyPump, const LLSD& replyPumpNamePath) const LLEventPumpOrPumpName& replyPump, const LLSD& replyPumpNamePath)
{ {
// declare the future // declare the future
boost::dcoroutines::future<LLSD> future(LLCoros::get_self()); boost::dcoroutines::future<LLSD> future(LLCoros::get_self());
// make a callback that will assign a value to the future, and listen on // make a callback that will assign a value to the future, and listen on
// the specified LLEventPump with that callback // the specified LLEventPump with that callback
std::string listenerName(LLEventDetail::listenerNameForCoro()); std::string listenerName(listenerNameForCoro());
LLTempBoundListener connection( LLTempBoundListener connection(
replyPump.getPump().listen(listenerName, replyPump.getPump().listen(listenerName,
voidlistener(boost::dcoroutines::make_callback(future)))); voidlistener(boost::dcoroutines::make_callback(future))));
...@@ -160,7 +170,7 @@ LLSD postAndWait(const LLSD& event, const LLEventPumpOrPumpName& requestPump, ...@@ -160,7 +170,7 @@ LLSD postAndWait(const LLSD& event, const LLEventPumpOrPumpName& requestPump,
// If replyPumpNamePath is non-empty, store the replyPump name in the // If replyPumpNamePath is non-empty, store the replyPump name in the
// request event. // request event.
LLSD modevent(event); LLSD modevent(event);
LLEventDetail::storeToLLSDPath(modevent, replyPumpNamePath, replyPump.getPump().getName()); storeToLLSDPath(modevent, replyPumpNamePath, replyPump.getPump().getName());
LL_DEBUGS("lleventcoro") << "postAndWait(): coroutine " << listenerName LL_DEBUGS("lleventcoro") << "postAndWait(): coroutine " << listenerName
<< " posting to " << requestPump.getPump().getName() << " posting to " << requestPump.getPump().getName()
<< LL_ENDL; << LL_ENDL;
...@@ -176,7 +186,7 @@ LLSD postAndWait(const LLSD& event, const LLEventPumpOrPumpName& requestPump, ...@@ -176,7 +186,7 @@ LLSD postAndWait(const LLSD& event, const LLEventPumpOrPumpName& requestPump,
LLSD value; LLSD value;
{ {
// instantiate Suspending to manage the "current" coroutine // instantiate Suspending to manage the "current" coroutine
LLCoros::Suspending suspended; llcoro::Suspending suspended;
value = *future; value = *future;
} // destroy Suspending as soon as we're back } // destroy Suspending as soon as we're back
LL_DEBUGS("lleventcoro") << "postAndWait(): coroutine " << listenerName LL_DEBUGS("lleventcoro") << "postAndWait(): coroutine " << listenerName
...@@ -185,72 +195,6 @@ LLSD postAndWait(const LLSD& event, const LLEventPumpOrPumpName& requestPump, ...@@ -185,72 +195,6 @@ LLSD postAndWait(const LLSD& event, const LLEventPumpOrPumpName& requestPump,
return value; return value;
} }
LLEventWithID postAndWait2(const LLSD& event,
const LLEventPumpOrPumpName& requestPump,
const LLEventPumpOrPumpName& replyPump0,
const LLEventPumpOrPumpName& replyPump1,
const LLSD& replyPump0NamePath,
const LLSD& replyPump1NamePath)
{
// declare the future
boost::dcoroutines::future<LLEventWithID> future(LLCoros::get_self());
// either callback will assign a value to this future; listen on
// each specified LLEventPump with a callback
std::string name(LLEventDetail::listenerNameForCoro());
LLTempBoundListener connection0(
replyPump0.getPump().listen(name + "a",
LLEventDetail::wfeoh(boost::dcoroutines::make_callback(future), 0)));
LLTempBoundListener connection1(
replyPump1.getPump().listen(name + "b",
LLEventDetail::wfeoh(boost::dcoroutines::make_callback(future), 1)));
// skip the "post" part if requestPump is default-constructed
if (requestPump)
{
// If either replyPumpNamePath is non-empty, store the corresponding
// replyPump name in the request event.
LLSD modevent(event);
LLEventDetail::storeToLLSDPath(modevent, replyPump0NamePath,
replyPump0.getPump().getName());
LLEventDetail::storeToLLSDPath(modevent, replyPump1NamePath,
replyPump1.getPump().getName());
LL_DEBUGS("lleventcoro") << "postAndWait2(): coroutine " << name
<< " posting to " << requestPump.getPump().getName()
<< ": " << modevent << LL_ENDL;
requestPump.getPump().post(modevent);
}
LL_DEBUGS("lleventcoro") << "postAndWait2(): coroutine " << name
<< " about to wait on LLEventPumps " << replyPump0.getPump().getName()
<< ", " << replyPump1.getPump().getName() << LL_ENDL;
// trying to dereference ("resolve") the future makes us wait for it
LLEventWithID value;
{
// instantiate Suspending to manage "current" coroutine
LLCoros::Suspending suspended;
value = *future;
} // destroy Suspending as soon as we're back
LL_DEBUGS("lleventcoro") << "postAndWait(): coroutine " << name
<< " resuming with (" << value.first << ", " << value.second << ")"
<< LL_ENDL;
// returning should disconnect both connections
return value;
}
} // anonymous
void llcoro::yield()
{
// By viewer convention, we post an event on the "mainloop" LLEventPump
// each iteration of the main event-handling loop. So waiting for a single
// event on "mainloop" gives us a one-frame yield.
waitForEventOn("mainloop");
}
LLSD llcoro::postAndWait(const LLSD& event, const LLEventPumpOrPumpName& requestPump,
const LLEventPumpOrPumpName& replyPump, const LLSD& replyPumpNamePath)
boost::dcoroutines::future<LLSD> future(llcoro::get_self());
std::string listenerName(listenerNameForCoro());
storeToLLSDPath(modevent, replyPumpNamePath, replyPump.getPump().getName());
llcoro::Suspending suspended;
namespace namespace
{ {
...@@ -298,15 +242,56 @@ WaitForEventOnHelper<LISTENER> wfeoh(const LISTENER& listener, int discriminator ...@@ -298,15 +242,56 @@ WaitForEventOnHelper<LISTENER> wfeoh(const LISTENER& listener, int discriminator
namespace llcoro namespace llcoro
{ {
LLEventWithID postAndWait2(const LLSD& event,
const LLEventPumpOrPumpName& requestPump,
const LLEventPumpOrPumpName& replyPump0,
const LLEventPumpOrPumpName& replyPump1,
const LLSD& replyPump0NamePath,
const LLSD& replyPump1NamePath)
{
// declare the future
boost::dcoroutines::future<LLEventWithID> future(LLCoros::get_self()); boost::dcoroutines::future<LLEventWithID> future(LLCoros::get_self());
// either callback will assign a value to this future; listen on
// each specified LLEventPump with a callback
std::string name(listenerNameForCoro()); std::string name(listenerNameForCoro());
LLTempBoundListener connection0(
replyPump0.getPump().listen(name + "a",
wfeoh(boost::dcoroutines::make_callback(future), 0))); wfeoh(boost::dcoroutines::make_callback(future), 0)));
LLTempBoundListener connection1(
replyPump1.getPump().listen(name + "b",
wfeoh(boost::dcoroutines::make_callback(future), 1))); wfeoh(boost::dcoroutines::make_callback(future), 1)));
// skip the "post" part if requestPump is default-constructed
if (requestPump)
{
// If either replyPumpNamePath is non-empty, store the corresponding
// replyPump name in the request event.
LLSD modevent(event);
storeToLLSDPath(modevent, replyPump0NamePath, storeToLLSDPath(modevent, replyPump0NamePath,
replyPump0.getPump().getName()); replyPump0.getPump().getName());
storeToLLSDPath(modevent, replyPump1NamePath, storeToLLSDPath(modevent, replyPump1NamePath,
replyPump1.getPump().getName()); replyPump1.getPump().getName());
LL_DEBUGS("lleventcoro") << "postAndWait2(): coroutine " << name
<< " posting to " << requestPump.getPump().getName()
<< ": " << modevent << LL_ENDL;
requestPump.getPump().post(modevent);
}
LL_DEBUGS("lleventcoro") << "postAndWait2(): coroutine " << name
<< " about to wait on LLEventPumps " << replyPump0.getPump().getName()
<< ", " << replyPump1.getPump().getName() << LL_ENDL;
// trying to dereference ("resolve") the future makes us wait for it
LLEventWithID value;
{
// instantiate Suspending to manage "current" coroutine
llcoro::Suspending suspended; llcoro::Suspending suspended;
value = *future;
} // destroy Suspending as soon as we're back
LL_DEBUGS("lleventcoro") << "postAndWait(): coroutine " << name
<< " resuming with (" << value.first << ", " << value.second << ")"
<< LL_ENDL;
// returning should disconnect both connections
return value;
}
LLSD errorException(const LLEventWithID& result, const std::string& desc) LLSD errorException(const LLEventWithID& result, const std::string& desc)
{ {
// If the result arrived on the error pump (pump 1), instead of // If the result arrived on the error pump (pump 1), instead of
......
...@@ -101,8 +101,6 @@ VoidListener<LISTENER> voidlistener(const LISTENER& listener) ...@@ -101,8 +101,6 @@ VoidListener<LISTENER> voidlistener(const LISTENER& listener)
return VoidListener<LISTENER>(listener); return VoidListener<LISTENER>(listener);
} }
* each distinct coroutine instance.
std::string listenerNameForCoro();
/** /**
* Yield control from a coroutine for one "mainloop" tick. If your coroutine * Yield control from a coroutine for one "mainloop" tick. If your coroutine
* runs without suspending for nontrivial time, sprinkle in calls to this * runs without suspending for nontrivial time, sprinkle in calls to this
...@@ -309,13 +307,13 @@ class LL_COMMON_API LLCoroEventPump ...@@ -309,13 +307,13 @@ class LL_COMMON_API LLCoroEventPump
*/ */
LLSD wait() LLSD wait()
{ {
return ::waitForEventOn(mPump); return llcoro::waitForEventOn(mPump);
} }
LLSD postAndWait(const LLSD& event, const LLEventPumpOrPumpName& requestPump, LLSD postAndWait(const LLSD& event, const LLEventPumpOrPumpName& requestPump,
const LLSD& replyPumpNamePath=LLSD()) const LLSD& replyPumpNamePath=LLSD())
{ {
return ::postAndWait(event, requestPump, mPump, replyPumpNamePath); return llcoro::postAndWait(event, requestPump, mPump, replyPumpNamePath);
} }
private: private:
...@@ -354,19 +352,19 @@ class LL_COMMON_API LLCoroEventPumps ...@@ -354,19 +352,19 @@ class LL_COMMON_API LLCoroEventPumps
/// waitForEventOn(either of our two LLEventPumps) /// waitForEventOn(either of our two LLEventPumps)
LLEventWithID wait() LLEventWithID wait()
{ {
return waitForEventOn(mPump0, mPump1); return llcoro::waitForEventOn(mPump0, mPump1);
} }
/// errorException(wait()) /// errorException(wait())
LLSD waitWithException() LLSD waitWithException()
{ {
return errorException(wait(), std::string("Error event on ") + getName1()); return llcoro::errorException(wait(), std::string("Error event on ") + getName1());
} }
/// errorLog(wait()) /// errorLog(wait())
LLSD waitWithLog() LLSD waitWithLog()
{ {
return errorLog(wait(), std::string("Error event on ") + getName1()); return llcoro::errorLog(wait(), std::string("Error event on ") + getName1());
} }
LLEventWithID postAndWait(const LLSD& event, LLEventWithID postAndWait(const LLSD& event,
...@@ -374,7 +372,7 @@ class LL_COMMON_API LLCoroEventPumps ...@@ -374,7 +372,7 @@ class LL_COMMON_API LLCoroEventPumps
const LLSD& replyPump0NamePath=LLSD(), const LLSD& replyPump0NamePath=LLSD(),
const LLSD& replyPump1NamePath=LLSD()) const LLSD& replyPump1NamePath=LLSD())
{ {
return postAndWait2(event, requestPump, mPump0, mPump1, return llcoro::postAndWait2(event, requestPump, mPump0, mPump1,
replyPump0NamePath, replyPump1NamePath); replyPump0NamePath, replyPump1NamePath);
} }
...@@ -383,7 +381,7 @@ class LL_COMMON_API LLCoroEventPumps ...@@ -383,7 +381,7 @@ class LL_COMMON_API LLCoroEventPumps
const LLSD& replyPump0NamePath=LLSD(), const LLSD& replyPump0NamePath=LLSD(),
const LLSD& replyPump1NamePath=LLSD()) const LLSD& replyPump1NamePath=LLSD())
{ {
return errorException(postAndWait(event, requestPump, return llcoro::errorException(postAndWait(event, requestPump,
replyPump0NamePath, replyPump1NamePath), replyPump0NamePath, replyPump1NamePath),
std::string("Error event on ") + getName1()); std::string("Error event on ") + getName1());
} }
...@@ -393,7 +391,7 @@ class LL_COMMON_API LLCoroEventPumps ...@@ -393,7 +391,7 @@ class LL_COMMON_API LLCoroEventPumps
const LLSD& replyPump0NamePath=LLSD(), const LLSD& replyPump0NamePath=LLSD(),
const LLSD& replyPump1NamePath=LLSD()) const LLSD& replyPump1NamePath=LLSD())
{ {
return errorLog(postAndWait(event, requestPump, return llcoro::errorLog(postAndWait(event, requestPump,
replyPump0NamePath, replyPump1NamePath), replyPump0NamePath, replyPump1NamePath),
std::string("Error event on ") + getName1()); std::string("Error event on ") + getName1());
} }
......
...@@ -264,8 +264,7 @@ namespace tut ...@@ -264,8 +264,7 @@ namespace tut
// Construct the coroutine instance that will run explicit_wait. // Construct the coroutine instance that will run explicit_wait.
// Pass the ctor a callable that accepts the coroutine_type::self // Pass the ctor a callable that accepts the coroutine_type::self
// param passed by the library. // param passed by the library.
boost::dcoroutines::coroutine<void()> boost::dcoroutines::coroutine<void()> coro(explicit_wait);
coro(explicit_wait);
// Start the coroutine // Start the coroutine
coro(std::nothrow); coro(std::nothrow);
// When the coroutine waits for the event pump, it returns here. // When the coroutine waits for the event pump, it returns here.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment