mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-05-07 19:27:45 +00:00
more watchdog shenanigans
This commit is contained in:
parent
6f457a4e7e
commit
f9b5e0e874
3 changed files with 20 additions and 2 deletions
|
@ -70,9 +70,9 @@ foreach(_scriptDir ${children})
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
add_custom_command(TARGET "script_${_name}" POST_BUILD
|
add_custom_command(TARGET "script_${_name}" POST_BUILD
|
||||||
COMMAND ${CMAKE_COMMAND} -E touch ${SCRIPT_POSTBUILD_DIR}/$<TARGET_FILE:${ScriptTargetName}>_LOCK
|
COMMAND ${CMAKE_COMMAND} -E touch ${SCRIPT_POSTBUILD_DIR}$<TARGET_FILE_NAME:${ScriptTargetName}>_LOCK
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${ScriptTargetName}> ${SCRIPT_POSTBUILD_DIR}
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${ScriptTargetName}> ${SCRIPT_POSTBUILD_DIR}
|
||||||
COMMAND ${CMAKE_COMMAND} -E remove ${SCRIPT_POSTBUILD_DIR}/$<TARGET_FILE:${ScriptTargetName}>_LOCK
|
COMMAND ${CMAKE_COMMAND} -E remove ${SCRIPT_POSTBUILD_DIR}$<TARGET_FILE_NAME:${ScriptTargetName}>_LOCK
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@ namespace Sapphire::Scripting
|
||||||
|
|
||||||
bool NativeScriptMgr::loadScript( const std::string& path )
|
bool NativeScriptMgr::loadScript( const std::string& path )
|
||||||
{
|
{
|
||||||
|
std::scoped_lock lock( m_mutex );
|
||||||
|
|
||||||
auto module = m_loader.loadModule( path );
|
auto module = m_loader.loadModule( path );
|
||||||
if( !module )
|
if( !module )
|
||||||
return false;
|
return false;
|
||||||
|
@ -47,11 +49,15 @@ namespace Sapphire::Scripting
|
||||||
|
|
||||||
const std::string NativeScriptMgr::getModuleExtension()
|
const std::string NativeScriptMgr::getModuleExtension()
|
||||||
{
|
{
|
||||||
|
std::scoped_lock lock( m_mutex );
|
||||||
|
|
||||||
return m_loader.getModuleExtension();
|
return m_loader.getModuleExtension();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NativeScriptMgr::unloadScript( const std::string& name )
|
bool NativeScriptMgr::unloadScript( const std::string& name )
|
||||||
{
|
{
|
||||||
|
std::scoped_lock lock( m_mutex );
|
||||||
|
|
||||||
auto info = m_loader.getScriptInfo( name );
|
auto info = m_loader.getScriptInfo( name );
|
||||||
if( !info )
|
if( !info )
|
||||||
return false;
|
return false;
|
||||||
|
@ -61,6 +67,8 @@ namespace Sapphire::Scripting
|
||||||
|
|
||||||
bool NativeScriptMgr::unloadScript( ScriptInfo* info )
|
bool NativeScriptMgr::unloadScript( ScriptInfo* info )
|
||||||
{
|
{
|
||||||
|
std::scoped_lock lock( m_mutex );
|
||||||
|
|
||||||
for( auto& script : info->scripts )
|
for( auto& script : info->scripts )
|
||||||
{
|
{
|
||||||
m_scripts[ script->getType() ].erase( script->getId() );
|
m_scripts[ script->getType() ].erase( script->getId() );
|
||||||
|
@ -83,11 +91,14 @@ namespace Sapphire::Scripting
|
||||||
if( !unloadScript( info ) )
|
if( !unloadScript( info ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
std::scoped_lock lock( m_mutex );
|
||||||
m_scriptLoadQueue.push( libPath );
|
m_scriptLoadQueue.push( libPath );
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeScriptMgr::processLoadQueue()
|
void NativeScriptMgr::processLoadQueue()
|
||||||
{
|
{
|
||||||
|
std::scoped_lock lock( m_mutex );
|
||||||
|
|
||||||
std::vector< std::string > deferredLoads;
|
std::vector< std::string > deferredLoads;
|
||||||
|
|
||||||
while( !m_scriptLoadQueue.empty() )
|
while( !m_scriptLoadQueue.empty() )
|
||||||
|
@ -110,11 +121,15 @@ namespace Sapphire::Scripting
|
||||||
|
|
||||||
void NativeScriptMgr::findScripts( std::set< Sapphire::Scripting::ScriptInfo* >& scripts, const std::string& search )
|
void NativeScriptMgr::findScripts( std::set< Sapphire::Scripting::ScriptInfo* >& scripts, const std::string& search )
|
||||||
{
|
{
|
||||||
|
std::scoped_lock lock( m_mutex );
|
||||||
|
|
||||||
return m_loader.findScripts( scripts, search );
|
return m_loader.findScripts( scripts, search );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NativeScriptMgr::isModuleLoaded( const std::string& name )
|
bool NativeScriptMgr::isModuleLoaded( const std::string& name )
|
||||||
{
|
{
|
||||||
|
std::scoped_lock lock( m_mutex );
|
||||||
|
|
||||||
return m_loader.isModuleLoaded( name );
|
return m_loader.isModuleLoaded( name );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include "ScriptLoader.h"
|
#include "ScriptLoader.h"
|
||||||
|
|
||||||
|
@ -29,6 +30,8 @@ namespace Sapphire::Scripting
|
||||||
*/
|
*/
|
||||||
std::queue< std::string > m_scriptLoadQueue;
|
std::queue< std::string > m_scriptLoadQueue;
|
||||||
|
|
||||||
|
std::recursive_mutex m_mutex;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Used to unload a script
|
* @brief Used to unload a script
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue