#pragma once
#include "IsoConfig.h"
#include "Mutex.h"
#if BENABLE_MALLOC_HEAP_BREAKDOWN
#include <malloc/malloc.h>
#endif
namespace bmalloc {
template<typename Config> class IsoHeapImpl;
namespace api {
template<typename Type>
struct IsoHeap {
typedef IsoConfig<sizeof(Type)> Config;
#if BENABLE_MALLOC_HEAP_BREAKDOWN
IsoHeap(const char* = nullptr);
#else
constexpr IsoHeap(const char* = nullptr) { }
#endif
void* allocate();
void* tryAllocate();
void deallocate(void* p);
void scavenge();
void initialize();
bool isInitialized();
unsigned allocatorOffset() { return m_allocatorOffsetPlusOne - 1; }
void setAllocatorOffset(unsigned value) { m_allocatorOffsetPlusOne = value + 1; }
unsigned deallocatorOffset() { return m_deallocatorOffsetPlusOne - 1; }
void setDeallocatorOffset(unsigned value) { m_deallocatorOffsetPlusOne = value + 1; }
IsoHeapImpl<Config>& impl();
Mutex m_initializationLock;
unsigned m_allocatorOffsetPlusOne { 0 };
unsigned m_deallocatorOffsetPlusOne { 0 };
IsoHeapImpl<Config>* m_impl { nullptr };
#if BENABLE_MALLOC_HEAP_BREAKDOWN
malloc_zone_t* m_zone;
#endif
};
#define MAKE_BISO_MALLOCED(isoType, exportMacro) \
public: \
static exportMacro ::bmalloc::api::IsoHeap<isoType>& bisoHeap(); \
\
void* operator new(size_t, void* p) { return p; } \
void* operator new[](size_t, void* p) { return p; } \
\
exportMacro void* operator new(size_t size);\
exportMacro void operator delete(void* p);\
\
void* operator new[](size_t size) = delete; \
void operator delete[](void* p) = delete; \
using webkitFastMalloced = int; \
private: \
using __makeBisoMallocedMacroSemicolonifier = int
} }