summaryrefslogtreecommitdiff
path: root/indra/llcommon
AgeCommit message (Collapse)Author
2020-03-25DRTVWR-476: Add Sync class to help with stepwise coroutine tests.Nat Goodspeed
Sync is specifically intended for test programs. It is based on an LLScalarCond<int>. The idea is that each of two coroutines can watch for the other to get a chance to run, indicated by incrementing the wrapped int and notifying the wrapped condition_variable. This is less hand-wavy than calling llcoro::suspend() and hoping that the other routine will have had a chance to run. Use Sync in lleventcoro_test.cpp. Also refactor lleventcoro_test.cpp so that instead of a collection of static data requiring a clear() call at start of each individual test function, the relevant data is all part of the test_data struct common to all test functions. Make the helper coroutine functions members of test_data too. Introduce llcoro::logname(), a convenience function to log the name of the currently executing coroutine or "main" if in the thread's main coroutine.
2020-03-25DRTVWR-476: Improve llprocess_test.cpp diagnostic output.Nat Goodspeed
If the test<1>() child process terminates with nonzero rc, also report any stdout/stderr it might have emitted first.
2020-03-25DRTVWR-476: Add basic tests for LLCond.Nat Goodspeed
2020-03-25DRTVWR-476: Fix first round of compile errors.Nat Goodspeed
2020-03-25DRTVWR-476: Fix convert(F32Milliseconds)Nat Goodspeed
2020-03-25DRTVWR-476: Review response: remove wait_until() methods and LLDate.Nat Goodspeed
2020-03-25DRTVWR-476: Review response: support LLDate and llunits.h durations.Nat Goodspeed
Also introduce value_type typedef.
2020-03-25DRTVWR-476: WIP: Untested preliminary implementation of LLCond.Nat Goodspeed
LLCond encapsulates the usage patterns required to properly use condition_variable. We also provide LLScalarCond, LLBoolCond and LLOneShotCond.
2020-03-25DRTVWR-476: Fix confusing comment in LLProcess::handle_status().Nat Goodspeed
The global replace in changeset bd80903cf987 was a bit too sweeping: a comment mentioning the OS function wait() (which exists) was inadvertently changed to talk about an OS function suspend() (which does not).
2020-03-25[DRTVWR-476] - fix compiler errors 32 bit windows buildAnchor
2020-03-25[DRTVWR-476] - update cef, fix mergeAnchor
2020-03-25[DRTVWR-476] - temporary skip failing llinstancetracker tests to get TC ↵Anchor
build working
2020-03-25[DRTVWR-476] - suppress dbghelp.h compiler warningsAnchor
2020-03-25Removed unnecessary disconnection of listener in postAndSuspendSetupBrad Kittenbrink
2020-03-25Switched LL_ERRS to LL_WARNS for case where promise is fulfilled multiple ↵Brad Kittenbrink
times by multiple events.
2020-03-25Fixed variadic macro usage in LL_ERRS_IF and LL_WARNS_IF and improved ↵Brad Kittenbrink
LLError::shouldLogToStderr() behavior under xcode.
2020-03-25Attempt to close LLEventCoro's LLBoundListener connection when promise has ↵Brad Kittenbrink
been fulfilled.
2020-03-25Added try/catch closer to source of error so LL_ERRS fatal can be more ↵Brad Kittenbrink
useful for debugging;
2020-03-25[DRTVWR-476] - disable dbghelp.h warningsAnchor
2020-03-25[DRTVWR-476] - compile error fixAnchor
2020-03-25SL-793: Fix lllogin_test.cpp for new LLCoros implementation.Nat Goodspeed
Delete the test for SRV timeout: lllogin no longer issues an SRV query. That test only confuses the test program without exercising any useful paths in production code. As with other tests dating from the previous LLCoros implementation, we need a few llcoro::suspend() calls sprinkled in so that a fiber marked ready -- by fulfilling the future for which it is waiting -- gets a chance to run. Clear LLEventPumps between test functions.
2020-03-25SL-793: Add LL_PRETTY_FUNCTION macro wrapping __PRETTY_FUNCTION__Nat Goodspeed
which is, of course, different in Visual Studio (__FUNCSIG__). Use LL_PRETTY_FUNCTION in DEBUG output instead of plain __FUNCTION__.
2020-03-25SL-793: Add LLEventPumps::clear() method to disconnect all listeners.Nat Goodspeed
This is like the existing reset() method, except that reset() is specifically intended for shutdown: it disables every existing LLEventPump in such a way that it cannot be subsequently reused. (The original idea was to disconnect listeners in DLLs unloaded at shutdown.) clear() forcibly disconnects all existing listeners, but leaves LLEventPumps ready for reuse. This is useful (e.g.) for test programs to reset the state of LLEventPumps between individual test functions.
2020-03-25SL-793: Use Boost.Fiber instead of the "dcoroutine" library.Nat Goodspeed
Longtime fans will remember that the "dcoroutine" library is a Google Summer of Code project by Giovanni P. Deretta. He originally called it "Boost.Coroutine," and we originally added it to our 3p-boost autobuild package as such. But when the official Boost.Coroutine library came along (with a very different API), and we still needed the API of the GSoC project, we renamed the unofficial one "dcoroutine" to allow coexistence. The "dcoroutine" library had an internal low-level API more or less analogous to Boost.Context. We later introduced an implementation of that internal API based on Boost.Context, a step towards eliminating the GSoC code in favor of official, supported Boost code. However, recent versions of Boost.Context no longer support the API on which we built the shim for "dcoroutine." We started down the path of reimplementing that shim using the current Boost.Context API -- then realized that it's time to bite the bullet and replace the "dcoroutine" API with the Boost.Fiber API, which we've been itching to do for literally years now. Naturally, most of the heavy lifting is in llcoros.{h,cpp} and lleventcoro.{h,cpp} -- which is good: the LLCoros layer abstracts away most of the differences between "dcoroutine" and Boost.Fiber. The one feature Boost.Fiber does not provide is the ability to forcibly terminate some other fiber. Accordingly, disable LLCoros::kill() and LLCoprocedureManager::shutdown(). The only known shutdown() call was in LLCoprocedurePool's destructor. We also took the opportunity to remove postAndSuspend2() and its associated machinery: FutureListener2, LLErrorEvent, errorException(), errorLog(), LLCoroEventPumps. All that dual-LLEventPump stuff was introduced at a time when the Responder pattern was king, and we assumed we'd want to listen on one LLEventPump with the success handler and on another with the error handler. We have never actually used that in practice. Remove associated tests, of course. There is one other semantic difference that necessitates patching a number of tests: with "dcoroutine," fulfilling a future IMMEDIATELY resumes the waiting coroutine. With Boost.Fiber, fulfilling a future merely marks the fiber as ready to resume next time the scheduler gets around to it. To observe the test side effects, we've inserted a number of llcoro::suspend() calls -- also in the main loop. For a long time we retained a single unit test exercising the raw "dcoroutine" API. Remove that. Eliminate llcoro_get_id.{h,cpp}, which provided llcoro::get_id(), which was a hack to emulate fiber-local variables. Since Boost.Fiber has an actual API for that, remove the hack. In fact, use (new alias) LLCoros::local_ptr for LLSingleton's dependency tracking in place of llcoro::get_id(). In CMake land, replace BOOST_COROUTINE_LIBRARY with BOOST_FIBER_LIBRARY. We don't actually use the Boost.Coroutine for anything (though there exist plausible use cases).
2020-03-25DRTVWR-476: Explicitly cast 64-bit NaN constant to F32 as needed.Nat Goodspeed
VS 2017 was complaining about truncating the value.
2020-03-25DRTVWR-476: Eliminate unnecessary typedefs from struct, enum decls.Nat Goodspeed
With VS 2017, these produced fatal warnings.
2020-03-25DRTVWR-476: Eliminate snprintf_hack::snprintf(). Use MS snprintf().Nat Goodspeed
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/snprintf-snprintf-snprintf-l-snwprintf-snwprintf-l?view=vs-2017 "Beginning with the UCRT in Visual Studio 2015 and Windows 10, snprintf is no longer identical to _snprintf. The snprintf function behavior is now C99 standard compliant." In other words, VS 2015 et ff. snprintf() now promises to nul-terminate the buffer even in the overflow case, which is what snprintf_hack::snprintf() was for. This removal was motivated by ambiguous-call errors generated by VS 2017 for library snprintf() vs. snprintf_hack::snprintf().
2020-03-25SL-11216: Allow llsd::drill() to accept LLSD() as (empty) path.Nat Goodspeed
Before this change, you had to literally pass LLSD::emptyArray() to get no-op behavior.
2020-03-25SL-11216: Introduce generic LLStoreListener<T> to capture event data.Nat Goodspeed
LLStoreListener is an adapter initialized with a reference to an LLEventPump on which to listen, a reference to a variable into which to store received data, and an optional llsd::drill() path to extract desired data from each event received on the subject LLEventPump. In effect, LLStoreListener is like a miniature LLEventAPI whose only operation is to store to its destination variable.
2020-03-25SL-11216: Add llsd::drill() function to drill into an LLSD blob.Nat Goodspeed
We include both const and non-const overloads. The latter returns LLSD&, so you can assign to the located element. In fact we already implemented the non-const logic in a less public form as storeToLLSDPath() in lleventcoro.cpp. Reimplement the latter to use the new llsd::drill() function.
2020-03-25SL-11216: Remove LLSingletonBase::cleanupAll().Nat Goodspeed
Remove call from LLAppViewer::cleanup(). Instead, make each LLSingleton<T>::deleteSingleton() call cleanupSingleton() just before destroying the instance. Since deleteSingleton() is not a destructor, it's fine to call cleanupSingleton() from there; and since deleteAll() calls deleteSingleton() on every remaining instance, the former cleanupAll() functionality has been subsumed into deleteAll(). Since cleanupSingleton() is now called at exactly one point in the instance's lifetime, we no longer need a bool indicating whether it has been called. The previous protocol of calling cleanupAll() before deleteAll() implemented a two-phase cleanup strategy for the application. That is no longer needed. Moreover, the cleanupAll() / deleteAll() sequence created a time window during which individual LLSingleton<T> instances weren't usable (to the extent that their cleanupSingleton() methods released essential resources) but still existed -- so a getInstance() call would return the crippled instance rather than recreating it. Remove cleanupAll() calls from tests; adjust to new order of expected side effects: instead of A::cleanupSingleton(), B::cleanupSingleton(), ~A(), ~B(), now we get A::cleanupSingleton(), ~A(), B::cleanupSingleton(), ~B().
2020-03-25DRTVWR-494: Get initialized LLMutexes for very early log calls.Nat Goodspeed
Use function-static LLMutex instances instead of module-static instances, since some log calls are evidently issued before we get around to initializing llerror.cpp module-static variables.
2020-03-25DRTVWR-494: Move most LLSingleton cleanup back to destructorNat Goodspeed
instead of deleteSingleton(). Specifically, clear static SingletonData and remove the instance from the MasterList in the destructor. Empirically, some consumers are manually deleting LLSingleton instances, instead of calling deleteSingleton(). If deleteSingleton() handles cleanup rather than the destructor, we're left with dangling pointers in the Master List. We don't also call cleanupSingleton() from the destructor because only deleteSingleton() promises to call cleanupSingleton(). Hopefully whoever is directly deleting an LLSingleton subclass instance isn't relying on cleanupSingleton().
2020-03-25DRTVWR-494: LLParamSingleton::initParamSingleton() returns reference.Nat Goodspeed
2020-03-25DRTVWR-494: LLParamSingleton::initParamSingleton() on main thread.Nat Goodspeed
When calling LLParamSingleton::initParamSingleton() on a secondary thread, use LLMainThreadTask::dispatch() to construct the instance on the main thread -- as with LLSingleton::getInstance().
2020-03-25DRTVWR-494: LLParamSingleton<T>::initParamSingleton() now returns T*.Nat Goodspeed
So does LLLockedSingleton<T>::construct().
2020-03-25DRTVWR-494: Dispatch all LLSingleton construction to the main thread.Nat Goodspeed
Given the viewer's mutually-dependent LLSingletons, given that different threads might simultaneously request different LLSingletons from such a chain of circular dependencies, the key to avoiding deadlock is to serialize all LLSingleton construction on one thread: the main thread. Add comments to LLSingleton::getInstance() explaining the problem and the solution. Recast LLSingleton's static SingletonData to use LockStatic. Instead of using Locker, and simply trusting that every reference to sData is within the dynamic scope of a Locker instance, LockStatic enforces that: you can only access SingletonData members via LockStatic. Reorganize the switch in getInstance() to group the CONSTRUCTING error, the INITIALIZING/INITIALIZED success case, and the DELETED/UNINITIALIZED construction case. When [re]constructing an instance, on the main thread, retain the lock and call constructSingleton() (and capture_dependency()) directly. On a secondary thread, unlock LockStatic and use LLMainThreadTask::dispatch() to call getInstance() on the main thread. Since we might end up enqueuing multiple such tasks, it's important to let getInstance() notice when the instance has already been constructed and simply return the existing pointer. Add loginfos() method, sibling to logerrs(), logwarns() and logdebugs(). Produce loginfos() messages when dispatching to the main thread, when actually running on the main thread and when resuming the suspended requesting thread. Make deleteSingleton() manage all associated state, instead of delegating some of that work to ~LLSingleton(). Now, within LockStatic, extract the instance pointer and set state to DELETED; that lets subsequent code, which retains the only remaining pointer to the instance, remove the master-list entry, call the subclass cleanupSingleton() and destructor without needing to hold the lock. In fact, entirely remove ~LLSingleton(). Import LLSingletonBase::cleanup_() method to wrap the call to subclass cleanupSingleton() in try/catch. Remove cleanupAll() calls from llsingleton_test.cpp, and reorder the success cases to reflect the fact that T::cleanupSingleton() is called immediately before ~T() for each distinct LLSingleton subclass T. When getInstance() on a secondary thread dispatches to the main thread, it necessarily unlocks its LockStatic lock. But an LLSingleton dependency chain strongly depends on the function stack on which getInstance() is invoked -- the task dispatched to the main thread doesn't know the dependencies tracked on the requesting thread stack. So, once the main thread delivers the instance pointer, the requesting thread captures its own dependencies for that instance. Back in the requesting thread, obtaining the current EInitState to pass to capture_dependencies() would have required relocking LockStatic. Instead, I've convinced myself that (a) capture_dependencies() only wanted to know EInitState to produce an error for CONSTRUCTING, and (b) in CONSTRUCTING state, we never get as far as capture_dependencies() because getInstance() produces an error first. Eliminate the EInitState parameter from all capture_dependencies() methods. Remove the LLSingletonBase::capture_dependency() stanza that tested EInitState. Make the capture_dependencies() variants that accepted LockStatic instead accept LLSingletonBase*. That lets getInstance(), in the LLMainThreadTask case, pass the newly-returned instance pointer. For symmetry, make pop_initializing() accept LLSingletonBase* as well, instead of accepting LockStatic and extracting mInstance.
2020-03-25DRTVWR-494: Fix VS LLError::Log::demangle() vulnerability.Nat Goodspeed
The Windows implementation of demangle() assumed that a "mangled" class name produced by typeid(class).name() always starts with the prefix "class ", checked for that and removed it. If the mangled name didn't start with that prefix, it would emit a debug message and return the full name. When the class in question is actually a struct, the prefix is "struct " instead. But when demangle() was being called before logging had been fully initialized, the debug message remarking that it didn't start with "class " crashed. Look for either "class " or "struct " prefix. Remove whichever is found and return the rest of the name. If neither is found, only log if logging is available.
2020-03-25DRTVWR-494: Remove LLMainThreadTask::dispatch(LockStatic&, ...)Nat Goodspeed
Monty's code review reveals that conflating dispatch() with [un]lock functionality is inconsistent and unnecessary.
2020-03-25DRTVWR-494: Document LLMainThreadTask class.Nat Goodspeed
2020-03-25DRTVWR-494: Add LLMainThreadTask to perform work on the main thread.Nat Goodspeed
If already running on the main thread, LLMaintThreadTask simply runs the work inline. Otherwise it queues it for the main thread using LLEventTimer, using std::future to retrieve the result.
2020-03-25DRTVWR-494: VS 2013 can't yet handle variadic llmake().Nat Goodspeed
2020-03-25DRTVWR-494: Use std::thread::id for LLThread::currentID().Nat Goodspeed
LLThread::currentID() used to return a U32, a distinct unsigned value incremented by explicitly constructing LLThread or by calling LLThread:: registerThreadID() early in a thread launched by other means. The latter imposed an unobvious requirement on new code based on std::thread. Using std::thread::id instead delegates to the compiler/library the problem of distinguishing threads launched by any means. Change lots of explicit U32 declarations. Introduce LLThread::id_t typedef to avoid having to run around fixing uses again if we later revisit this decision. LLMutex, which stores an LLThread::id_t, wants a distinguished value meaning NO_THREAD, and had an enum with that name. But as std::thread::id promises that the default-constructed value is distinct from every valid value, NO_THREAD becomes unnecessary and goes away. Because LLMutex now stores LLThread::id_t instead of U32, make llmutex.h #include "llthread.h" instead of the other way around. This makes LLMutex an incomplete type within llthread.h, so move LLThread::lockData() and unlockData() to the .cpp file. Similarly, remove llrefcount.h's #include "llmutex.h" to break circularity; instead forward-declare LLMutex. It turns out that a number of source files assumed that #include "llthread.h" would get the definition for LLMutex. Sprinkle #include "llmutex.h" as needed. In the SAFE_SSL code in llcorehttp/httpcommon.cpp, there's an ssl_thread_id() callback that returns an unsigned long to the SSL library. When LLThread:: currentID() was U32, we could simply return that. But std::thread::id is very deliberately opaque, and can't be reinterpret_cast to unsigned long. Fortunately it can be hashed because std::hash is specialized with that type.
2020-03-25DRTVWR-494: Move LL_ERRS out of llinstancetracker.h header file.Nat Goodspeed
Add a namespaced free function in .cpp file to report LL_ERRS as needed. Per code review, use a more indicative namespace name.
2020-03-25DRTVWR-494: Move explanatory comments from LLSingleton to LockStatic.Nat Goodspeed
2020-03-25DRTVWR-494: Add llmake_heap(); update to variadic llmake().Nat Goodspeed
2020-03-25DRTVWR-494: Extract LockStatic as a standalone template class.Nat Goodspeed
The pattern of requiring a lock to permit *any* access to a static instance of something seems generally useful. Break out lockstatic.h; recast LLInstanceTracker to use it. Moving LockStatic to an external template class instead of a nested class in LLInstanceTrackerBase leaves LLInstanceTrackerBase pretty empty. Get rid of it. And *that* means we can move the definition of the StaticData used by each LLInstanceTracker specialization into the class itself, rather than having to define it beforehand in namespace LLInstanceTrackerStuff.
2020-03-25DRTVWR-494: Streamline LLSingleton state machine.Nat Goodspeed
The CONSTRUCTED state was only briefly set between constructSingleton() and finishInitializing(). But as no consumer code is executed between setting CONSTRUCTED and setting INITIALIZING, it was impossible to reach the switch statement in either getInstance() method in state CONSTRUCTED. So there was no point in state CONSTRUCTED. Remove it. With CONSTRUCTED gone, we only ever call finishInitializing() right after constructSingleton(). Merge finishInitializing() into constructSingleton().
2020-03-25DRTVWR-494: Encapsulate redundant VS boilerplate around <mutex>.Nat Goodspeed
2020-03-25DRTVWR-494: Streamline LLEventTimer::updateClass().Nat Goodspeed
No need to capture a separate list of completed LLEventTimer instances to delete after the primary loop, since at this point we're looping over a snapshot and can directly delete each completed timer.