MCPcopy Create free account
hub / github.com/MayaPosch/NymphCast / Discard

Method Discard

src/server/angelscript/angelscript/source/as_module.cpp:101–136  ·  view source on GitHub ↗

interface

Source from the content-addressed store, hash-verified

99
100// interface
101void asCModule::Discard()
102{
103 // Reset the global variables already so that no object in the global variables keep the module alive forever.
104 // If any live object tries to access the global variables during clean up they will fail with a script exception,
105 // so the application must keep that in mind before discarding a module.
106 CallExit();
107
108 // Keep a local copy of the engine pointer, because once the module is moved do the discarded
109 // pile, it is possible that another thread might discard it while we are still in here. So no
110 // further access to members may be done after that
111 asCScriptEngine *engine = m_engine;
112
113 // Instead of deleting the module immediately, move it to the discarded pile
114 // This will turn it invisible to the application, yet keep it alive until all
115 // external references to its entities have been released.
116 ACQUIREEXCLUSIVE(engine->engineRWLock);
117 if( engine->lastModule == this )
118 engine->lastModule = 0;
119 engine->scriptModules.RemoveValue(this);
120 engine->discardedModules.PushLast(this);
121 RELEASEEXCLUSIVE(engine->engineRWLock);
122
123 // Allow the engine to go over the list of discarded modules to see what can be cleaned up at this moment.
124 // Don't do this if the engine is already shutting down, as it will be done explicitly by the engine itself with error reporting
125 if( !engine->shuttingDown )
126 {
127 if( engine->ep.autoGarbageCollect )
128 engine->GarbageCollect();
129 else
130 {
131 // GarbageCollect calls DeleteDiscardedModules, so no need
132 // to call it again if we already called GarbageCollect
133 engine->DeleteDiscardedModules();
134 }
135 }
136}
137
138// interface
139void *asCModule::SetUserData(void *data, asPWORD type)

Callers 4

ExecuteScriptFunction · 0.80
ShutDownAndReleaseMethod · 0.80
GetModuleMethod · 0.80
DiscardModuleMethod · 0.80

Calls 4

RemoveValueMethod · 0.80
PushLastMethod · 0.80
GarbageCollectMethod · 0.45

Tested by

no test coverage detected