Commit Graph

60 Commits (b3a549b8b5e01809b2dd2006d6bf92a7a4d6baf7)

Author SHA1 Message Date
Rye Mutt 70f455347e Introduce tracy instrumentation of mutex in LLSingleton, LLInstanceTracker and logging 2024-08-13 17:28:19 -04:00
Andrey Lihatskiy 1b68f71348 #824 Process source files in bulk: replace tabs with spaces, convert CRLF to LF, and trim trailing whitespaces as needed 2024-04-29 07:56:09 +03:00
Brad Linden 2f44377b3e Merge remote-tracking branch 'origin/main' into DRTVWR-559 2023-05-17 11:17:48 -07:00
Nat Goodspeed 00478b1e76 DRTVWR-559: Introduce LLInstanceTrackerSubclass mediator class.
Deriving your tracked class T from LLInstanceTracker<T> gives you
T::getInstance() et al. But what about a subclass S derived from T?
S::getInstance() still delivers a pointer to T, requiring explicit downcast.
And so on for other LLInstanceTracker methods.

Instead, derive S from LLInstanceTrackerSubclass<S, T>. This implies that S is
a grandchild class of T, but it also recasts the LLInstanceTracker methods to
deliver results for S rather than for T.
2022-12-09 13:16:39 -05:00
Nat Goodspeed 9522a0b7c1 DRTVWR-575: Fix llcommon assumptions that size_t fits in 4 bytes.
It's a little distressing how often we have historically coded S32 or U32 to
pass a length or index.

There are more such assumptions in other viewer subdirectories, but this is a
start.
2022-11-03 14:58:32 -04:00
Nat Goodspeed 2cb09dd4a8 SL-16024: Return shared_ptr from LLInstanceTracker::getInstance().
It feels wrong to return a dumb LLInstanceTracker subclass* from getInstance()
when we use std::shared_ptr and std::weak_ptr internally. But tweak consumers
to use 'auto' or LLInstanceTracker::ptr_t in case we later revisit this
decision.

We did add a couple get() calls where it's important to obtain a dumb pointer.
2021-10-07 11:53:45 -04:00
Nat Goodspeed 557a74fbdd DRTVWR-476: Adapt LLInstanceTracker::snapshot for VS limitations. 2020-03-25 19:24:25 -04:00
Nat Goodspeed 2506fd7882 DRTVWR-494: Move LL_ERRS out of llinstancetracker.h header file.
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-25 15:28:17 -04:00
Nat Goodspeed 1f7335fde3 DRTVWR-494: Extract LockStatic as a standalone template class.
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-25 15:28:17 -04:00
Nat Goodspeed b080b06b42 DRTVWR-494: Encapsulate redundant VS boilerplate around <mutex>. 2020-03-25 15:28:17 -04:00
Nat Goodspeed 7915dc4562 DRTVWR-494: Quiet VS warnings about its own <mutex> header. 2020-03-25 15:28:17 -04:00
Nat Goodspeed 9d5b897600 DRTVWR-494: Defend LLInstanceTracker against multi-thread usage.
The previous implementation went to some effort to crash if anyone attempted
to create or destroy an LLInstanceTracker subclass instance during traversal.
That restriction is manageable within a single thread, but becomes unworkable
if it's possible that a given subclass might be used on more than one thread.

Remove LLInstanceTracker::instance_iter, beginInstances(), endInstances(),
also key_iter, beginKeys() and endKeys(). Instead, introduce key_snapshot()
and instance_snapshot(), the only means of iterating over LLInstanceTracker
instances. (These are intended to resemble functions, but in fact the current
implementation simply presents the classes.) Iterating over a captured
snapshot defends against container modifications during traversal. The term
'snapshot' reminds the coder that a new instance created during traversal will
not be considered. To defend against instance deletion during traversal, a
snapshot stores std::weak_ptrs which it lazily dereferences, skipping on the
fly any that have expired.

