Osiris_UnloadModule Purpose: Given a module id, it will decrement the reference count to that module by one. If the reference count becomes zero, the module will be unloaded from memory.
| 792 | // Given a module id, it will decrement the reference count to that module by one. If the reference |
| 793 | // count becomes zero, the module will be unloaded from memory. |
| 794 | void Osiris_UnloadModule(int module_id) { |
| 795 | if (module_id < 0 || module_id >= MAX_LOADED_MODULES) |
| 796 | return; |
| 797 | if (OSIRIS_loaded_modules[module_id].flags & OSIMF_INUSE) { |
| 798 | // the module is in use |
| 799 | if (Show_osiris_debug) { |
| 800 | mprintf(0, "OSIRIS: Decrementing reference count for module (%s)\n", OSIRIS_loaded_modules[module_id].module_name); |
| 801 | } |
| 802 | OSIRIS_loaded_modules[module_id].reference_count--; |
| 803 | |
| 804 | ASSERT(OSIRIS_loaded_modules[module_id].reference_count >= 0); |
| 805 | |
| 806 | if (OSIRIS_loaded_modules[module_id].reference_count <= 0) { |
| 807 | |
| 808 | if (OSIRIS_loaded_modules[module_id].flags & OSIMF_NOUNLOAD) { |
| 809 | |
| 810 | ASSERT(!(OSIRIS_loaded_modules[module_id].flags & OSIMF_LEVEL)); // level modules cannot be set static |
| 811 | ASSERT(!(OSIRIS_loaded_modules[module_id].flags & OSIMF_DLLELSEWHERE)); // mission modules cannot be set static |
| 812 | |
| 813 | // do not unload this module, due to the forced stay in memory |
| 814 | mprintf(0, "OSIRIS: Module (%s) staying in memory due to static flag\n", |
| 815 | OSIRIS_loaded_modules[module_id].module_name); |
| 816 | } else { |
| 817 | // time to unload this module |
| 818 | if (Show_osiris_debug) { |
| 819 | mprintf(0, "OSIRIS: Module (%s) reference count is at 0, unloading\n", |
| 820 | OSIRIS_loaded_modules[module_id].module_name); |
| 821 | } |
| 822 | Osiris_FreeModule(module_id); |
| 823 | } |
| 824 | } |
| 825 | } else { |
| 826 | mprintf(0, "OSIRIS: Trying to unload a module (%d) that is not in use!\n", module_id); |
| 827 | Int3(); |
| 828 | } |
| 829 | } |
| 830 | |
| 831 | // Osiris_UnloadLevelModule |
| 832 | // Purpose: |
no test coverage detected