Switching to xe::mutex.

This commit is contained in:
Ben Vanik
2015-05-24 23:16:43 -07:00
parent 814ec82ad4
commit f5a2b85d42
31 changed files with 133 additions and 108 deletions

View File

@@ -122,7 +122,7 @@ void* X64CodeCache::PlaceCode(uint32_t guest_address, void* machine_code,
uint8_t* unwind_entry_address = nullptr;
size_t unwind_table_slot = 0;
{
std::lock_guard<std::mutex> allocation_lock(allocation_mutex_);
std::lock_guard<xe::mutex> allocation_lock(allocation_mutex_);
low_mark = generated_code_offset_;

View File

@@ -17,6 +17,8 @@
#include <mutex>
#include <vector>
#include "xenia/base/mutex.h"
namespace xe {
namespace cpu {
namespace backend {
@@ -54,7 +56,7 @@ class X64CodeCache {
// Must be held when manipulating the offsets or counts of anything, to keep
// the tables consistent and ordered.
std::mutex allocation_mutex_;
xe::mutex allocation_mutex_;
// Value that the indirection table will be initialized with upon commit.
uint32_t indirection_default_value_;

View File

@@ -18,7 +18,7 @@ namespace cpu {
EntryTable::EntryTable() = default;
EntryTable::~EntryTable() {
std::lock_guard<std::mutex> guard(lock_);
std::lock_guard<xe::mutex> guard(lock_);
for (auto it : map_) {
Entry* entry = it.second;
delete entry;
@@ -26,7 +26,7 @@ EntryTable::~EntryTable() {
}
Entry* EntryTable::Get(uint32_t address) {
std::lock_guard<std::mutex> guard(lock_);
std::lock_guard<xe::mutex> guard(lock_);
const auto& it = map_.find(address);
Entry* entry = it != map_.end() ? it->second : nullptr;
if (entry) {
@@ -74,7 +74,7 @@ Entry::Status EntryTable::GetOrCreate(uint32_t address, Entry** out_entry) {
}
std::vector<Function*> EntryTable::FindWithAddress(uint32_t address) {
std::lock_guard<std::mutex> guard(lock_);
std::lock_guard<xe::mutex> guard(lock_);
std::vector<Function*> fns;
for (auto& it : map_) {
Entry* entry = it.second;

View File

@@ -14,6 +14,8 @@
#include <unordered_map>
#include <vector>
#include "xenia/base/mutex.h"
namespace xe {
namespace cpu {
@@ -45,7 +47,7 @@ class EntryTable {
private:
// TODO(benvanik): replace with a better data structure.
std::mutex lock_;
xe::mutex lock_;
std::unordered_map<uint32_t, Entry*> map_;
};

View File

@@ -61,7 +61,7 @@ void CheckGlobalLock(PPCContext* ppc_state, void* arg0, void* arg1) {
ppc_state->scratch = 0x8000;
}
void HandleGlobalLock(PPCContext* ppc_state, void* arg0, void* arg1) {
std::mutex* global_lock = reinterpret_cast<std::mutex*>(arg0);
auto global_lock = reinterpret_cast<xe::mutex*>(arg0);
volatile bool* global_lock_taken = reinterpret_cast<bool*>(arg1);
uint64_t value = ppc_state->scratch;
if (value == 0x8000) {

View File

@@ -13,6 +13,7 @@
#include <memory>
#include <mutex>
#include "xenia/base/mutex.h"
#include "xenia/base/type_pool.h"
#include "xenia/cpu/frontend/context_info.h"
#include "xenia/cpu/function.h"
@@ -32,7 +33,7 @@ namespace frontend {
class PPCTranslator;
struct PPCBuiltins {
std::mutex global_lock;
xe::mutex global_lock;
bool global_lock_taken;
FunctionInfo* check_global_lock;
FunctionInfo* handle_global_lock;

View File

@@ -24,7 +24,7 @@ Function::Function(FunctionInfo* symbol_info)
Function::~Function() = default;
bool Function::AddBreakpoint(Breakpoint* breakpoint) {
std::lock_guard<std::mutex> guard(lock_);
std::lock_guard<xe::mutex> guard(lock_);
bool found = false;
for (auto other : breakpoints_) {
if (other == breakpoint) {
@@ -41,7 +41,7 @@ bool Function::AddBreakpoint(Breakpoint* breakpoint) {
}
bool Function::RemoveBreakpoint(Breakpoint* breakpoint) {
std::lock_guard<std::mutex> guard(lock_);
std::lock_guard<xe::mutex> guard(lock_);
for (auto it = breakpoints_.begin(); it != breakpoints_.end(); ++it) {
if (*it == breakpoint) {
if (!RemoveBreakpointImpl(breakpoint)) {
@@ -54,7 +54,7 @@ bool Function::RemoveBreakpoint(Breakpoint* breakpoint) {
}
Breakpoint* Function::FindBreakpoint(uint32_t address) {
std::lock_guard<std::mutex> guard(lock_);
std::lock_guard<xe::mutex> guard(lock_);
Breakpoint* result = nullptr;
for (auto breakpoint : breakpoints_) {
if (breakpoint->address() == address) {

View File

@@ -14,6 +14,7 @@
#include <mutex>
#include <vector>
#include "xenia/base/mutex.h"
#include "xenia/cpu/debug_info.h"
#include "xenia/cpu/thread_state.h"
#include "xenia/debug/breakpoint.h"
@@ -53,7 +54,7 @@ class Function {
std::unique_ptr<DebugInfo> debug_info_;
// TODO(benvanik): move elsewhere? DebugData?
std::mutex lock_;
xe::mutex lock_;
std::vector<debug::Breakpoint*> breakpoints_;
};

View File

@@ -15,6 +15,8 @@
#include <mutex>
#include <vector>
#include "xenia/base/mutex.h"
namespace xe {
namespace cpu {
@@ -85,7 +87,7 @@ class MMIOHandler {
std::vector<MMIORange> mapped_ranges_;
// TODO(benvanik): data structure magic.
std::mutex write_watch_mutex_;
xe::mutex write_watch_mutex_;
std::list<WriteWatchEntry*> write_watches_;
static MMIOHandler* global_handler_;

View File

@@ -151,7 +151,7 @@ SymbolInfo::Status Module::DefineVariable(VariableInfo* symbol_info) {
void Module::ForEachFunction(std::function<void(FunctionInfo*)> callback) {
SCOPE_profile_cpu_f("cpu");
std::lock_guard<std::mutex> guard(lock_);
std::lock_guard<xe::mutex> guard(lock_);
for (auto& symbol_info : list_) {
if (symbol_info->type() == SymbolInfo::TYPE_FUNCTION) {
FunctionInfo* info = static_cast<FunctionInfo*>(symbol_info.get());
@@ -163,7 +163,7 @@ void Module::ForEachFunction(std::function<void(FunctionInfo*)> callback) {
void Module::ForEachFunction(size_t since, size_t& version,
std::function<void(FunctionInfo*)> callback) {
SCOPE_profile_cpu_f("cpu");
std::lock_guard<std::mutex> guard(lock_);
std::lock_guard<xe::mutex> guard(lock_);
size_t count = list_.size();
version = count;
for (size_t n = since; n < count; n++) {

View File

@@ -16,8 +16,9 @@
#include <unordered_map>
#include <vector>
#include "xenia/memory.h"
#include "xenia/base/mutex.h"
#include "xenia/cpu/symbol_info.h"
#include "xenia/memory.h"
namespace xe {
namespace cpu {
@@ -62,7 +63,7 @@ class Module {
private:
// TODO(benvanik): replace with a better data structure.
std::mutex lock_;
xe::mutex lock_;
std::unordered_map<uint32_t, SymbolInfo*> map_;
std::vector<std::unique_ptr<SymbolInfo>> list_;
};

View File

@@ -89,7 +89,7 @@ Processor::~Processor() {
}
{
std::lock_guard<std::mutex> guard(modules_lock_);
std::lock_guard<xe::mutex> guard(modules_lock_);
modules_.clear();
}
@@ -159,13 +159,13 @@ bool Processor::Setup() {
}
bool Processor::AddModule(std::unique_ptr<Module> module) {
std::lock_guard<std::mutex> guard(modules_lock_);
std::lock_guard<xe::mutex> guard(modules_lock_);
modules_.push_back(std::move(module));
return true;
}
Module* Processor::GetModule(const char* name) {
std::lock_guard<std::mutex> guard(modules_lock_);
std::lock_guard<xe::mutex> guard(modules_lock_);
for (const auto& module : modules_) {
if (module->name() == name) {
return module.get();
@@ -175,7 +175,7 @@ Module* Processor::GetModule(const char* name) {
}
std::vector<Module*> Processor::GetModules() {
std::lock_guard<std::mutex> guard(modules_lock_);
std::lock_guard<xe::mutex> guard(modules_lock_);
std::vector<Module*> clone(modules_.size());
for (const auto& module : modules_) {
clone.push_back(module.get());
@@ -242,7 +242,7 @@ bool Processor::LookupFunctionInfo(uint32_t address,
// Find the module that contains the address.
Module* code_module = nullptr;
{
std::lock_guard<std::mutex> guard(modules_lock_);
std::lock_guard<xe::mutex> guard(modules_lock_);
// TODO(benvanik): sort by code address (if contiguous) so can bsearch.
// TODO(benvanik): cache last module low/high, as likely to be in there.
for (const auto& module : modules_) {
@@ -378,7 +378,7 @@ uint64_t Processor::ExecuteInterrupt(uint32_t cpu, uint32_t address,
SCOPE_profile_cpu_f("cpu");
// Acquire lock on interrupt thread (we can only dispatch one at a time).
std::lock_guard<std::mutex> lock(interrupt_thread_lock_);
std::lock_guard<xe::mutex> lock(interrupt_thread_lock_);
// Set 0x10C(r13) to the current CPU ID.
xe::store_and_swap<uint8_t>(

View File

@@ -13,6 +13,7 @@
#include <mutex>
#include <vector>
#include "xenia/base/mutex.h"
#include "xenia/cpu/backend/backend.h"
#include "xenia/cpu/entry_table.h"
#include "xenia/cpu/export_resolver.h"
@@ -90,13 +91,13 @@ class Processor {
ExportResolver* export_resolver_;
EntryTable entry_table_;
std::mutex modules_lock_;
xe::mutex modules_lock_;
std::vector<std::unique_ptr<Module>> modules_;
Module* builtin_module_;
uint32_t next_builtin_address_;
Irql irql_;
std::mutex interrupt_thread_lock_;
xe::mutex interrupt_thread_lock_;
ThreadState* interrupt_thread_state_;
uint32_t interrupt_thread_block_;
};