1 | // |
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo |
---|
3 | // |
---|
4 | // The contents of this file are covered under the licence agreement in the |
---|
5 | // file "LICENCE" distributed with Cforall. |
---|
6 | // |
---|
7 | // memory.hfa -- Memory Management Tools for CFA |
---|
8 | // |
---|
9 | // Author : Andrew Beach |
---|
10 | // Created On : Tue Jun 2 16:48:00 2020 |
---|
11 | // Last Modified By : Andrew Beach |
---|
12 | // Last Modified On : Fri Jan 29 15:52:00 2021 |
---|
13 | // Update Count : 1 |
---|
14 | // |
---|
15 | |
---|
16 | #pragma once |
---|
17 | |
---|
18 | // Internal data object. |
---|
19 | forall(T & | sized(T)) |
---|
20 | struct counter_data { |
---|
21 | unsigned int counter; |
---|
22 | T object; |
---|
23 | }; |
---|
24 | |
---|
25 | forall(T & | sized(T), Args... | { void ?{}(T &, Args); }) |
---|
26 | void ?{}(counter_data(T) & this, Args args); |
---|
27 | |
---|
28 | forall(T & | sized(T) | { void ^?{}(T &); }) |
---|
29 | void ^?{}(counter_data(T) & this); |
---|
30 | |
---|
31 | // This is one of many pointers keeping this alive. |
---|
32 | forall(T & | sized(T)) |
---|
33 | struct counter_ptr { |
---|
34 | counter_data(T) * data; |
---|
35 | }; |
---|
36 | |
---|
37 | forall(T & | sized(T)) |
---|
38 | void ?{}(counter_ptr(T) & this); |
---|
39 | forall(T & | sized(T)) |
---|
40 | void ?{}(counter_ptr(T) & this, zero_t); |
---|
41 | forall(T & | sized(T)) |
---|
42 | void ?{}(counter_ptr(T) & this, counter_ptr(T) that); |
---|
43 | forall(T & | sized(T), Args... | { void ?{}(T&, Args); }) |
---|
44 | void ?{}(counter_ptr(T) & this, Args args); |
---|
45 | |
---|
46 | forall(T & | sized(T) | { void ^?{}(T &); }) |
---|
47 | void ^?{}(counter_ptr(T) & this); |
---|
48 | |
---|
49 | forall(T & | sized(T)) |
---|
50 | T & *?(counter_ptr(T) & this); |
---|
51 | |
---|
52 | forall(T & | sized(T) | { void ^?{}(T &); }) |
---|
53 | void ?=?(counter_ptr(T) & this, counter_ptr(T) that); |
---|
54 | forall(T & | sized(T) | { void ^?{}(T &); }) |
---|
55 | void ?=?(counter_ptr(T) & this, zero_t); |
---|
56 | |
---|
57 | forall(T & | sized(T)) |
---|
58 | int ?==?(counter_ptr(T) const & this, counter_ptr(T) const & that); |
---|
59 | forall(T & | sized(T)) |
---|
60 | int ?!=?(counter_ptr(T) const & this, counter_ptr(T) const & that); |
---|
61 | forall(T & | sized(T)) |
---|
62 | int ?==?(counter_ptr(T) const & this, zero_t); |
---|
63 | forall(T & | sized(T)) |
---|
64 | int ?!=?(counter_ptr(T) const & this, zero_t); |
---|
65 | |
---|
66 | // This is the only pointer that keeps this alive. |
---|
67 | forall(T &) |
---|
68 | struct unique_ptr { |
---|
69 | T * data; |
---|
70 | }; |
---|
71 | |
---|
72 | forall(T &) |
---|
73 | void ?{}(unique_ptr(T) & this); |
---|
74 | forall(T &) |
---|
75 | void ?{}(unique_ptr(T) & this, zero_t); |
---|
76 | forall(T &) |
---|
77 | void ?{}(unique_ptr(T) & this, unique_ptr(T) that) = void; |
---|
78 | forall(T & | sized(T), Args... | { void ?{}(T &, Args); }) |
---|
79 | void ?{}(unique_ptr(T) & this, Args args); |
---|
80 | |
---|
81 | forall(T & | { void ^?{}(T &); }) |
---|
82 | void ^?{}(unique_ptr(T) & this); |
---|
83 | |
---|
84 | forall(T & ) |
---|
85 | T & *?(unique_ptr(T) & this); |
---|
86 | |
---|
87 | forall(T &) |
---|
88 | void ?=?(unique_ptr(T) & this, unique_ptr(T) that) = void; |
---|
89 | forall(T & | { void ^?{}(T &); }) |
---|
90 | void ?=?(unique_ptr(T) & this, zero_t); |
---|
91 | |
---|
92 | forall(T & | { void ^?{}(T &); }) |
---|
93 | void move(unique_ptr(T) & this, unique_ptr(T) & that); |
---|
94 | |
---|
95 | forall(T &) |
---|
96 | T * release(unique_ptr(T) & this); |
---|
97 | |
---|
98 | forall(T &) |
---|
99 | int ?==?(unique_ptr(T) const & this, unique_ptr(T) const & that); |
---|
100 | forall(T &) |
---|
101 | int ?!=?(unique_ptr(T) const & this, unique_ptr(T) const & that); |
---|
102 | forall(T &) |
---|
103 | int ?==?(unique_ptr(T) const & this, zero_t); |
---|
104 | forall(T &) |
---|
105 | int ?!=?(unique_ptr(T) const & this, zero_t); |
---|