CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
96 lines
1.8 KiB
C++
96 lines
1.8 KiB
C++
/*
|
|
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <condition_variable>
|
|
#include <mutex>
|
|
#include <thread>
|
|
|
|
/*
|
|
Guarantees total ordering between parent and child thread
|
|
PARENT CHILD
|
|
THREAD THREAD
|
|
TestPart1
|
|
\
|
|
\
|
|
\
|
|
TestPart2
|
|
/
|
|
/
|
|
/
|
|
TestPart3
|
|
\
|
|
\
|
|
\
|
|
TestPart4
|
|
Usage:
|
|
Define a derived class which inherits from ThreadedZigZagTest instantiated with that selfsame class,
|
|
which implements the appropriate test methods
|
|
class DerivedTestClass : public ThreadedZigZagTest<DerivedTestClass> {
|
|
void TestPart1() {...}
|
|
void TestPart2() {...}
|
|
void TestPart3() {...}
|
|
void TestPart4() {...}
|
|
};
|
|
The derived class can contain state that the test requires.
|
|
*/
|
|
|
|
template <typename T> class ThreadedZigZagTest {
|
|
public:
|
|
void run() {
|
|
// 1.
|
|
static_cast<T*>(this)->TestPart1();
|
|
|
|
auto t = std::thread([this] {
|
|
// 2.
|
|
static_cast<T*>(this)->TestPart2();
|
|
|
|
{
|
|
std::lock_guard<std::mutex> lock(mtx_);
|
|
ready_ = true;
|
|
}
|
|
cv_.notify_one();
|
|
|
|
{
|
|
std::unique_lock<std::mutex> lock(mtx_);
|
|
cv_.wait(lock, [this] { return !ready_; });
|
|
}
|
|
|
|
// 4.
|
|
static_cast<T*>(this)->TestPart4();
|
|
});
|
|
|
|
{
|
|
std::unique_lock<std::mutex> lock(mtx_);
|
|
cv_.wait(lock, [this] { return ready_; });
|
|
}
|
|
|
|
// 3.
|
|
static_cast<T*>(this)->TestPart3();
|
|
|
|
{
|
|
std::lock_guard<std::mutex> lock(mtx_);
|
|
ready_ = false;
|
|
}
|
|
cv_.notify_one();
|
|
|
|
// Finalize
|
|
t.join();
|
|
HIP_CHECK_THREAD_FINALIZE();
|
|
}
|
|
|
|
void TestPart1() const {}
|
|
void TestPart2() const {}
|
|
void TestPart3() const {}
|
|
void TestPart4() const {}
|
|
|
|
private:
|
|
std::mutex mtx_;
|
|
std::condition_variable cv_;
|
|
bool ready_ = false;
|
|
}; |