Commit Graph

97 Commits

Author SHA1 Message Date
Rye Mutt
8561af1f84 Add abseil hashmaps and use in texture list, also fix bugs in texture list insertion 2019-09-28 19:03:49 -04:00
Drake Arconis
2f2e1fbe8f Major breaking changes 2016-01-16 08:05:47 -05:00
Shyotl
1c627317ec No longer include llerrorlegacy.h. Updated llstl to include deletion utilites. 2015-06-19 03:54:20 -05:00
Shyotl
f8927a8a11 Merge branch 'master' of https://Shyotl@bitbucket.org/LightDrake/singularityviewer-internal.git into FMODStudio
Conflicts:
	indra/llcommon/llsingleton.h
2014-11-22 22:19:44 -06:00
Shyotl
37c7a72505 Implement boost and stl mutexes and atomics. 2014-09-07 17:18:55 -05:00
Aleric Inglewood
b1e406731d Merge remote-tracking branch 'singu/master' 2014-08-25 18:39:46 +02:00
Aleric Inglewood
8c6d51cb71 No longer support DEBUG_CURLIO when libcwd isn't installed. 2014-08-25 17:58:45 +02:00
Shyotl
541021f29c Fix relwithdebug. 2014-08-20 17:42:48 -05:00
Shyotl
0e86b696c5 Added more verbose statemachine debug output. 2014-08-18 00:54:01 -05:00
Aleric Inglewood
e523aadc4a Do not destruct running Responders upon viewer exit.
This hopefully saves some crashes.
2013-12-29 21:50:10 +01:00
Aleric Inglewood
53e26d4909 Compile fix for -DDEBUG_CURLIO
Since that fakes the libcwd macros, this is needed to compile
the recent change that allows to only turn on debugging output
for certain statemachine objects when DEBUG_CURLIO is defined,
but libcwd is not used (CWDEBUG is undefined).
2013-11-21 01:28:16 +01:00
Aleric Inglewood
aa5bc7bc25 Compile fix (libcwd) 2013-10-27 15:14:11 +01:00
Aleric Inglewood
811f670199 AIStateMachine fixes.
Things (one debug code only) that don't happen currently,
but that I ran into with AIMultiGrid.
2013-10-16 00:30:28 +02:00
Aleric Inglewood
09708b6318 Added AICondition.
AICondition is like AIThreadSafeSimpleDC (it is derived from it),
and wraps some variable, protecting it with a builtin mutex.

While in a statemachine, one can call wait(condition) to make
the state machine go idle, and call condition.signal() to
wake it (or another) up again.

While normally a condition variable is used as follows:

condition.lock();
while (!whatwerewaitingfor)
{
  condition.wait();
}
// Here the condition is guaranteed to be true and we're
// still in the critical area of the mutex.
condition.unlock();

where the thread blocks in wait(), the statemachine actually
returns CPU to the thread (the AIEngine), so there is no
while loop involved, and our wait() doesn't even unlock
the mutex: that happens because the state machine returns:

condition_wat condition_w(condition);		// Lock condition.
if (!condition_w->whatwerewaitingfor())		// The variable(s) involved can only be accessed when condition is locked.
{
  wait(condition);				// Causes the state machine to go idle. This does not block.
  break;					// Leave scope (unlock condition) and return to the mainloop - but as idle state machine.
}
// Here the condition is guaranteed to be true and we're
// still in the critical area of the condition variable.

In this case, when condition.signal() is called, the thread
doesn't return from wait() with a locked mutex - but the
statemachine executes the same state again, and enters from
the top: locking the condition and doing the test again,
just like it would be when this was a while loop.
2013-10-15 22:30:53 +02:00
Aleric Inglewood
9114f04ef6 Add AIStateMachine::yield_if_not
This can be used to switch to a specific engine.
If the state machine is not running in the passed engine,
then it performs a yield to that engine, otherwise it keeps
running. Hence, putting this at the top of a state
guarantees that it runs in that engine.