Dereferencing instance_snapshot::iterator gets you a reference rather than a
pointer. Because some use cases want to delete all existing instances, add an
instance_snapshot::deleteAll() method that extracts the pointer. Those cases
used to require explicitly copying instance pointers into a separate
container; instance_snapshot() now takes care of that. It remains the caller's
responsibility to ensure that all instances of that LLInstanceTracker subclass
were allocated on the heap.

Replace unkeyed static LLInstanceTracker::getInstance(T*) -- which returned
nullptr if that instance had been destroyed -- with new getWeak() method
returning std::weak_ptr<T>. Caller must detect expiration of that weak_ptr.

Adjust tests accordingly.

Use of std::weak_ptr to detect expired instances requires engaging
std::shared_ptr in the constructor. We now store shared_ptrs in the static
containers (std::map for keyed, std::set for unkeyed).

Make LLInstanceTrackerBase a template parameterized on the type of the static
data it manages. For that reason, hoist static data class declarations out of
the class definitions to an LLInstanceTrackerStuff namespace.

Remove the static atomic sIterationNestDepth and its methods incrementDepth(),
decrementDepth() and getDepth(), since they were used only to forbid creation
and destruction during traversal.

Add a std::mutex to static data. Introduce an internal LockStatic class that
locks the mutex while providing a pointer to static data, making that the only
way to access the static data.

The LLINSTANCETRACKER_DTOR_NOEXCEPT macro goes away because we no longer
expect ~LLInstanceTracker() to throw an exception in test programs.
That affects LLTrace::StatBase as well as LLInstanceTracker itself.

Adapt consumers to the new LLInstanceTracker API.
2020-03-25 15:28:17 -04:00
andreykproductengine fa15830e02 SL-10291 Replace apr_atomic with standard C++11 functionality 2019-01-15 18:31:17 +02:00
Nat Goodspeed 8502b7dc47 DRTVWR-418: Work around VS2013's lack of __has_feature(). 2017-05-08 12:33:33 -04:00
Nat Goodspeed 322c4c6bec DRTVWR-418: Fix -std=c++11 llinstancetracker_test crash.
LLInstanceTracker<T> performs validation in ~LLInstanceTracker(). Normally
validation failure logs an error and terminates the program, which is fine. In
the test executable, though, we want validation failure to throw an exception
instead so we can catch it and continue testing other failure conditions. But
since destructors in C++11 are implicitly noexcept(true), that exception never
made it out of ~LLInstanceTracker(): it crashed the test program instead.
Declaring ~LLInstanceTracker() noexcept(false) solves that, allowing the test
program to catch the exception and continue.

However, if we unconditionally declare that, then every destructor anywhere in
the inheritance hierarchy for any LLInstanceTracker subclass must also be
noexcept(false)! That's way too pervasive, especially for functionality we
only need (or want) in a specific test executable.

Instead, make the CMake macros LL_ADD_PROJECT_UNIT_TESTS() and
LL_ADD_INTEGRATION_TEST() -- with which we define all viewer build-time tests
-- define two new command-line macros: LL_TEST=testname and LL_TEST_testname.
That way, preprocessor logic in a header file can detect whether it's being
compiled for production code or for a test executable.

(While at it, encapsulate in a new GET_OPT_SOURCE_FILE_PROPERTY() CMake macro
an ugly repetitive pattern. The builtin GET_SOURCE_FILE_PROPERTY() sets the
target variable to "NOTFOUND" -- rather than an empty string -- if the
specified property wasn't set. Every call to GET_SOURCE_FILE_PROPERTY() in
LL_ADD_PROJECT_UNIT_TESTS() was followed by a test for NOTFOUND and an
assignment to "". Wrap all that in a macro whose 'unset' value is "".)

Now llinstancetracker.h can detect when we're building the LLInstanceTracker
unit test executable, and *only then* declare ~LLInstanceTracker() as
noexcept(false). We #define LLINSTANCETRACKER_DTOR_NOEXCEPT to expand either
empty or noexcept(false), also detecting clang in C++11 mode. (It all works
fine without noexcept(false) until we turn on C++11 mode.)

We also use that macro for the StatBase class in lltrace.h. Turns out some of
the infrastructure headers required for tests in general, including the
LLInstanceTracker test, use LLInstanceTracker. Fortunately that appears to be
the only other class we must annotate this way for the LLInstanceTracker tests.
2017-05-08 09:09:22 -04:00
Oz Linden c8726aba30 remove execute permission from many files that should not have it 2015-11-10 09:48:56 -05:00
Richard Linden 7a91ec40aa SH-4626 FIX: [INTERESTING RC] Viewer randomly crashes when I click on links in IMs or group IMs 2013-11-20 16:21:03 -08:00
Richard Linden 391ac367d6 SH-4634 FIX Interesting: Viewer crashes when receiving teleport offer
renamed fast timers to have unique names, changes instance tracker to never allow duplicates
2013-11-19 17:40:44 -08:00
Richard Linden dc60a7564a SH-4577 WIP Interesting: viewer crashed when clicking a offline Conversation containing a shared object
potential fix by making instance tracker allow key collisions for LLToastNotifyPanel
changed assertion macro to use original unpreprocessed source code
renamed instance tracker behavior macros to use LL prefix
added RestoreCameraPosOnLogin setting to optionally restore old camera positioning behavior
2013-10-24 14:37:57 -07:00
Richard Linden 18aedf0241 fix for assert at runtime (reading stats from recording while it was active)
fix for bad values returns from getPeriodMin and getPeriodMax on count stats when no counts recorded
fix for gcc compile time error (typename ftw)
2013-10-17 19:18:53 -07:00
Richard Linden 1beaedacad moved root timer to global variable
added flag to LLInstanceTracker to allow multiple values per key
made StatType allow multiple values per key to eliminate block timer related crash
2013-10-17 14:23:56 -07:00
Richard Linden 80dfbbaacd merge from viewer-release 2013-10-08 11:59:24 -07:00
simon 3f5e6280db Tweak MAINT-3046 fix for faster remove_() performance 2013-08-26 14:16:28 -07:00
Graham Madarasz (Graham Linden) 19726783cd MAINT-3046 make LLNotifications clear out vecs of LLNotificationChannelPtr so singleton cleanup doesn't do things it really ought not do 2013-08-23 14:44:46 -07:00
Richard Linden a2e22732f1 Summer cleaning - removed a lot of llcommon dependencies to speed up build times
consolidated most indra-specific constants in llcommon under indra_constants.h
fixed issues with operations on mixed unit types (implicit and explicit)
made LL_INFOS() style macros variadic in order to subsume other logging methods
such as ll_infos
added optional tag output to error recorders
2013-07-30 19:13:45 -07:00
Richard Linden 075a7bcc98 SH-4297 WIP interesting: viewer-interesting starts loading cached scene late
dependency cleanup - removed a lot of unecessary includes
2013-07-18 15:09:45 -07:00
Richard Linden 0a96b47663 merge with viewer-release 2013-06-05 19:05:43 -07:00
simon ee2fce8790 Merge downstream code and viewer-beta 2013-05-09 14:10:45 -07:00
simon 87ba85eaab diff -r 59c7bed66dfd indra/llcommon/lleventapi.h 2013-04-24 09:35:38 -07:00
Richard Linden 62c8844414 SH-3931 WIP Interesting: Add graphs to visualize scene load metrics
added ExtendablePeriodicRecording
and ability to append periodic recordings to each other
2013-04-21 23:10:03 -07:00
Richard Linden cc7d92147c SH-4080 WIP interesting: random crash on Mac
removed unused dll support from llinstancetracker as it didn't appear to be thread safe
2013-04-19 20:09:00 -07:00
simon 6742d90d39 Some minor cleanups while hunting crashes. Reviewed by Kelly 2013-04-17 11:17:46 -07:00
Graham Madarasz bf6182daa8 Update Mac and Windows breakpad builds to latest 2013-03-29 07:50:08 -07:00
Simon Linden d5561a1ada Merge in viewer-beta to get CHUI code 2013-03-19 16:20:53 -07:00
Graham Madarasz (Graham) 3849ee79c3 Added missing enums for integ test usage 2013-03-01 14:28:48 -08:00
Graham Madarasz (Graham) 93eaccae6f Modify LLInstanceTracker to avoid using a map of strings to find a map of foo to find some pointers 2013-02-28 15:35:14 -08:00
Richard Linden 3fd640a6e3 SH-3468 WIP add memory tracking base class
fixed crash on exit by making LLInstanceTracker iterators use atomic iterator
nesting count for thread safety
2012-12-23 12:27:25 -08:00
Richard Linden 819adb5eb4 SH-3405 FIX convert existing stats to lltrace system
final removal of remaining LLStat code
2012-11-01 00:26:44 -07:00
Todd Stinson 3e038cd71b Pull and merge from ssh://hg@bitbucket.org/lindenlab/viewer-release. 2012-07-27 12:53:54 -07:00
Nat Goodspeed c0318d1bf9 Make LLInstanceTracker<T, T*>::getInstance(T*) validate passed T*.
For the T* specialization (no string, or whatever, key), the original
getInstance() method simply returned the passed-in T* value. It was defined,
as the comments noted, for completeness of the analogy with the keyed
LLInstanceTracker specialization.
It turns out, though, that getInstance(T*) can still be useful to ask whether
the T* you have in hand still references a valid T instance. Support that
usage.
2012-02-27 11:50:47 -05:00
Richard Linden 2fa1c42aad CHUI-51 WIP notifications routig code cleanup
phase 2, removal of extraneous signaling in favor of llnotificationchannels
made notificationchannels work better with overrides and lifetime managed
by creator
2012-03-29 23:48:29 -07:00
Richard Nelson 3b4f4d34ea fixed one crash on exit 2011-10-17 18:28:48 -07:00
Nat Goodspeed 286342f705 STORM-1541: Change llassert() to llassert_always(): unit tests expect.
Now that we have unit tests that require assertion failure if you try to
delete an LLInstanceTracker subclass instance with an iterator loose, having
llassert() "sometimes" compile away (whimsically, depending on platform as
well as build type!) makes those tests fail. Use llassert_always() instead.
2011-09-07 18:03:25 -04:00
Nat Goodspeed 8c6f752982 STORM-1541: Hoist LLInstanceTracker::getMap_() to base getStatic().
Generalize the notion of getting some chunk of "static" storage: introduce
LLInstanceTrackerBase::getStatic() template method. Define StaticData struct
containing the InstanceMap (or InstanceSet, for that specialization) along
with the S32 that caused the VS2010 linker so much grief. Completely eliminate
that S32 as an actual class-static member, qualifying all references with the
struct returned by getStatic().
In LLInstanceTrackerBase::getInstances(), use one std::map lookup instead of
three.
2011-09-06 22:07:49 -04:00
Nat Goodspeed bf906ac926 Re-add 3 llinstancetracker tests disabled by changeset 1ead63777bf6.
Fix LLInstanceTracker::key_iter constructor param; accepting
InstanceMap::iterator by non-const reference relied on Microsoft extension
that accepts non-const reference to an rvalue. Given typical iterator
implementation, simply accept by value instead, which makes gcc happy too.
2011-08-24 09:08:42 -04:00
Aaron Stone 5eec3a4e51 Swap typename and const. 2011-07-27 16:03:01 -07:00
Richard Nelson 61a7726611 another potential gcc fix 2011-07-27 15:58:52 -07:00
Richard Nelson 061e9efd3e broken operator= semantics for instance tracker iterators 2011-07-27 13:11:09 -07:00
Richard Nelson 7a43d38eaa another fix for build 2011-07-27 10:25:45 -07:00
Richard Nelson 75d2382dc3 fixed build 2011-07-26 18:54:07 -07:00