Add thread-safety to various scripting methods
This commit is contained in:
@@ -647,6 +647,8 @@ ScriptingTypeInitializer::ScriptingTypeInitializer(BinaryModule* module, const S
|
||||
module->TypeNameToTypeIndex[fullname] = TypeIndex;
|
||||
}
|
||||
|
||||
CriticalSection BinaryModule::Locker;
|
||||
|
||||
BinaryModule::BinaryModulesList& BinaryModule::GetModules()
|
||||
{
|
||||
static BinaryModulesList modules;
|
||||
|
||||
@@ -60,6 +60,9 @@ public:
|
||||
/// <returns>The found binary module or null if missing.</returns>
|
||||
static BinaryModule* GetModule(const StringAnsiView& name);
|
||||
|
||||
// Global scripting locker for cached data.
|
||||
static CriticalSection Locker;
|
||||
|
||||
protected:
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -35,7 +35,6 @@ private:
|
||||
mutable int32 _hasCachedClasses : 1;
|
||||
|
||||
mutable ClassesDictionary _classes;
|
||||
CriticalSection _locker;
|
||||
|
||||
int32 _reloadCount;
|
||||
StringAnsi _name;
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "Engine/Scripting/ManagedCLR/MException.h"
|
||||
#include "Engine/Scripting/ManagedCLR/MUtils.h"
|
||||
#include "Engine/Scripting/Scripting.h"
|
||||
#include "Engine/Scripting/BinaryModule.h"
|
||||
#include "Engine/Engine/Globals.h"
|
||||
#include "Engine/Profiler/ProfilerCPU.h"
|
||||
#include "Engine/Threading/Threading.h"
|
||||
@@ -636,7 +637,7 @@ const MAssembly::ClassesDictionary& MAssembly::GetClasses() const
|
||||
#if TRACY_ENABLE
|
||||
ZoneText(*_name, _name.Length());
|
||||
#endif
|
||||
ScopeLock lock(_locker);
|
||||
ScopeLock lock(BinaryModule::Locker);
|
||||
if (_hasCachedClasses)
|
||||
return _classes;
|
||||
ASSERT(_classes.IsEmpty());
|
||||
@@ -939,6 +940,9 @@ MMethod* MClass::GetMethod(const char* name, int32 numParams) const
|
||||
|
||||
const Array<MMethod*>& MClass::GetMethods() const
|
||||
{
|
||||
if (_hasCachedMethods)
|
||||
return _methods;
|
||||
ScopeLock lock(BinaryModule::Locker);
|
||||
if (_hasCachedMethods)
|
||||
return _methods;
|
||||
|
||||
@@ -972,6 +976,9 @@ MField* MClass::GetField(const char* name) const
|
||||
|
||||
const Array<MField*>& MClass::GetFields() const
|
||||
{
|
||||
if (_hasCachedFields)
|
||||
return _fields;
|
||||
ScopeLock lock(BinaryModule::Locker);
|
||||
if (_hasCachedFields)
|
||||
return _fields;
|
||||
|
||||
@@ -1016,6 +1023,9 @@ MProperty* MClass::GetProperty(const char* name) const
|
||||
|
||||
const Array<MProperty*>& MClass::GetProperties() const
|
||||
{
|
||||
if (_hasCachedProperties)
|
||||
return _properties;
|
||||
ScopeLock lock(BinaryModule::Locker);
|
||||
if (_hasCachedProperties)
|
||||
return _properties;
|
||||
|
||||
@@ -1038,6 +1048,9 @@ const Array<MProperty*>& MClass::GetProperties() const
|
||||
|
||||
const Array<MClass*>& MClass::GetInterfaces() const
|
||||
{
|
||||
if (_hasCachedInterfaces)
|
||||
return _interfaces;
|
||||
ScopeLock lock(BinaryModule::Locker);
|
||||
if (_hasCachedInterfaces)
|
||||
return _interfaces;
|
||||
|
||||
@@ -1073,6 +1086,9 @@ MObject* MClass::GetAttribute(const MClass* monoClass) const
|
||||
|
||||
const Array<MObject*>& MClass::GetAttributes() const
|
||||
{
|
||||
if (_hasCachedAttributes)
|
||||
return _attributes;
|
||||
ScopeLock lock(BinaryModule::Locker);
|
||||
if (_hasCachedAttributes)
|
||||
return _attributes;
|
||||
|
||||
|
||||
@@ -1044,7 +1044,7 @@ const MAssembly::ClassesDictionary& MAssembly::GetClasses() const
|
||||
const StringAnsiView monoImageName(mono_image_get_name(_monoImage));
|
||||
ZoneText(*monoImageName, monoImageName.Length());
|
||||
#endif
|
||||
ScopeLock lock(_locker);
|
||||
ScopeLock lock(BinaryModule::Locker);
|
||||
if (_hasCachedClasses)
|
||||
return _classes;
|
||||
ASSERT(_classes.IsEmpty());
|
||||
|
||||
Reference in New Issue
Block a user