For example:

    case FrontEnd_done:
    {
      // Unlock must be called by the same thread that locked it.
      if (yield_if_not(&gStateMachineThreadEngine))
      {
        break;
      }
      // Here we are running in gStateMachineThreadEngine.
    ...
2013-10-15 22:30:16 +02:00
Aleric Inglewood
9db6bc0557 Add AIStateMachine::mSMDebug
The patch is exclusively libcwd related.

Turns off output from statemachines to dc::statemachine by default.
Allows to turn on the debug output on a per statemachine basis (at
compile time).
2013-10-15 22:29:52 +02:00
Aleric Inglewood
6f733f6f62 Documentation update. 2013-08-02 13:04:56 +02:00
Aleric Inglewood
dc265ff9a1 Attempt to fix issue 848
https://code.google.com/p/singularity-viewer/issues/detail?id=848

If advance_state is called, then the state is NOT changed (only
sub_state_w->advance_state is set), but sub_state_w->skip_idle is set to
true in order to ignore the next call to idle (if the state machine is
already in the middle of executing a state). Therefore, this assert
would trigger. The solution is to not trigger when skip_idle is set.
2013-05-29 02:37:48 +02:00
Aleric Inglewood
b6f6dfbe99 Fix french assert.
Fixes a possible ASSERT(!(need_new_run && !mYieldEngine &&
sub_state_r->run_state == run_state)).

When over all multiplex_impl functions and this is the only case that I
found where it could return without changing the state and without
calling either idle() or yield().
2013-05-27 02:15:28 +02:00
Aleric Inglewood
74102e4964 Force running AIMeshUpload in the main thread.
I don't think it did -- but theoretically it could run in any thread
the way it was.
2013-05-17 15:07:45 +02:00
Aleric Inglewood
8688f6e772 Detect infinite loop. 2013-05-17 15:07:45 +02:00
Aleric Inglewood
ca66f44c0e Obscure bug fix. Not relevant in the current viewer code. 2013-05-17 15:07:32 +02:00
Aleric Inglewood
1d2b3d3dc9 Derived classes may access this. 2013-04-28 03:31:16 +02:00
Aleric Inglewood
0b86c9eec1 Merge remote-tracking branch 'singu/master'
Conflicts:
	indra/newview/llviewerwindow.cpp

c_str() dropped out (50f03d83c0).
Added it back.
2013-04-20 05:18:27 +02:00
Aleric Inglewood
e12aaa3f5f Compile warning fix. 2013-04-20 05:06:30 +02:00
Aleric Inglewood
9fb3fe21bc Compile warning fix. 2013-04-20 05:03:17 +02:00
Aleric Inglewood
e0aa3489f8 Fix for AIStateMachineThread (LLThreadSafeRefCount: deleting non-zero reference)
This fixes
https://code.google.com/p/singularity-viewer/issues/detail?id=736

The problem was that we need to keep the 'user' derived THREAD_IMPL
alive in the thread, and therefore used an LLPointer<THREAD_IMPL>
(as base class of AIStateMachineThread<THREAD_IMPL>), and therefore
THREAD_IMPL, derived from AIThreadImpl had to be derived from
LLThreadSafeRefCount. However, AIStateMachineThread<THREAD_IMPL> also
needed to be a statemachine of itself and is derived from
AIStateMachineThreadBase derived from AIStateMachine which is ALSO
derived from LLThreadSafeRefCount - that in this case wasn't really
needed. An attempt to deactive it by calling ref() from the constructor
of AIStateMachineThreadBase failed on the fact that LLThreadSafeRefCount
insists that its ref count mRef is exactly zero when it is being
deleted.

The chosen solution is to remove the ref count from AIThreadImpl and use
the LLThreadSafeRefCount base class of AIStateMachineThreadBase. The
result is that not only THREAD_IMPL, but also the state machine object
is kept alive, but that doesn't seem like a problem.

Thus, instead of passing a AIThreadImpl* to
AIStateMachineThreadBase::Thread, we now pass a
AIStateMachineThreadBase* to it to keep the whole of the
AIStateMachineThread<THREAD_IMPL> object alive, which has a THREAD_IMPL
as member now. This member then can be accessed through a virtual
function impl(). Another result of this change is that the 'user' (the
class derived from AIThreadImpl, THREAD_IMPL) now has to deal with the
LLPointer, and use LLPointer<AIStateMachineThread<THREAD_IMPL> >
instead of just AIStateMachineThread<THREAD_IMPL> and also allocate
this object himself. The access from there then changes into a -> to
access the state machine (as opposed to a .) and ->thread_impl() to
access the THREAD_IMPL object (as opposed to a ->).
2013-04-20 04:28:23 +02:00
Latif Khalifa
adb535421d Fixed build with DEBUG_CURLIO defined 2013-04-13 22:08:19 +02:00
Aleric Inglewood
c14601f7c2 Avoid assertion in ~AIStateMachine upon viewer exit.
Force the state to bs_killed before clearing the list of statemachines
in AIEngine::flush().
2013-03-28 03:01:27 +01:00
Aleric Inglewood
779f697ffb Fix yield_ms().
This fixes
https://code.google.com/p/singularity-viewer/issues/detail?id=714

The problem was a typo in AIStateMachine::sleep, >= should have been <=
which caused a state machine that uses yield_ms() to never run anymore
when next run it already should have run again. AIFilePicker is the only
state machine that currently uses yield_ms and I hadn't spotted this
because I don't have plugin messages on by default which made my viewer
just that much faster that it the yield never expired the first run
already (causing it to expire immediately).

The rest of the changes in this commit are just minor improvements /
conformation to the EXAMPLE_CODE in aistatemachine.cpp.
2013-03-26 23:30:04 +01:00
Aleric Inglewood
df93ebb8f6 Bug fix for AIStateMachine.
When a state machine is aborted after it switched to bs_initialize,
but before it executed initialize_impl(), then we should set the
state back to bs_reset and abort cleanly by switching to bs_killed
and then handle that. Before the state was set to bs_abort, resulting
in calling abort_impl(), finish_impl(), the call back and unref()
for an not initialized state machine! (detected by the assert that
makes sure that ref()/unref() are called in balance).
2013-03-09 04:20:54 +01:00
Aleric Inglewood
50caf98cd6 Dont enter AIStateMachine::multiplex recursively. 2013-03-08 16:58:25 +01:00
Aleric Inglewood
e8ef74156a Added print_statemachine_diagnostics
The responder name is now cached in LLURLRequest
(ResponderBase::getName() must return a string literal).
The run time (in the main thread) per state machine is now accumulated
in AIStateMachine (instead of AIEngine::QueueElement).
When AIStateMachine::mainloop runs longer than StateMachineMaxTime
then a warning is printed that now includes the time spent in the
slowest state machine (that frame) and (if it is a LLURLRequest)
what the corresponding responder is. Also the total accumulated run
time of that state machine is printed.

From this is can be concluded that the only responder currently
regularly holding up the main thread is LLMeshLODResponder (mostly 30 to
100 ms, but with spikes in the 1 to 2 second range some times).
2013-03-08 01:50:02 +01:00
Aleric Inglewood
4e0269b3d0 Bug fix in debug code. 2013-03-07 05:23:23 +01:00
Aleric Inglewood
58c07f8054 Don't return from abort() until the current execution, if any, finished. 2013-03-07 04:20:17 +01:00
Aleric Inglewood
380eec10fb Initialize mDebugRefCalled on restart. 2013-03-07 02:23:23 +01:00
Aleric Inglewood
b9b5f13624 Run HTTPGetResponder in any thread.
This fixes a bug where unref() was called when a state machine was
aborted before it reached bs_initialized. Debug code was added to detect
errors related to that.

In order to run HTTPGetResponder in any thread, I needed direct access
to LLHTTPClient::request, so I had to move that to the header file,
and therefore had to move ERequestAction from LLURLRequest to
LLHTTPClient to avoid include problems.

With this, textures are fetched with no latency: call to
LLHTTPClient::request runs all the way till the state machine is idle
(AICurlEasyRequestStateMachine_waitAdded). There is small delay till the
curl thread wakes up, which then processes the request and opens the url
etc. When the transaction is finished, it calls
AIStateMachine::advance_state(AICurlEasyRequestStateMachine_removed_after_finished)
which subsequently doesn't return until the state machine is completely
finished (bs_killed). The LLURLRequest isn't deleted yet at that point
because the AITimer of the LLURLRequest runs in the main thread: it is
aborted, but only the next time the main thread state engines run that
is deleted and the timer keeps an LLPointer to it's parent, the
LLURLRequest, so only then the LLURLRequest object is destructed. This
however has nothing to do with the texture-bandwidth loop.
2013-03-07 01:52:21 +01:00
Aleric Inglewood
c4dceaf3e9 Rewrite of AIStateMachine, version 2. 2013-03-06 03:26:43 +01:00
Aleric Inglewood
4851cc174e Revert "Work in progress"
This reverts commit ef35aa7954
because it contained too much wrong things that I won't be
using. I'll re-commit stuff from it after that that I do
want to keep.
2013-02-23 20:00:13 +01:00
Aleric Inglewood
ef35aa7954 Work in progress
This work extends AIStateMachine to run multiplex() in the thread
that calls run(), cont() or set_state(). Note that all three
eventually call locked_cont(), so thats where multiplex() is called
from. Calling multiplex() means "running the state machine", as in
"calling multiplex_impl".

Currently only LLURLRequest uses this feature, and then only
for the HTTPGetResponder, and well only for the initializing,
start up and normal finish states.

A current/remaining problem is that we run into a situation where
the curl thread runs a statemachine to it's finish and kills it,
while the main thread is also 'running' it and tries to call
multiplex while the statemachine isn't running anymore.
2013-02-20 23:29:38 +01:00
Aleric Inglewood
9203b24eb9 Remove AIStateMachineThreadBase* argument from AIThreadImpl constructor.
Also removes the use of 'this' to initialize base classes, which led to
a compiler warning on vs2010.
2013-01-30 03:44:02 +01:00
Aleric Inglewood
7ba0b6482c Fix example code. 2013-01-29 20:49:53 +01:00
Aleric Inglewood
e99175444f Bike fix: Always set mStatus to STOPPED 2013-01-29 20:45:08 +01:00
Aleric Inglewood
d5ed31ca9b Allow passing a name to underlaying LLThread in debug mode. 2013-01-29 20:44:14 +01:00
Aleric Inglewood
ebac80b5b7 Fix termination race condition. 2013-01-27 20:52:21 +01:00
Aleric Inglewood
c528a15e95 Added AIStateMachineThread 2013-01-26 19:19:09 +01:00
Aleric Inglewood
a1fa43850b Comment fixes. 2013-01-25 16:09:34 +01:00
Aleric Inglewood
e88c39b090 AIStateMachine::flush can only make statemachines idle.
As idle statemachines aren't in any list, it's not possible
(without adding that list) to delete them. I don't think
that there are any active statemachines left at the end
of flush anyway, but killing them doesn't much sense if
we can't get them all: there will always be statemachines
left: those that were idle at the moment the viewer was
quit.
2012-11-07 01:53:12 +01:00
Aleric Inglewood
a1f5e6ba43 Rename AICurlResponderBufferEvents to AIBufferedCurlEasyRequestEvents
Since we changed CurlResponderBuffer to be derived from CurlEasyRequest
and therefore changed it's name to BufferedCurlEasyRequest, we should
also rename AICurlResponderBufferEvents to
AIBufferedCurlEasyRequestEvents.
This commit also fixes C++ comment in several places to reflex the
previous name change.
2012-11-07 01:49:45 +01:00
Aleric Inglewood
7549b471c3 Moved curl stuff from indra/aistatemachine to indra/llmessage. 2012-10-31 18:51:52 +01:00