diff --git a/level_zero/tools/source/debug/linux/debug_session.h b/level_zero/tools/source/debug/linux/debug_session.h index 961c9a6e40..27d1d22876 100644 --- a/level_zero/tools/source/debug/linux/debug_session.h +++ b/level_zero/tools/source/debug/linux/debug_session.h @@ -32,7 +32,7 @@ struct DebugSessionLinux : DebugSessionImp { static void *readInternalEventsThreadFunction(void *arg); MOCKABLE_VIRTUAL void startInternalEventsThread() { - internalEventThread.thread = NEO::Thread::create(readInternalEventsThreadFunction, reinterpret_cast(this)); + internalEventThread.thread = NEO::Thread::createFunc(readInternalEventsThreadFunction, reinterpret_cast(this)); } void closeInternalEventsThread() { internalEventThread.close(); diff --git a/level_zero/tools/source/debug/linux/prelim/debug_session.cpp b/level_zero/tools/source/debug/linux/prelim/debug_session.cpp index 5fc046a99f..3d1baa8383 100644 --- a/level_zero/tools/source/debug/linux/prelim/debug_session.cpp +++ b/level_zero/tools/source/debug/linux/prelim/debug_session.cpp @@ -130,7 +130,7 @@ void *DebugSessionLinuxi915::asyncThreadFunction(void *arg) { } void DebugSessionLinuxi915::startAsyncThread() { - asyncThread.thread = NEO::Thread::create(asyncThreadFunction, reinterpret_cast(this)); + asyncThread.thread = NEO::Thread::createFunc(asyncThreadFunction, reinterpret_cast(this)); } bool DebugSessionLinuxi915::handleInternalEvent() { diff --git a/level_zero/tools/source/debug/linux/xe/debug_session.cpp b/level_zero/tools/source/debug/linux/xe/debug_session.cpp index 7c2ec19ec8..5d27f26f9b 100644 --- a/level_zero/tools/source/debug/linux/xe/debug_session.cpp +++ b/level_zero/tools/source/debug/linux/xe/debug_session.cpp @@ -89,7 +89,7 @@ void *DebugSessionLinuxXe::asyncThreadFunction(void *arg) { } void DebugSessionLinuxXe::startAsyncThread() { - asyncThread.thread = NEO::Thread::create(asyncThreadFunction, reinterpret_cast(this)); + asyncThread.thread = NEO::Thread::createFunc(asyncThreadFunction, reinterpret_cast(this)); } void DebugSessionLinuxXe::readInternalEventsAsync() { diff --git a/level_zero/tools/source/debug/windows/debug_session.cpp b/level_zero/tools/source/debug/windows/debug_session.cpp index 611ec23450..b0b20a4154 100644 --- a/level_zero/tools/source/debug/windows/debug_session.cpp +++ b/level_zero/tools/source/debug/windows/debug_session.cpp @@ -113,7 +113,7 @@ bool DebugSessionWindows::closeConnection() { } void DebugSessionWindows::startAsyncThread() { - asyncThread.thread = NEO::Thread::create(asyncThreadFunction, reinterpret_cast(this)); + asyncThread.thread = NEO::Thread::createFunc(asyncThreadFunction, reinterpret_cast(this)); } void DebugSessionWindows::closeAsyncThread() { diff --git a/level_zero/tools/test/unit_tests/sources/debug/linux/prelim/debug_session_fixtures_linux.h b/level_zero/tools/test/unit_tests/sources/debug/linux/prelim/debug_session_fixtures_linux.h index b294bb16ce..f78a5de338 100644 --- a/level_zero/tools/test/unit_tests/sources/debug/linux/prelim/debug_session_fixtures_linux.h +++ b/level_zero/tools/test/unit_tests/sources/debug/linux/prelim/debug_session_fixtures_linux.h @@ -419,7 +419,7 @@ struct MockAsyncThreadDebugSessionLinuxi915 : public MockDebugSessionLinuxi915 { } void startAsyncThread() override { - asyncThread.thread = NEO::Thread::create(mockAsyncThreadFunction, reinterpret_cast(this)); + asyncThread.thread = NEO::Thread::createFunc(mockAsyncThreadFunction, reinterpret_cast(this)); } std::atomic asyncThreadFinished{false}; diff --git a/level_zero/tools/test/unit_tests/sources/debug/linux/xe/debug_session_fixtures_linux_xe.h b/level_zero/tools/test/unit_tests/sources/debug/linux/xe/debug_session_fixtures_linux_xe.h index 9daeafffc5..33e482aacc 100644 --- a/level_zero/tools/test/unit_tests/sources/debug/linux/xe/debug_session_fixtures_linux_xe.h +++ b/level_zero/tools/test/unit_tests/sources/debug/linux/xe/debug_session_fixtures_linux_xe.h @@ -286,7 +286,7 @@ struct MockAsyncThreadDebugSessionLinuxXe : public MockDebugSessionLinuxXe { } void startAsyncThread() override { - asyncThread.thread = NEO::Thread::create(mockAsyncThreadFunction, reinterpret_cast(this)); + asyncThread.thread = NEO::Thread::createFunc(mockAsyncThreadFunction, reinterpret_cast(this)); } std::atomic asyncThreadFinished{false}; diff --git a/level_zero/tools/test/unit_tests/sources/debug/windows/test_debug_api_windows.cpp b/level_zero/tools/test/unit_tests/sources/debug/windows/test_debug_api_windows.cpp index 806712e32c..0de3f5f6e4 100644 --- a/level_zero/tools/test/unit_tests/sources/debug/windows/test_debug_api_windows.cpp +++ b/level_zero/tools/test/unit_tests/sources/debug/windows/test_debug_api_windows.cpp @@ -154,7 +154,7 @@ struct MockAsyncThreadDebugSessionWindows : public MockDebugSessionWindows { } void startAsyncThread() override { - asyncThread.thread = NEO::Thread::create(mockAsyncThreadFunction, reinterpret_cast(this)); + asyncThread.thread = NEO::Thread::createFunc(mockAsyncThreadFunction, reinterpret_cast(this)); } std::atomic asyncThreadFinished{false}; diff --git a/opencl/source/event/async_events_handler.cpp b/opencl/source/event/async_events_handler.cpp index f2dfd37a9a..52bcdc31a6 100644 --- a/opencl/source/event/async_events_handler.cpp +++ b/opencl/source/event/async_events_handler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2023 Intel Corporation + * Copyright (C) 2018-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -105,7 +105,7 @@ void AsyncEventsHandler::openThread() { if (!thread.get()) { DEBUG_BREAK_IF(allowAsyncProcess); allowAsyncProcess = true; - thread = Thread::create(asyncProcess, reinterpret_cast(this)); + thread = Thread::createFunc(asyncProcess, reinterpret_cast(this)); } } diff --git a/shared/source/command_stream/command_stream_receiver.cpp b/shared/source/command_stream/command_stream_receiver.cpp index aa45c47d58..0986cb01d3 100644 --- a/shared/source/command_stream/command_stream_receiver.cpp +++ b/shared/source/command_stream/command_stream_receiver.cpp @@ -831,7 +831,7 @@ bool CommandStreamReceiver::initializeTagAllocation() { this->tagAddress, static_cast(osContext->getEngineType())); if (debugManager.flags.PauseOnEnqueue.get() != -1 || debugManager.flags.PauseOnBlitCopy.get() != -1) { - userPauseConfirmation = Thread::create(CommandStreamReceiver::asyncDebugBreakConfirmation, reinterpret_cast(this)); + userPauseConfirmation = Thread::createFunc(CommandStreamReceiver::asyncDebugBreakConfirmation, reinterpret_cast(this)); } this->barrierCountTagAddress = ptrOffset(this->tagAddress, TagAllocationLayout::barrierCountOffset); diff --git a/shared/source/direct_submission/direct_submission_controller.cpp b/shared/source/direct_submission/direct_submission_controller.cpp index e07587c6c5..f29eb32ac3 100644 --- a/shared/source/direct_submission/direct_submission_controller.cpp +++ b/shared/source/direct_submission/direct_submission_controller.cpp @@ -82,7 +82,7 @@ void DirectSubmissionController::unregisterDirectSubmission(CommandStreamReceive } void DirectSubmissionController::startThread() { - directSubmissionControllingThread = Thread::create(controlDirectSubmissionsState, reinterpret_cast(this)); + directSubmissionControllingThread = Thread::createFunc(controlDirectSubmissionsState, reinterpret_cast(this)); } void DirectSubmissionController::stopThread() { diff --git a/shared/source/memory_manager/deferred_deleter.cpp b/shared/source/memory_manager/deferred_deleter.cpp index 02c7648ecc..bd623779c5 100644 --- a/shared/source/memory_manager/deferred_deleter.cpp +++ b/shared/source/memory_manager/deferred_deleter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2023 Intel Corporation + * Copyright (C) 2018-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -73,7 +73,7 @@ void DeferredDeleter::ensureThread() { if (worker != nullptr) { return; } - worker = Thread::create(run, reinterpret_cast(this)); + worker = Thread::createFunc(run, reinterpret_cast(this)); } bool DeferredDeleter::areElementsReleased() { diff --git a/shared/source/os_interface/linux/drm_gem_close_worker.cpp b/shared/source/os_interface/linux/drm_gem_close_worker.cpp index 658d4a2ae0..8a12cdb47b 100644 --- a/shared/source/os_interface/linux/drm_gem_close_worker.cpp +++ b/shared/source/os_interface/linux/drm_gem_close_worker.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2022 Intel Corporation + * Copyright (C) 2018-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -20,7 +20,7 @@ namespace NEO { DrmGemCloseWorker::DrmGemCloseWorker(DrmMemoryManager &memoryManager) : memoryManager(memoryManager) { - thread = Thread::create(worker, reinterpret_cast(this)); + thread = Thread::createFunc(worker, reinterpret_cast(this)); } void DrmGemCloseWorker::closeThread() { diff --git a/shared/source/os_interface/linux/os_thread_linux.cpp b/shared/source/os_interface/linux/os_thread_linux.cpp index 4d4cae3f33..15aaa01d0b 100644 --- a/shared/source/os_interface/linux/os_thread_linux.cpp +++ b/shared/source/os_interface/linux/os_thread_linux.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -12,6 +12,8 @@ namespace NEO { ThreadLinux::ThreadLinux(pthread_t threadId) : threadId(threadId){}; +decltype(&Thread::create) Thread::createFunc = Thread::create; + std::unique_ptr Thread::create(void *(*func)(void *), void *arg) { pthread_t threadId; pthread_create(&threadId, nullptr, func, arg); diff --git a/shared/source/os_interface/os_thread.h b/shared/source/os_interface/os_thread.h index 080e965bb8..08a9f3aa0f 100644 --- a/shared/source/os_interface/os_thread.h +++ b/shared/source/os_interface/os_thread.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -10,8 +10,10 @@ namespace NEO { class Thread { - public: static std::unique_ptr create(void *(*func)(void *), void *arg); + + public: + static decltype(&Thread::create) createFunc; virtual void join() = 0; virtual ~Thread() = default; virtual void yield() = 0; diff --git a/shared/source/os_interface/windows/os_thread_win.cpp b/shared/source/os_interface/windows/os_thread_win.cpp index acb8f65ca4..ba83965a74 100644 --- a/shared/source/os_interface/windows/os_thread_win.cpp +++ b/shared/source/os_interface/windows/os_thread_win.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -11,6 +11,8 @@ ThreadWin::ThreadWin(std::thread *thread) { this->thread.reset(thread); }; +decltype(&Thread::create) Thread::createFunc = Thread::create; + std::unique_ptr Thread::create(void *(*func)(void *), void *arg) { return std::unique_ptr(new ThreadWin(new std::thread(func, arg))); } diff --git a/shared/test/common/mocks/mock_deferred_deleter.cpp b/shared/test/common/mocks/mock_deferred_deleter.cpp index 330976025b..5719ca382e 100644 --- a/shared/test/common/mocks/mock_deferred_deleter.cpp +++ b/shared/test/common/mocks/mock_deferred_deleter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2023 Intel Corporation + * Copyright (C) 2018-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -116,7 +116,7 @@ std::unique_ptr createDeferredDeleter() { } void MockDeferredDeleter::runThread() { - worker = Thread::create(run, reinterpret_cast(this)); + worker = Thread::createFunc(run, reinterpret_cast(this)); } void MockDeferredDeleter::forceStop() { diff --git a/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp b/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp index 7d7ec99faf..79fb7481ef 100644 --- a/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp +++ b/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp @@ -26,6 +26,7 @@ #include "shared/source/os_interface/device_factory.h" #include "shared/source/os_interface/os_context.h" #include "shared/source/os_interface/os_interface.h" +#include "shared/source/os_interface/os_thread.h" #include "shared/source/os_interface/product_helper.h" #include "shared/source/utilities/tag_allocator.h" #include "shared/test/common/cmd_parse/gen_cmd_parse.h" @@ -990,6 +991,7 @@ using InitDirectSubmissionTest = Test; HWTEST_F(InitDirectSubmissionTest, givenDirectSubmissionControllerEnabledWhenInitDirectSubmissionThenCsrIsRegistered) { DebugManagerStateRestore restorer; debugManager.flags.EnableDirectSubmissionController.set(1); + VariableBackup funcBackup{&NEO::Thread::createFunc, [](void *(*func)(void *), void *arg) -> std::unique_ptr { return nullptr; }}; auto csr = std::make_unique>(*device->executionEnvironment, device->getRootDeviceIndex(), device->getDeviceBitfield()); std::unique_ptr osContext(OsContext::create(device->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.get(), device->getRootDeviceIndex(), 0, @@ -5741,6 +5743,7 @@ HWTEST_F(CommandStreamReceiverTest, givenCommandStreamReceiverWhenEnqueueWaitFor auto pagingFenceValue = 10u; EXPECT_FALSE(csr.enqueueWaitForPagingFence(pagingFenceValue)); + VariableBackup funcBackup{&NEO::Thread::createFunc, [](void *(*func)(void *), void *arg) -> std::unique_ptr { return nullptr; }}; // enqueue waitForPagingFence is possible only if controller exists and direct submission is enabled auto controller = static_cast(executionEnvironment->initializeDirectSubmissionController()); controller->stopThread(); @@ -5755,4 +5758,4 @@ HWTEST_F(CommandStreamReceiverTest, givenCommandStreamReceiverWhenEnqueueWaitFor csr.directSubmissionAvailable = false; controller->handlePagingFenceRequests(lock, false); EXPECT_EQ(10u, csr.pagingFenceValueToUnblock); -} \ No newline at end of file +} diff --git a/shared/test/unit_test/execution_environment/execution_environment_tests.cpp b/shared/test/unit_test/execution_environment/execution_environment_tests.cpp index 4e25133ee4..5c9ad17887 100644 --- a/shared/test/unit_test/execution_environment/execution_environment_tests.cpp +++ b/shared/test/unit_test/execution_environment/execution_environment_tests.cpp @@ -21,6 +21,7 @@ #include "shared/source/os_interface/device_factory.h" #include "shared/source/os_interface/driver_info.h" #include "shared/source/os_interface/os_interface.h" +#include "shared/source/os_interface/os_thread.h" #include "shared/source/os_interface/os_time.h" #include "shared/source/release_helper/release_helper.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" @@ -224,6 +225,7 @@ TEST(ExecutionEnvironment, givenEnableDirectSubmissionControllerSetWhenInitializ DebugManagerStateRestore restorer; debugManager.flags.EnableDirectSubmissionController.set(1); + VariableBackup funcBackup{&NEO::Thread::createFunc, [](void *(*func)(void *), void *arg) -> std::unique_ptr { return nullptr; }}; MockExecutionEnvironment executionEnvironment{}; auto controller = executionEnvironment.initializeDirectSubmissionController();