[CPU] Use RAII lock_guard in GuestTrampolineGroup
This commit is contained in:
@@ -133,30 +133,25 @@ struct GuestTrampolineGroup
|
|||||||
xe_mutex m_mutex;
|
xe_mutex m_mutex;
|
||||||
|
|
||||||
uint32_t _NewTrampoline(SimpleGuestTrampolineProc proc, bool longterm) {
|
uint32_t _NewTrampoline(SimpleGuestTrampolineProc proc, bool longterm) {
|
||||||
uint32_t result;
|
std::lock_guard<xe_mutex> lock(m_mutex);
|
||||||
m_mutex.lock();
|
|
||||||
auto iter = this->find(proc);
|
auto iter = this->find(proc);
|
||||||
if (iter == this->end()) {
|
if (iter == this->end()) {
|
||||||
uint32_t new_entry = longterm
|
uint32_t new_entry = longterm
|
||||||
? m_backend->CreateLongTermGuestTrampoline(proc)
|
? m_backend->CreateLongTermGuestTrampoline(proc)
|
||||||
: m_backend->CreateGuestTrampoline(proc);
|
: m_backend->CreateGuestTrampoline(proc);
|
||||||
this->emplace_hint(iter, proc, new_entry);
|
this->emplace_hint(iter, proc, new_entry);
|
||||||
result = new_entry;
|
return new_entry;
|
||||||
} else {
|
|
||||||
result = iter->second;
|
|
||||||
}
|
}
|
||||||
m_mutex.unlock();
|
return iter->second;
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GuestTrampolineGroup(Backend* backend) : m_backend(backend) {}
|
GuestTrampolineGroup(Backend* backend) : m_backend(backend) {}
|
||||||
~GuestTrampolineGroup() {
|
~GuestTrampolineGroup() {
|
||||||
m_mutex.lock();
|
std::lock_guard<xe_mutex> lock(m_mutex);
|
||||||
for (auto&& entry : *this) {
|
for (auto&& entry : *this) {
|
||||||
m_backend->FreeGuestTrampoline(entry.second);
|
m_backend->FreeGuestTrampoline(entry.second);
|
||||||
}
|
}
|
||||||
m_mutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t NewLongtermTrampoline(SimpleGuestTrampolineProc proc) {
|
uint32_t NewLongtermTrampoline(SimpleGuestTrampolineProc proc) {
|
||||||
|
|||||||
Reference in New Issue
Block a user