clang-format on everything.

This commit is contained in:
Kevin Bentley
2024-04-16 12:56:40 -06:00
parent 142052a67d
commit c6640cc631
909 changed files with 652028 additions and 707349 deletions

View File

@@ -28,7 +28,6 @@
andreas@angelcode.com
*/
//
// as_memory.cpp
//
@@ -47,117 +46,100 @@ BEGIN_AS_NAMESPACE
// By default we'll use the standard memory management functions
asALLOCFUNC_t userAlloc = malloc;
asFREEFUNC_t userFree = free;
asFREEFUNC_t userFree = free;
extern "C"
{
extern "C" {
int asSetGlobalMemoryFunctions(asALLOCFUNC_t allocFunc, asFREEFUNC_t freeFunc)
{
userAlloc = allocFunc;
userFree = freeFunc;
int asSetGlobalMemoryFunctions(asALLOCFUNC_t allocFunc, asFREEFUNC_t freeFunc) {
userAlloc = allocFunc;
userFree = freeFunc;
return 0;
return 0;
}
int asResetGlobalMemoryFunctions()
{
asThreadCleanup();
int asResetGlobalMemoryFunctions() {
asThreadCleanup();
userAlloc = malloc;
userFree = free;
userAlloc = malloc;
userFree = free;
return 0;
return 0;
}
} // extern "C"
asCMemoryMgr::asCMemoryMgr()
{
asCMemoryMgr::asCMemoryMgr() {}
asCMemoryMgr::~asCMemoryMgr() { FreeUnusedMemory(); }
void asCMemoryMgr::FreeUnusedMemory() {
// It's necessary to protect the scriptNodePool from multiple
// simultaneous accesses, as the parser is used by several methods
// that can be executed simultaneously.
ENTERCRITICALSECTION(cs);
int n;
for (n = 0; n < (signed)scriptNodePool.GetLength(); n++)
userFree(scriptNodePool[n]);
scriptNodePool.Allocate(0, false);
LEAVECRITICALSECTION(cs);
// The engine already protects against multiple threads
// compiling scripts simultaneously so this pool doesn't have
// to be protected again.
for (n = 0; n < (signed)byteInstructionPool.GetLength(); n++)
userFree(byteInstructionPool[n]);
byteInstructionPool.Allocate(0, false);
}
asCMemoryMgr::~asCMemoryMgr()
{
FreeUnusedMemory();
}
void *asCMemoryMgr::AllocScriptNode() {
ENTERCRITICALSECTION(cs);
void asCMemoryMgr::FreeUnusedMemory()
{
// It's necessary to protect the scriptNodePool from multiple
// simultaneous accesses, as the parser is used by several methods
// that can be executed simultaneously.
ENTERCRITICALSECTION(cs);
if (scriptNodePool.GetLength()) {
void *tRet = scriptNodePool.PopLast();
LEAVECRITICALSECTION(cs);
return tRet;
}
int n;
for( n = 0; n < (signed)scriptNodePool.GetLength(); n++ )
userFree(scriptNodePool[n]);
scriptNodePool.Allocate(0, false);
LEAVECRITICALSECTION(cs);
LEAVECRITICALSECTION(cs);
// The engine already protects against multiple threads
// compiling scripts simultaneously so this pool doesn't have
// to be protected again.
for( n = 0; n < (signed)byteInstructionPool.GetLength(); n++ )
userFree(byteInstructionPool[n]);
byteInstructionPool.Allocate(0, false);
}
void *asCMemoryMgr::AllocScriptNode()
{
ENTERCRITICALSECTION(cs);
if( scriptNodePool.GetLength() )
{
void *tRet = scriptNodePool.PopLast();
LEAVECRITICALSECTION(cs);
return tRet;
}
LEAVECRITICALSECTION(cs);
#if defined(AS_DEBUG)
return ((asALLOCFUNCDEBUG_t)(userAlloc))(sizeof(asCScriptNode), __FILE__, __LINE__);
#if defined(AS_DEBUG)
return ((asALLOCFUNCDEBUG_t)(userAlloc))(sizeof(asCScriptNode), __FILE__, __LINE__);
#else
return userAlloc(sizeof(asCScriptNode));
return userAlloc(sizeof(asCScriptNode));
#endif
}
void asCMemoryMgr::FreeScriptNode(void *ptr)
{
ENTERCRITICALSECTION(cs);
void asCMemoryMgr::FreeScriptNode(void *ptr) {
ENTERCRITICALSECTION(cs);
// Pre allocate memory for the array to avoid slow growth
if( scriptNodePool.GetLength() == 0 )
scriptNodePool.Allocate(100, 0);
// Pre allocate memory for the array to avoid slow growth
if (scriptNodePool.GetLength() == 0)
scriptNodePool.Allocate(100, 0);
scriptNodePool.PushLast(ptr);
scriptNodePool.PushLast(ptr);
LEAVECRITICALSECTION(cs);
LEAVECRITICALSECTION(cs);
}
void *asCMemoryMgr::AllocByteInstruction()
{
if( byteInstructionPool.GetLength() )
return byteInstructionPool.PopLast();
void *asCMemoryMgr::AllocByteInstruction() {
if (byteInstructionPool.GetLength())
return byteInstructionPool.PopLast();
#if defined(AS_DEBUG)
return ((asALLOCFUNCDEBUG_t)(userAlloc))(sizeof(cByteInstruction), __FILE__, __LINE__);
#if defined(AS_DEBUG)
return ((asALLOCFUNCDEBUG_t)(userAlloc))(sizeof(cByteInstruction), __FILE__, __LINE__);
#else
return userAlloc(sizeof(cByteInstruction));
return userAlloc(sizeof(cByteInstruction));
#endif
}
void asCMemoryMgr::FreeByteInstruction(void *ptr)
{
// Pre allocate memory for the array to avoid slow growth
if( byteInstructionPool.GetLength() == 0 )
byteInstructionPool.Allocate(100, 0);
void asCMemoryMgr::FreeByteInstruction(void *ptr) {
// Pre allocate memory for the array to avoid slow growth
if (byteInstructionPool.GetLength() == 0)
byteInstructionPool.Allocate(100, 0);
byteInstructionPool.PushLast(ptr);
byteInstructionPool.PushLast(ptr);
}
END_AS_NAMESPACE