@@ -34,73 +34,50 @@ class TaskLocal {
34
34
public:
35
35
// / Type of the pointed at `next` task local item.
36
36
enum class NextLinkType : uintptr_t {
37
- // / This task is known to be a "terminal" node in the lookup of task locals.
38
- // / In other words, even if it had a parent, the parent (and its parents)
39
- // / are known to not contain any any more task locals, and thus any further
40
- // / search beyond this task.
41
- IsTerminal = 0b00 ,
42
37
// / The storage pointer points at the next TaskLocal::Item in this task.
43
- IsNext = 0b01 ,
38
+ IsNext = 0b00 ,
44
39
// / The storage pointer points at a item stored by another AsyncTask.
45
40
// /
46
41
// / Note that this may not necessarily be the same as the task's parent
47
42
// / task -- we may point to a super-parent if we know / that the parent
48
43
// / does not "contribute" any task local values. This is to speed up
49
44
// / lookups by skipping empty parent tasks during get(), and explained
50
45
// / in depth in `createParentLink`.
51
- IsParent = 0b11
52
- };
53
-
54
- // / Values must match `TaskLocalInheritance` declared in `TaskLocal.swift`.
55
- enum class TaskLocalInheritance : uint8_t {
56
- // / Default task local value behavior
57
- // /
58
- // / Values declared with a default-inherited key are accessible from:
59
- // / - the current task that has bound the value,
60
- // / - any child task of the current task (e.g. created by async let or groups)
61
- // /
62
- // / Such values are *not* carried through detached tasks.
63
- Default = 0 ,
64
-
65
- // / Special semantics which confine a task's local value to *only* the current
66
- // / task. In other words, they ave never inherited by any child task created
67
- // / by the current task.
68
- // /
69
- // / Values declared with a never-inherited key only accessible:
70
- // / - specifically from the current task itself
71
- // /
72
- // / Such values are *not* accessible from child tasks or detached tasks.
73
- Never = 1
46
+ IsParent = 0b01 ,
74
47
};
75
48
76
49
class Item {
77
50
private:
78
51
// / Mask used for the low status bits in a task local chain item.
79
52
static const uintptr_t statusMask = 0x03 ;
80
53
81
- // / Pointer to the next task local item; be it in this task or in a parent.
82
- // / Low bits encode `NextLinkType`.
83
- // / Item *next = nullptr;
54
+ // / Pointer to one of the following:
55
+ // / - next task local item as OpaqueValue* if it is task-local allocated
56
+ // / - next task local item as HeapObject* if it is heap allocated "heavy"
57
+ // / - the parent task's TaskLocal::Storage
58
+ // /
59
+ // / Low bits encode `NextLinkType`, based on which the type of the pointer
60
+ // / is determined.
84
61
uintptr_t next;
85
62
86
63
public:
87
64
// / The type of the key with which this value is associated.
88
- const Metadata *keyType ;
65
+ const HeapObject *key ;
89
66
// / The type of the value stored by this item.
90
67
const Metadata *valueType;
91
68
92
69
// Trailing storage for the value itself. The storage will be
93
70
// uninitialized or contain an instance of \c valueType.
94
71
95
- private :
72
+ protected :
96
73
explicit Item ()
97
74
: next(0 ),
98
- keyType (nullptr ),
75
+ key (nullptr ),
99
76
valueType(nullptr ) {}
100
77
101
- explicit Item (const Metadata *keyType , const Metadata *valueType)
78
+ explicit Item (const HeapObject *key , const Metadata *valueType)
102
79
: next(0 ),
103
- keyType(keyType ),
80
+ key(key ),
104
81
valueType(valueType) {}
105
82
106
83
public:
@@ -116,7 +93,7 @@ class TaskLocal {
116
93
static Item *createParentLink (AsyncTask *task, AsyncTask *parent);
117
94
118
95
static Item *createLink (AsyncTask *task,
119
- const Metadata *keyType ,
96
+ const HeapObject *key ,
120
97
const Metadata *valueType);
121
98
122
99
void destroy (AsyncTask *task);
@@ -125,13 +102,13 @@ class TaskLocal {
125
102
return reinterpret_cast <Item *>(next & ~statusMask);
126
103
}
127
104
128
- NextLinkType getNextLinkType () {
105
+ NextLinkType getNextLinkType () const {
129
106
return static_cast <NextLinkType>(next & statusMask);
130
107
}
131
108
132
109
// / Item does not contain any actual value, and is only used to point at
133
110
// / a specific parent item.
134
- bool isEmpty () {
111
+ bool isEmpty () const {
135
112
return !valueType;
136
113
}
137
114
@@ -144,6 +121,7 @@ class TaskLocal {
144
121
// / Compute the offset of the storage from the base of the item.
145
122
static size_t storageOffset (const Metadata *valueType) {
146
123
size_t offset = sizeof (Item);
124
+
147
125
if (valueType) {
148
126
size_t alignment = valueType->vw_alignment ();
149
127
return (offset + alignment - 1 ) & ~(alignment - 1 );
@@ -162,7 +140,6 @@ class TaskLocal {
162
140
}
163
141
};
164
142
165
-
166
143
class Storage {
167
144
friend class TaskLocal ::Item;
168
145
private:
@@ -202,12 +179,10 @@ class TaskLocal {
202
179
void initializeLinkParent (AsyncTask *task, AsyncTask *parent);
203
180
204
181
void pushValue (AsyncTask *task,
205
- const Metadata *keyType ,
182
+ const HeapObject *key ,
206
183
/* +1 */ OpaqueValue *value, const Metadata *valueType);
207
184
208
- OpaqueValue* getValue (AsyncTask *task,
209
- const Metadata *keyType,
210
- TaskLocalInheritance inheritance);
185
+ OpaqueValue* getValue (AsyncTask *task, const HeapObject *key);
211
186
212
187
void popValue (AsyncTask *task);
213
188
0 commit comments