@@ -110,24 +110,22 @@ DeviceImage &ProgramManager::getDeviceImage(OSModuleHandle M,
110110}
111111
112112template <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) {
116115 // any thread which will find nullptr in cache will wait until the pointer
117116 // is not null anymore
118- Cache.waitUntilBuilt ([WithBuildState ]() {
119- int State = WithBuildState ->State .load ();
117+ Cache.waitUntilBuilt ([BuildResult ]() {
118+ int State = BuildResult ->State .load ();
120119
121120 return State == BS_Done || State == BS_Failed;
122121 });
123122
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 );
128126 }
129127
130- RetT *Result = WithBuildState ->Ptr .load ();
128+ RetT *Result = BuildResult ->Ptr .load ();
131129
132130 assert (Result && " An exception should have been thrown" );
133131
@@ -156,7 +154,7 @@ template <typename RetT, typename ExceptionT, typename KeyT, typename AcquireFT,
156154RetT *getOrBuild (KernelProgramCache &KPCache, const KeyT &CacheKey,
157155 AcquireFT &&Acquire, GetCacheFT &&GetCache, BuildFT &&Build) {
158156 bool InsertionTookPlace;
159- KernelProgramCache::EntityWithBuildResult <RetT> *WithState ;
157+ KernelProgramCache::BuildResult <RetT> *BuildResult ;
160158
161159 {
162160 auto LockedCache = Acquire (KPCache);
@@ -166,13 +164,13 @@ RetT *getOrBuild(KernelProgramCache &KPCache, const KeyT &CacheKey,
166164 std::forward_as_tuple (nullptr , BS_InProgress));
167165
168166 InsertionTookPlace = Inserted.second ;
169- WithState = &Inserted.first ->second ;
167+ BuildResult = &Inserted.first ->second ;
170168 }
171169
172170 // no insertion took place, thus some other thread has already inserted smth
173171 // in the cache
174172 if (!InsertionTookPlace) {
175- return waitUntilBuilt<ExceptionT>(KPCache, WithState );
173+ return waitUntilBuilt<ExceptionT>(KPCache, BuildResult );
176174 }
177175
178176 // only the building thread will run this, and only once.
@@ -182,28 +180,30 @@ RetT *getOrBuild(KernelProgramCache &KPCache, const KeyT &CacheKey,
182180#ifndef NDEBUG
183181 RetT *Expected = nullptr ;
184182
185- if (!WithState ->Ptr .compare_exchange_strong (Expected, Desired))
183+ if (!BuildResult ->Ptr .compare_exchange_strong (Expected, Desired))
186184 // We've got a funny story here
187185 assert (false && " We've build an entity that is already have been built." );
188186#else
189187 WithState->Ptr .store (Desired);
190188#endif
191189
192- WithState ->State .store (BS_Done);
190+ BuildResult ->State .store (BS_Done);
193191
194192 KPCache.notifyAllBuild ();
195193
196194 return Desired;
197195 } 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);
201201
202202 KPCache.notifyAllBuild ();
203203
204204 std::rethrow_exception (std::current_exception ());
205205 } catch (...) {
206- WithState ->State .store (BS_Failed);
206+ BuildResult ->State .store (BS_Failed);
207207
208208 KPCache.notifyAllBuild ();
209209
0 commit comments