[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 f4848c875f
commit 9492aaeba0
9 changed files with 10 additions and 49 deletions
+10 -1
View File
@@ -198,7 +198,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() {};
-11
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());
-1
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;
-11
View File
@@ -123,17 +123,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());
-1
View File
@@ -38,7 +38,6 @@ class XmaContextMaster : public XmaContext {
bool Work();
void Enable();
bool Block(bool poll);
void Clear();
void Disable();
void Release();
-11
View File
@@ -204,17 +204,6 @@ 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_);
ClearLocked();
-1
View File
@@ -55,7 +55,6 @@ class XmaContextNew : public XmaContext {
bool Work();
void Enable();
bool Block(bool poll);
void Clear();
void Disable();
void Release();
-11
View File
@@ -124,17 +124,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());
-1
View File
@@ -38,7 +38,6 @@ class XmaContextOld : public XmaContext {
bool Work();
void Enable();
bool Block(bool poll);
void Clear();
void Disable();
void Release();