1212#include " zone.hpp"
1313#include " ../Util/assert.hpp"
1414#include < sys/mman.h>
15+ #include < dispatch/dispatch.h>
16+ #if OG_TARGET_OS_DARWIN
1517#include < malloc/malloc.h>
18+ #else
19+ #include < malloc.h>
20+ #endif
21+
22+ #if OG_TARGET_OS_DARWIN
1623#include < mach/mach.h>
24+ #endif
1725
1826void *OGGraphVMRegionBaseAddress;
1927
2028namespace OG {
2129namespace data {
2230
31+ #if OG_TARGET_OS_DARWIN
2332malloc_zone_t *_Nullable _malloc_zone;
33+ #endif
2434
2535table &table::ensure_shared () {
2636 static dispatch_once_t once;
@@ -41,14 +51,19 @@ table::table() {
4151 }
4252 _data_base = reinterpret_cast <vm_address_t >(region) - page_size;
4353 _data_capacity = initial_size + page_size;
54+ #if OG_TARGET_OS_DARWIN
4455 if (_malloc_zone == nullptr ) {
4556 malloc_zone_t *zone = malloc_create_zone (0 , 0 );
4657 _malloc_zone = zone;
4758 malloc_set_zone_name (zone, " OpenGraph graph data" );
4859 }
60+ #else
61+ precondition_failure (" not implemented" );
62+ #endif
4963}
5064
5165void table::grow_region () OG_NOEXCEPT {
66+ #if OG_TARGET_OS_DARWIN
5267 uint32_t new_size = 4 * _region_capacity;
5368 // Check size does not exceed 32 bits
5469 if (new_size <= _region_capacity) {
@@ -81,9 +96,13 @@ void table::grow_region() OG_NOEXCEPT {
8196 _region_base = reinterpret_cast <vm_address_t >(new_region);
8297 _region_capacity = new_size;
8398 _data_capacity = new_size + page_size;
99+ #else
100+ precondition_failure (" not implemented" );
101+ #endif
84102}
85103
86104void table::make_pages_reusable (uint32_t page_index, bool reusable) OG_NOEXCEPT {
105+ #if OG_TARGET_OS_DARWIN
87106 static constexpr uint32_t mapped_pages_size = page_size * pages_per_map; // 64 * 512 = 0x8000
88107 void *mapped_pages_address = reinterpret_cast <void *>(region_base () + ((page_index * page_size) & ~(mapped_pages_size - 1 )));
89108 int advice = reusable ? MADV_FREE_REUSABLE : MADV_FREE_REUSE;
@@ -100,6 +119,9 @@ void table::make_pages_reusable(uint32_t page_index, bool reusable) OG_NOEXCEPT
100119 mprotect (mapped_pages_address, mapped_pages_size, protection);
101120 }
102121 _reusable_pages_num += reusable ? mapped_pages_size : -mapped_pages_size;
122+ #else
123+ precondition_failure (" not implemented" );
124+ #endif
103125}
104126
105127// TO BE AUDITED
@@ -242,13 +264,13 @@ uint64_t table::raw_page_seed(ptr<page> page) OG_NOEXCEPT {
242264}
243265
244266void table::print () const OG_NOEXCEPT {
245- os_unfair_lock_lock (&_lock );
267+ lock ( );
246268 fprintf (stderr, " data::table %p:\n %.2fKB allocated, %.2fKB used, %.2fKB reusable.\n " ,
247269 this ,
248270 double (_region_capacity - page_size) / 1024.0 ,
249271 double (this ->used_pages_num ()) / 1024.0 ,
250272 double (_reusable_pages_num) / 1024.0 );
251- os_unfair_lock_unlock (&_lock );
273+ unlock ( );
252274}
253275
254276} /* data */
0 commit comments