[APU] Move XmaContext::Block() to base class with RAII locking

This commit is contained in:
Herman S.
2026-02-10 00:12:27 +09:00
parent b0a387c6ea
commit 0efd3a9610
9 changed files with 10 additions and 49 deletions

View File

@@ -203,7 +203,16 @@ class XmaContext {
virtual bool Work() { return false; };
virtual void Enable() {};
virtual bool Block(bool poll) { return 0; };
virtual bool Block(bool poll) {
std::unique_lock<xe_mutex> lock(lock_, std::try_to_lock);
if (!lock.owns_lock()) {
if (poll) {
return false;
}
lock.lock();
}
return true;
}
virtual void Clear() {};
virtual void Disable() {};
virtual void Release() {};

View File

@@ -139,17 +139,6 @@ void XmaContextFake::Enable() {
set_is_enabled(true);
}
bool XmaContextFake::Block(bool poll) {
if (!lock_.try_lock()) {
if (poll) {
return false;
}
lock_.lock();
}
lock_.unlock();
return true;
}
void XmaContextFake::Clear() {
std::lock_guard<xe_mutex> lock(lock_);
XELOGAPU("XmaContextFake: reset context {}", id());

View File

@@ -36,7 +36,6 @@ class XmaContextFake : public XmaContext {
bool Work() override;
void Enable() override;
bool Block(bool poll) override;
void Clear() override;
void Disable() override;
void Release() override;

View File

@@ -122,17 +122,6 @@ void XmaContextMaster::Enable() {
set_is_enabled(true);
}
bool XmaContextMaster::Block(bool poll) {
if (!lock_.try_lock()) {
if (poll) {
return false;
}
lock_.lock();
}
lock_.unlock();
return true;
}
void XmaContextMaster::Clear() {
std::lock_guard<xe_mutex> lock(lock_);
XELOGAPU("XmaContext: reset context {}", id());

View File

@@ -38,7 +38,6 @@ class XmaContextMaster : public XmaContext {
bool Work();
void Enable();
bool Block(bool poll);
void Clear();
void Disable();
void Release();

View File

@@ -208,17 +208,6 @@ bool XmaContextNew::Work() {
void XmaContextNew::Enable() { set_is_enabled(true); }
bool XmaContextNew::Block(bool poll) {
if (!lock_.try_lock()) {
if (poll) {
return false;
}
lock_.lock();
}
lock_.unlock();
return true;
}
void XmaContextNew::Clear() {
std::lock_guard<xe_mutex> lock(lock_);

View File

@@ -55,7 +55,6 @@ class XmaContextNew : public XmaContext {
bool Work();
void Enable();
bool Block(bool poll);
void Clear();
void Disable();
void Release();

View File

@@ -123,17 +123,6 @@ void XmaContextOld::Enable() {
set_is_enabled(true);
}
bool XmaContextOld::Block(bool poll) {
if (!lock_.try_lock()) {
if (poll) {
return false;
}
lock_.lock();
}
lock_.unlock();
return true;
}
void XmaContextOld::Clear() {
std::lock_guard<xe_mutex> lock(lock_);
XELOGAPU("XmaContext: reset context {}", id());

View File

@@ -38,7 +38,6 @@ class XmaContextOld : public XmaContext {
bool Work();
void Enable();
bool Block(bool poll);
void Clear();
void Disable();
void Release();