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 : Tue Jun 3 12:29:00 2020 |
---|
13 | // Update Count : 0 |
---|
14 | // |
---|
15 | |
---|
16 | #pragma once |
---|
17 | |
---|
18 | // Internal data object. |
---|
19 | forall(dtype T | sized(T)) { |
---|
20 | struct counter_data { |
---|
21 | unsigned int counter; |
---|
22 | T object; |
---|
23 | }; |
---|
24 | |
---|
25 | forall(ttype Args | { void ?{}(T &, Args); }) |
---|
26 | void ?{}(counter_data(T) & this, Args args); |
---|
27 | |
---|
28 | forall( | { void ^?{}(T &); }) |
---|
29 | void ^?{}(counter_data(T) & this); |
---|
30 | } |
---|
31 | |
---|
32 | // This is one of many pointers keeping this alive. |
---|
33 | forall(dtype T | sized(T)) { |
---|
34 | struct counter_ptr { |
---|
35 | counter_data(T) * data; |
---|
36 | }; |
---|
37 | |
---|
38 | void ?{}(counter_ptr(T) & this); |
---|
39 | void ?{}(counter_ptr(T) & this, zero_t); |
---|
40 | forall( | { void ^?{}(T &); }) |
---|
41 | void ?{}(counter_ptr(T) & this, counter_ptr(T) that); |
---|
42 | forall(ttype Args | { void ?{}(T&, Args); }) |
---|
43 | void ?{}(counter_ptr(T) & this, Args args); |
---|
44 | |
---|
45 | forall( | { void ^?{}(T &); }) |
---|
46 | void ^?{}(counter_ptr(T) & this); |
---|
47 | |
---|
48 | T & *?(counter_ptr(T) & this); |
---|
49 | |
---|
50 | forall( | { void ^?{}(T &); }) |
---|
51 | void ?=?(counter_ptr(T) & this, counter_ptr(T) that); |
---|
52 | forall( | { void ^?{}(T &); }) |
---|
53 | void ?=?(counter_ptr(T) & this, zero_t); |
---|
54 | |
---|
55 | int ?==?(counter_ptr(T) const & this, counter_ptr(T) const & that); |
---|
56 | int ?!=?(counter_ptr(T) const & this, counter_ptr(T) const & that); |
---|
57 | int ?==?(counter_ptr(T) const & this, zero_t); |
---|
58 | int ?!=?(counter_ptr(T) const & this, zero_t); |
---|
59 | } |
---|
60 | |
---|
61 | // This is the only pointer that keeps this alive. |
---|
62 | forall(dtype T) { |
---|
63 | struct unique_ptr { |
---|
64 | T * data; |
---|
65 | }; |
---|
66 | |
---|
67 | void ?{}(unique_ptr(T) & this); |
---|
68 | void ?{}(unique_ptr(T) & this, zero_t); |
---|
69 | void ?{}(unique_ptr(T) & this, unique_ptr(T) that) = void; |
---|
70 | forall( | sized(T), ttype Args | { void ?{}(T &, Args); }) |
---|
71 | void ?{}(unique_ptr(T) & this, Args args); |
---|
72 | |
---|
73 | forall( | { void ^?{}(T &); }) |
---|
74 | void ^?{}(unique_ptr(T) & this); |
---|
75 | |
---|
76 | T & *?(unique_ptr(T) & this); |
---|
77 | |
---|
78 | void ?=?(unique_ptr(T) & this, unique_ptr(T) that) = void; |
---|
79 | forall( | { void ^?{}(T &); }) |
---|
80 | void ?=?(unique_ptr(T) & this, zero_t); |
---|
81 | |
---|
82 | forall( | { void ^?{}(T &); }) |
---|
83 | void move(unique_ptr(T) & this, unique_ptr(T) & that); |
---|
84 | |
---|
85 | int ?==?(unique_ptr(T) const & this, unique_ptr(T) const & that); |
---|
86 | int ?!=?(unique_ptr(T) const & this, unique_ptr(T) const & that); |
---|
87 | int ?==?(unique_ptr(T) const & this, zero_t); |
---|
88 | int ?!=?(unique_ptr(T) const & this, zero_t); |
---|
89 | } |
---|