@@ -34,73 +34,50 @@ class TaskLocal {
3434public:
3535 // / Type of the pointed at `next` task local item.
3636 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 ,
4237 // / The storage pointer points at the next TaskLocal::Item in this task.
43- IsNext = 0b01 ,
38+ IsNext = 0b00 ,
4439 // / The storage pointer points at a item stored by another AsyncTask.
4540 // /
4641 // / Note that this may not necessarily be the same as the task's parent
4742 // / task -- we may point to a super-parent if we know / that the parent
4843 // / does not "contribute" any task local values. This is to speed up
4944 // / lookups by skipping empty parent tasks during get(), and explained
5045 // / 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 ,
7447 };
7548
7649 class Item {
7750 private:
7851 // / Mask used for the low status bits in a task local chain item.
7952 static const uintptr_t statusMask = 0x03 ;
8053
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.
8461 uintptr_t next;
8562
8663 public:
8764 // / The type of the key with which this value is associated.
88- const Metadata *keyType ;
65+ const HeapObject *key ;
8966 // / The type of the value stored by this item.
9067 const Metadata *valueType;
9168
9269 // Trailing storage for the value itself. The storage will be
9370 // uninitialized or contain an instance of \c valueType.
9471
95- private :
72+ protected :
9673 explicit Item ()
9774 : next(0 ),
98- keyType (nullptr ),
75+ key (nullptr ),
9976 valueType(nullptr ) {}
10077
101- explicit Item (const Metadata *keyType , const Metadata *valueType)
78+ explicit Item (const HeapObject *key , const Metadata *valueType)
10279 : next(0 ),
103- keyType(keyType ),
80+ key(key ),
10481 valueType(valueType) {}
10582
10683 public:
@@ -116,7 +93,7 @@ class TaskLocal {
11693 static Item *createParentLink (AsyncTask *task, AsyncTask *parent);
11794
11895 static Item *createLink (AsyncTask *task,
119- const Metadata *keyType ,
96+ const HeapObject *key ,
12097 const Metadata *valueType);
12198
12299 void destroy (AsyncTask *task);
@@ -125,13 +102,13 @@ class TaskLocal {
125102 return reinterpret_cast <Item *>(next & ~statusMask);
126103 }
127104
128- NextLinkType getNextLinkType () {
105+ NextLinkType getNextLinkType () const {
129106 return static_cast <NextLinkType>(next & statusMask);
130107 }
131108
132109 // / Item does not contain any actual value, and is only used to point at
133110 // / a specific parent item.
134- bool isEmpty () {
111+ bool isEmpty () const {
135112 return !valueType;
136113 }
137114
@@ -144,6 +121,7 @@ class TaskLocal {
144121 // / Compute the offset of the storage from the base of the item.
145122 static size_t storageOffset (const Metadata *valueType) {
146123 size_t offset = sizeof (Item);
124+
147125 if (valueType) {
148126 size_t alignment = valueType->vw_alignment ();
149127 return (offset + alignment - 1 ) & ~(alignment - 1 );
@@ -162,7 +140,6 @@ class TaskLocal {
162140 }
163141 };
164142
165-
166143 class Storage {
167144 friend class TaskLocal ::Item;
168145 private:
@@ -202,12 +179,10 @@ class TaskLocal {
202179 void initializeLinkParent (AsyncTask *task, AsyncTask *parent);
203180
204181 void pushValue (AsyncTask *task,
205- const Metadata *keyType ,
182+ const HeapObject *key ,
206183 /* +1 */ OpaqueValue *value, const Metadata *valueType);
207184
208- OpaqueValue* getValue (AsyncTask *task,
209- const Metadata *keyType,
210- TaskLocalInheritance inheritance);
185+ OpaqueValue* getValue (AsyncTask *task, const HeapObject *key);
211186
212187 void popValue (AsyncTask *task);
213188
0 commit comments