Skip to content

Commit 6b7c19c

Browse files
committed
Update to dynamic framework
1 parent ef74847 commit 6b7c19c

File tree

5 files changed

+17
-18
lines changed

5 files changed

+17
-18
lines changed

Package.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,8 @@ let openGraphSPICompatibilityTestTarget = Target.testTarget(
159159
let package = Package(
160160
name: "OpenGraph",
161161
products: [
162-
.library(name: "OpenGraph_SPI", targets: ["OpenGraph_SPI"]),
163-
.library(name: "OpenGraph", targets: ["OpenGraph"]),
164-
.library(name: "OpenGraphShims", targets: ["OpenGraphShims"]),
162+
.library(name: "OpenGraph", type: .dynamic, targets: ["OpenGraph", "OpenGraph_SPI"]),
163+
.library(name: "OpenGraphShims", type: .dynamic, targets: ["OpenGraph", "OpenGraph_SPI", "OpenGraphShims"]),
165164
],
166165
dependencies: [
167166
.package(url: "https://github.com/apple/swift-numerics", from: "1.0.2"),

Sources/OpenGraph_SPI/Data/ptr.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ template <typename T> class ptr {
3838

3939
OG_INLINE OG_CONSTEXPR
4040
void assert_valid() const {
41-
if (_offset >= table::shared().data_capacity()) {
41+
if (_offset >= shared_table().data_capacity()) {
4242
precondition_failure("invalid data offset: %u", _offset);
4343
}
4444
}
4545

4646
OG_INLINE OG_CONSTEXPR
4747
element_type *_Nonnull get() const OG_NOEXCEPT {
4848
assert(_offset != 0);
49-
return reinterpret_cast<element_type *>(table::shared().data_base() + _offset);
49+
return reinterpret_cast<element_type *>(shared_table().data_base() + _offset);
5050
}
5151

5252
OG_INLINE OG_CONSTEXPR

Sources/OpenGraph_SPI/Data/table.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,16 @@ void *OGGraphVMRegionBaseAddress;
1818
namespace OG {
1919
namespace data {
2020

21-
uint8_t _shared_table_bytes[sizeof(table) / sizeof(uint8_t)] = {};
22-
2321
malloc_zone_t *_Nullable _malloc_zone;
2422

2523
table &table::ensure_shared() {
2624
static dispatch_once_t once;
2725
dispatch_once_f(&once, nullptr, [](void *_Nullable context){
2826
new (_shared_table_bytes) table();
2927
});
30-
return shared();
28+
return shared_table();
3129
}
3230

33-
table &table::shared() { return *reinterpret_cast<data::table *>(&_shared_table_bytes); }
34-
35-
// FIXME
3631
table::table() {
3732
constexpr vm_size_t initial_size = 32 * pages_per_map * page_size;
3833
_region_capacity = initial_size;

Sources/OpenGraph_SPI/Data/table.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class table {
2424

2525
public:
2626
static table &ensure_shared();
27-
static table &shared();
2827

2928
OG_INLINE OG_CONSTEXPR
3029
vm_address_t data_base() const OG_NOEXCEPT { return _data_base; };
@@ -98,9 +97,15 @@ class table {
9897
using page_map_type = std::bitset<pages_per_map>;
9998
vector<page_map_type, 0, uint32_t> _page_maps = {};
10099
vector<page_map_type, 0, uint32_t> _page_metadata_maps = {};
101-
102100
}; /* table */
103101

102+
static uint8_t _shared_table_bytes[sizeof(table) / sizeof(uint8_t)] = {};
103+
104+
OG_INLINE
105+
static table &shared_table() {
106+
return *reinterpret_cast<data::table *>(&_shared_table_bytes);
107+
}
108+
104109
} /* data */
105110
} /* OG */
106111

Sources/OpenGraph_SPI/Data/zone.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ namespace OG {
1111
namespace data {
1212

1313
void zone::clear() OG_NOEXCEPT {
14-
table::shared().lock();
14+
shared_table().lock();
1515
while (last_page()) {
1616
auto page = last_page();
1717
_last_page = page->previous;
18-
table::shared().dealloc_page_locked(page);
18+
shared_table().dealloc_page_locked(page);
1919
}
20-
table::shared().unlock();
20+
shared_table().unlock();
2121
}
2222

2323
ptr<void> zone::alloc_slow(uint32_t size, uint32_t alignment_mask) OG_NOEXCEPT {
@@ -41,12 +41,12 @@ ptr<void> zone::alloc_slow(uint32_t size, uint32_t alignment_mask) OG_NOEXCEPT {
4141

4242
ptr<page> new_page;
4343
if (size <= page_size / 2) {
44-
new_page = table::shared().alloc_page(this, page_size);
44+
new_page = shared_table().alloc_page(this, page_size);
4545
new_page->previous = _last_page;
4646
_last_page = new_page;
4747
} else {
4848
uint32_t aligned_size = ((sizeof(page) + size) + alignment_mask) & ~alignment_mask;
49-
new_page = table::shared().alloc_page(this, aligned_size);
49+
new_page = shared_table().alloc_page(this, aligned_size);
5050
if (_last_page) {
5151
// It's less likely we will be able to alloc unused bytes from this page,
5252
// so insert it before the last page.

0 commit comments

Comments
 (0)