@@ -110,24 +110,22 @@ DeviceImage &ProgramManager::getDeviceImage(OSModuleHandle M,
110
110
}
111
111
112
112
template <typename ExceptionT, typename RetT>
113
- RetT *waitUntilBuilt (
114
- KernelProgramCache &Cache,
115
- KernelProgramCache::EntityWithBuildResult<RetT> *WithBuildState) {
113
+ RetT *waitUntilBuilt (KernelProgramCache &Cache,
114
+ KernelProgramCache::BuildResult<RetT> *BuildResult) {
116
115
// any thread which will find nullptr in cache will wait until the pointer
117
116
// is not null anymore
118
- Cache.waitUntilBuilt ([WithBuildState ]() {
119
- int State = WithBuildState ->State .load ();
117
+ Cache.waitUntilBuilt ([BuildResult ]() {
118
+ int State = BuildResult ->State .load ();
120
119
121
120
return State == BS_Done || State == BS_Failed;
122
121
});
123
122
124
- if (WithBuildState->BuildResult .get ()) {
125
- using BuildResult = KernelProgramCache::BuildResultT;
126
- const BuildResult &Res = *WithBuildState->BuildResult .get ();
127
- throw ExceptionT (Res.Msg , Res.Code );
123
+ if (BuildResult->Error .FilledIn ) {
124
+ const KernelProgramCache::BuildError &Error = BuildResult->Error ;
125
+ throw ExceptionT (Error.Msg , Error.Code );
128
126
}
129
127
130
- RetT *Result = WithBuildState ->Ptr .load ();
128
+ RetT *Result = BuildResult ->Ptr .load ();
131
129
132
130
assert (Result && " An exception should have been thrown" );
133
131
@@ -156,7 +154,7 @@ template <typename RetT, typename ExceptionT, typename KeyT, typename AcquireFT,
156
154
RetT *getOrBuild (KernelProgramCache &KPCache, const KeyT &CacheKey,
157
155
AcquireFT &&Acquire, GetCacheFT &&GetCache, BuildFT &&Build) {
158
156
bool InsertionTookPlace;
159
- KernelProgramCache::EntityWithBuildResult <RetT> *WithState ;
157
+ KernelProgramCache::BuildResult <RetT> *BuildResult ;
160
158
161
159
{
162
160
auto LockedCache = Acquire (KPCache);
@@ -166,13 +164,13 @@ RetT *getOrBuild(KernelProgramCache &KPCache, const KeyT &CacheKey,
166
164
std::forward_as_tuple (nullptr , BS_InProgress));
167
165
168
166
InsertionTookPlace = Inserted.second ;
169
- WithState = &Inserted.first ->second ;
167
+ BuildResult = &Inserted.first ->second ;
170
168
}
171
169
172
170
// no insertion took place, thus some other thread has already inserted smth
173
171
// in the cache
174
172
if (!InsertionTookPlace) {
175
- return waitUntilBuilt<ExceptionT>(KPCache, WithState );
173
+ return waitUntilBuilt<ExceptionT>(KPCache, BuildResult );
176
174
}
177
175
178
176
// only the building thread will run this, and only once.
@@ -182,28 +180,30 @@ RetT *getOrBuild(KernelProgramCache &KPCache, const KeyT &CacheKey,
182
180
#ifndef NDEBUG
183
181
RetT *Expected = nullptr ;
184
182
185
- if (!WithState ->Ptr .compare_exchange_strong (Expected, Desired))
183
+ if (!BuildResult ->Ptr .compare_exchange_strong (Expected, Desired))
186
184
// We've got a funny story here
187
185
assert (false && " We've build an entity that is already have been built." );
188
186
#else
189
187
WithState->Ptr .store (Desired);
190
188
#endif
191
189
192
- WithState ->State .store (BS_Done);
190
+ BuildResult ->State .store (BS_Done);
193
191
194
192
KPCache.notifyAllBuild ();
195
193
196
194
return Desired;
197
195
} catch (const exception &Ex) {
198
- using BuildResultT = KernelProgramCache::BuildResultT;
199
- WithState->BuildResult .reset (new BuildResultT{Ex.what (), Ex.get_cl_code ()});
200
- WithState->State .store (BS_Failed);
196
+ BuildResult->Error .Msg = Ex.what ();
197
+ BuildResult->Error .Code = Ex.get_cl_code ();
198
+ BuildResult->Error .FilledIn = true ;
199
+
200
+ BuildResult->State .store (BS_Failed);
201
201
202
202
KPCache.notifyAllBuild ();
203
203
204
204
std::rethrow_exception (std::current_exception ());
205
205
} catch (...) {
206
- WithState ->State .store (BS_Failed);
206
+ BuildResult ->State .store (BS_Failed);
207
207
208
208
KPCache.notifyAllBuild ();
209
209
0 commit comments