interface
| 99 | |
| 100 | // interface |
| 101 | void 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 |
| 139 | void *asCModule::SetUserData(void *data, asPWORD type) |
no test coverage detected