@@ -105,20 +105,7 @@ void GlobalHandler::TraceEventXPTI(const char *Message) {
105105#endif
106106}
107107
108- GlobalHandler *&GlobalHandler::getInstancePtr () {
109- static GlobalHandler *RTGlobalObjHandler = new GlobalHandler ();
110- return RTGlobalObjHandler;
111- }
112-
113- GlobalHandler &GlobalHandler::instance () {
114- GlobalHandler *RTGlobalObjHandler = GlobalHandler::getInstancePtr ();
115- assert (RTGlobalObjHandler && " Handler must not be deallocated earlier" );
116- return *RTGlobalObjHandler;
117- }
118-
119- bool GlobalHandler::isInstanceAlive () {
120- return GlobalHandler::getInstancePtr ();
121- }
108+ GlobalHandler *GlobalHandler::RTGlobalObjHandler = new GlobalHandler();
122109
123110template <typename T, typename ... Types>
124111T &GlobalHandler::getOrCreate (InstWithLock<T> &IWL, Types &&...Args) {
@@ -331,8 +318,7 @@ void GlobalHandler::drainThreadPool() {
331318// 2) when process is being terminated
332319void shutdown_early (bool CanJoinThreads = true ) {
333320 const LockGuard Lock{GlobalHandler::MSyclGlobalHandlerProtector};
334- GlobalHandler *&Handler = GlobalHandler::getInstancePtr ();
335- if (!Handler)
321+ if (!GlobalHandler::RTGlobalObjHandler)
336322 return ;
337323
338324#if defined(XPTI_ENABLE_INSTRUMENTATION) && defined(_WIN32)
@@ -342,26 +328,26 @@ void shutdown_early(bool CanJoinThreads = true) {
342328#endif
343329
344330 // Now that we are shutting down, we will no longer defer MemObj releases.
345- Handler ->endDeferredRelease ();
331+ GlobalHandler::RTGlobalObjHandler ->endDeferredRelease ();
346332
347333 // Ensure neither host task is working so that no default context is accessed
348334 // upon its release
349- Handler ->prepareSchedulerToRelease (true );
335+ GlobalHandler::RTGlobalObjHandler ->prepareSchedulerToRelease (true );
350336
351- if (Handler->MHostTaskThreadPool .Inst ) {
352- Handler->MHostTaskThreadPool .Inst ->finishAndWait (CanJoinThreads);
353- Handler->MHostTaskThreadPool .Inst .reset (nullptr );
337+ if (GlobalHandler::RTGlobalObjHandler->MHostTaskThreadPool .Inst ) {
338+ GlobalHandler::RTGlobalObjHandler->MHostTaskThreadPool .Inst ->finishAndWait (
339+ CanJoinThreads);
340+ GlobalHandler::RTGlobalObjHandler->MHostTaskThreadPool .Inst .reset (nullptr );
354341 }
355342
356343 // This releases OUR reference to the default context, but
357344 // other may yet have refs
358- Handler ->releaseDefaultContexts ();
345+ GlobalHandler::RTGlobalObjHandler ->releaseDefaultContexts ();
359346}
360347
361348void shutdown_late () {
362349 const LockGuard Lock{GlobalHandler::MSyclGlobalHandlerProtector};
363- GlobalHandler *&Handler = GlobalHandler::getInstancePtr ();
364- if (!Handler)
350+ if (!GlobalHandler::RTGlobalObjHandler)
365351 return ;
366352
367353#if defined(XPTI_ENABLE_INSTRUMENTATION) && defined(_WIN32)
@@ -371,26 +357,27 @@ void shutdown_late() {
371357#endif
372358
373359 // First, release resources, that may access adapters.
374- Handler ->MPlatformCache .Inst .reset (nullptr );
375- Handler ->MScheduler .Inst .reset (nullptr );
376- Handler ->MProgramManager .Inst .reset (nullptr );
360+ GlobalHandler::RTGlobalObjHandler ->MPlatformCache .Inst .reset (nullptr );
361+ GlobalHandler::RTGlobalObjHandler ->MScheduler .Inst .reset (nullptr );
362+ GlobalHandler::RTGlobalObjHandler ->MProgramManager .Inst .reset (nullptr );
377363
378364#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
379365 // Kernel cache, which is part of device kernel info,
380366 // stores handles to the adapter, so clear it before releasing adapters.
381- Handler->MDeviceKernelInfoStorage .Inst .reset (nullptr );
367+ GlobalHandler::RTGlobalObjHandler->MDeviceKernelInfoStorage .Inst .reset (
368+ nullptr );
382369#endif
383370
384371 // Clear the adapters and reset the instance if it was there.
385- Handler ->unloadAdapters ();
386- if (Handler ->MAdapters .Inst )
387- Handler ->MAdapters .Inst .reset (nullptr );
372+ GlobalHandler::RTGlobalObjHandler ->unloadAdapters ();
373+ if (GlobalHandler::RTGlobalObjHandler ->MAdapters .Inst )
374+ GlobalHandler::RTGlobalObjHandler ->MAdapters .Inst .reset (nullptr );
388375
389- Handler ->MXPTIRegistry .Inst .reset (nullptr );
376+ GlobalHandler::RTGlobalObjHandler ->MXPTIRegistry .Inst .reset (nullptr );
390377
391378 // Release the rest of global resources.
392- delete Handler ;
393- Handler = nullptr ;
379+ delete GlobalHandler::RTGlobalObjHandler ;
380+ GlobalHandler::RTGlobalObjHandler = nullptr ;
394381}
395382
396383#ifdef _WIN32
0 commit comments