Skip to content

Commit c3ca4da

Browse files
committed
Update ptr.hpp
1 parent 619f11a commit c3ca4da

File tree

3 files changed

+78
-33
lines changed

3 files changed

+78
-33
lines changed

Sources/OpenGraph_SPI/Data/page.hpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,19 @@
66
#define page_hpp
77

88
#include "OGBase.h"
9+
#include "ptr.hpp"
910

1011
namespace OG {
1112
namespace data {
1213

13-
constexpr const uint32_t page_mask_bits = 9;
14-
15-
/// 0x200
16-
constexpr const uint32_t page_size = 1 << page_mask_bits;
17-
18-
/// 0x1FF
19-
constexpr const uint32_t page_mask = page_size - 1;
20-
21-
/// 0xFFFF_FFE0
22-
constexpr const uintptr_t page_alignment = ~page_mask;
23-
2414
class zone;
15+
template <typename T> class ptr;
2516

2617
struct page {
27-
// zone *zone;
28-
// ptr<page> previous;
29-
// uint32_t total;
30-
// uint32_t in_use;
18+
zone *zone;
19+
ptr<page> previous;
20+
uint32_t total;
21+
uint32_t in_use;
3122
}; /* page */
3223

3324
} /* data */
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// page_const.hpp
3+
// OpenGraph_SPI
4+
5+
#ifndef page_const_hpp
6+
#define page_const_hpp
7+
8+
#include "OGBase.h"
9+
10+
namespace OG {
11+
namespace data {
12+
13+
constexpr const uint32_t page_mask_bits = 9;
14+
15+
/// 0x200
16+
constexpr const uint32_t page_size = 1 << page_mask_bits;
17+
18+
/// 0x1FF
19+
constexpr const uint32_t page_mask = page_size - 1;
20+
21+
/// 0xFFFF_FE00
22+
constexpr const uintptr_t page_alignment = ~page_mask;
23+
24+
} /* data */
25+
} /* OG */
26+
27+
28+
#endif /* page_const_hpp */

Sources/OpenGraph_SPI/Data/ptr.hpp

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <mach/vm_types.h>
1414
#include <bitset>
1515
#include <os/lock.h>
16-
#include "page.hpp"
16+
#include "page_const.hpp"
1717

1818
OG_ASSUME_NONNULL_BEGIN
1919

@@ -33,44 +33,70 @@ template <typename T> class ptr {
3333
template <typename U> friend class ptr;
3434

3535
public:
36-
ptr(difference_type offset = 0) : _offset(offset){};
37-
ptr(nullptr_t){};
36+
OG_INLINE OG_CONSTEXPR ptr(difference_type offset = 0) : _offset(offset){};
37+
OG_INLINE OG_CONSTEXPR ptr(nullptr_t){};
3838

39+
OG_INLINE OG_CONSTEXPR
3940
void assert_valid() const {
4041
if (_offset >= table::shared().data_capacity()) {
4142
precondition_failure("invalid data offset: %u", _offset);
4243
}
4344
}
4445

45-
element_type *_Nonnull get() const noexcept {
46+
OG_INLINE OG_CONSTEXPR
47+
element_type *_Nonnull get() const OG_NOEXCEPT {
4648
assert(_offset != 0);
4749
return reinterpret_cast<element_type *>(table::shared().data_base() + _offset);
4850
}
4951

50-
ptr<page> page_ptr() const noexcept { return ptr<page>(_offset & page_alignment); }
52+
OG_INLINE OG_CONSTEXPR
53+
ptr<page> page_ptr() const OG_NOEXCEPT { return ptr<page>(_offset & page_alignment); }
5154

52-
difference_type page_relative_offset() const noexcept { return _offset & page_mask; }
55+
OG_INLINE OG_CONSTEXPR
56+
difference_type page_relative_offset() const OG_NOEXCEPT { return _offset & page_mask; }
5357

5458
template <typename U> ptr<U> aligned(difference_type alignment_mask = sizeof(difference_type) - 1) const {
5559
return ptr<U>((_offset + alignment_mask) & ~alignment_mask);
5660
};
5761

58-
operator bool() const noexcept { return _offset != 0; };
59-
std::add_lvalue_reference_t<T> operator*() const noexcept { return *get(); };
60-
T *_Nonnull operator->() const noexcept { return get(); };
62+
OG_INLINE OG_CONSTEXPR
63+
operator bool() const OG_NOEXCEPT { return _offset != 0; };
6164

62-
bool operator==(nullptr_t) const noexcept { return _offset == 0; };
63-
bool operator!=(nullptr_t) const noexcept { return _offset != 0; };
65+
OG_INLINE OG_CONSTEXPR
66+
std::add_lvalue_reference_t<T> operator*() const OG_NOEXCEPT { return *get(); };
6467

65-
bool operator<(difference_type offset) const noexcept { return _offset < offset; };
66-
bool operator<=(difference_type offset) const noexcept { return _offset <= offset; };
67-
bool operator>(difference_type offset) const noexcept { return _offset > offset; };
68-
bool operator>=(difference_type offset) const noexcept { return _offset >= offset; };
68+
OG_INLINE OG_CONSTEXPR
69+
T *_Nonnull operator->() const OG_NOEXCEPT { return get(); };
6970

70-
template <typename U> ptr<U> operator+(difference_type shift) const noexcept { return ptr(_offset + shift); };
71-
template <typename U> ptr<U> operator-(difference_type shift) const noexcept { return ptr(_offset - shift); };
71+
OG_INLINE OG_CONSTEXPR
72+
bool operator==(nullptr_t) const OG_NOEXCEPT { return _offset == 0; };
7273

73-
template <typename U> difference_type operator-(const ptr<U> &other) const noexcept {
74+
OG_INLINE OG_CONSTEXPR
75+
bool operator!=(nullptr_t) const OG_NOEXCEPT { return _offset != 0; };
76+
77+
OG_INLINE OG_CONSTEXPR
78+
bool operator<(difference_type offset) const OG_NOEXCEPT { return _offset < offset; };
79+
80+
OG_INLINE OG_CONSTEXPR
81+
bool operator<=(difference_type offset) const OG_NOEXCEPT { return _offset <= offset; };
82+
83+
OG_INLINE OG_CONSTEXPR
84+
bool operator>(difference_type offset) const OG_NOEXCEPT { return _offset > offset; };
85+
86+
OG_INLINE OG_CONSTEXPR
87+
bool operator>=(difference_type offset) const OG_NOEXCEPT { return _offset >= offset; };
88+
89+
template <typename U>
90+
OG_INLINE OG_CONSTEXPR
91+
ptr<U> operator+(difference_type shift) const OG_NOEXCEPT { return ptr(_offset + shift); };
92+
93+
template <typename U>
94+
OG_INLINE OG_CONSTEXPR
95+
ptr<U> operator-(difference_type shift) const OG_NOEXCEPT { return ptr(_offset - shift); };
96+
97+
template <typename U>
98+
OG_INLINE OG_CONSTEXPR
99+
difference_type operator-(const ptr<U> &other) const OG_NOEXCEPT {
74100
return _offset - other._offset;
75101
};
76102
}; /* ptr */

0 commit comments

Comments
 (0)