mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
...
This commit is contained in:
parent
397123e3c9
commit
205f6ff225
@ -13,12 +13,6 @@
|
|||||||
#define PK_ENABLE_OS 0
|
#define PK_ENABLE_OS 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Enable this if you are working with multi-threading (experimental)
|
|
||||||
// This triggers necessary locks to make the VM thread-safe
|
|
||||||
#ifndef PK_ENABLE_THREAD // can be overridden by cmake
|
|
||||||
#define PK_ENABLE_THREAD 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Enable `line_profiler` module and `breakpoint()` function
|
// Enable `line_profiler` module and `breakpoint()` function
|
||||||
#ifndef PK_ENABLE_PROFILER // can be overridden by cmake
|
#ifndef PK_ENABLE_PROFILER // can be overridden by cmake
|
||||||
#define PK_ENABLE_PROFILER 0
|
#define PK_ENABLE_PROFILER 0
|
||||||
@ -56,9 +50,3 @@
|
|||||||
#else
|
#else
|
||||||
#define PK_PLATFORM_SEP '/'
|
#define PK_PLATFORM_SEP '/'
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if PK_ENABLE_THREAD
|
|
||||||
#define PK_THREAD_LOCAL thread_local
|
|
||||||
#else
|
|
||||||
#define PK_THREAD_LOCAL static
|
|
||||||
#endif
|
|
||||||
|
@ -238,59 +238,47 @@ static int FixedMemoryPool__total_bytes(FixedMemoryPool* self) {
|
|||||||
return self->BlockCount * self->BlockSize;
|
return self->BlockCount * self->BlockSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
PK_THREAD_LOCAL FixedMemoryPool PoolExpr;
|
static FixedMemoryPool PoolExpr;
|
||||||
PK_THREAD_LOCAL FixedMemoryPool PoolFrame;
|
static FixedMemoryPool PoolFrame;
|
||||||
PK_THREAD_LOCAL MemoryPool PoolObject;
|
static MemoryPool PoolObject;
|
||||||
PK_THREAD_LOCAL bool _Pools_initialized = false;
|
|
||||||
|
|
||||||
void pk_MemoryPools__initialize(){
|
void pk_MemoryPools__initialize(){
|
||||||
if(_Pools_initialized) return;
|
|
||||||
FixedMemoryPool__ctor(&PoolExpr, kPoolExprBlockSize, 64);
|
FixedMemoryPool__ctor(&PoolExpr, kPoolExprBlockSize, 64);
|
||||||
FixedMemoryPool__ctor(&PoolFrame, kPoolFrameBlockSize, 128);
|
FixedMemoryPool__ctor(&PoolFrame, kPoolFrameBlockSize, 128);
|
||||||
MemoryPool__ctor(&PoolObject);
|
MemoryPool__ctor(&PoolObject);
|
||||||
_Pools_initialized = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pk_MemoryPools__finalize(){
|
void pk_MemoryPools__finalize(){
|
||||||
if(!_Pools_initialized) return;
|
|
||||||
FixedMemoryPool__dtor(&PoolExpr);
|
FixedMemoryPool__dtor(&PoolExpr);
|
||||||
FixedMemoryPool__dtor(&PoolFrame);
|
FixedMemoryPool__dtor(&PoolFrame);
|
||||||
MemoryPool__dtor(&PoolObject);
|
MemoryPool__dtor(&PoolObject);
|
||||||
_Pools_initialized = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void* PoolExpr_alloc() {
|
void* PoolExpr_alloc() {
|
||||||
assert(_Pools_initialized);
|
|
||||||
return FixedMemoryPool__alloc(&PoolExpr);
|
return FixedMemoryPool__alloc(&PoolExpr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolExpr_dealloc(void* p) {
|
void PoolExpr_dealloc(void* p) {
|
||||||
assert(_Pools_initialized);
|
|
||||||
FixedMemoryPool__dealloc(&PoolExpr, p);
|
FixedMemoryPool__dealloc(&PoolExpr, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* PoolFrame_alloc() {
|
void* PoolFrame_alloc() {
|
||||||
assert(_Pools_initialized);
|
|
||||||
return FixedMemoryPool__alloc(&PoolFrame);
|
return FixedMemoryPool__alloc(&PoolFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolFrame_dealloc(void* p) {
|
void PoolFrame_dealloc(void* p) {
|
||||||
assert(_Pools_initialized);
|
|
||||||
FixedMemoryPool__dealloc(&PoolFrame, p);
|
FixedMemoryPool__dealloc(&PoolFrame, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* PoolObject_alloc() {
|
void* PoolObject_alloc() {
|
||||||
assert(_Pools_initialized);
|
|
||||||
return MemoryPool__alloc(&PoolObject);
|
return MemoryPool__alloc(&PoolObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolObject_dealloc(void* p) {
|
void PoolObject_dealloc(void* p) {
|
||||||
assert(_Pools_initialized);
|
|
||||||
MemoryPool__dealloc(&PoolObject, p);
|
MemoryPool__dealloc(&PoolObject, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolObject_shrink_to_fit() {
|
void PoolObject_shrink_to_fit() {
|
||||||
assert(_Pools_initialized);
|
|
||||||
MemoryPool__shrink_to_fit(&PoolObject);
|
MemoryPool__shrink_to_fit(&PoolObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user