use scoped_lock instead of unique_lock

This commit is contained in:
georgemoralis 2023-11-08 08:21:11 +02:00
parent 9fb5852f2e
commit 76e24202da
1 changed files with 7 additions and 7 deletions

View File

@ -7,7 +7,7 @@ namespace Core::FileSys {
constexpr int RESERVED_HANDLES = 3; //first 3 handles are stdin,stdout,stderr constexpr int RESERVED_HANDLES = 3; //first 3 handles are stdin,stdout,stderr
void MntPoints::mount(const std::string& host_folder, const std::string& guest_folder) { void MntPoints::mount(const std::string& host_folder, const std::string& guest_folder) {
std::unique_lock lock{m_mutex}; std::scoped_lock lock{m_mutex};
MntPair pair; MntPair pair;
pair.host_path = host_folder; pair.host_path = host_folder;
@ -17,11 +17,11 @@ void MntPoints::mount(const std::string& host_folder, const std::string& guest_f
} }
void MntPoints::unmount(const std::string& path) {} // TODO! void MntPoints::unmount(const std::string& path) {} // TODO!
void MntPoints::unmountAll() { void MntPoints::unmountAll() {
std::unique_lock lock{m_mutex}; std::scoped_lock lock{m_mutex};
m_mnt_pairs.clear(); m_mnt_pairs.clear();
} }
std::string MntPoints::getHostDirectory(const std::string& guest_directory) { std::string MntPoints::getHostDirectory(const std::string& guest_directory) {
std::unique_lock lock{m_mutex}; std::scoped_lock lock{m_mutex};
for (auto& pair : m_mnt_pairs) { for (auto& pair : m_mnt_pairs) {
if (pair.guest_path.starts_with(guest_directory)) { if (pair.guest_path.starts_with(guest_directory)) {
return pair.host_path + guest_directory; return pair.host_path + guest_directory;
@ -37,7 +37,7 @@ std::string MntPoints::getHostDirectory(const std::string& guest_directory) {
return ""; return "";
} }
int HandleTable::createHandle() { int HandleTable::createHandle() {
std::unique_lock lock{m_mutex}; std::scoped_lock lock{m_mutex};
auto* file = new File{}; auto* file = new File{};
file->isDirectory = false; file->isDirectory = false;
file->isOpened = false; file->isOpened = false;
@ -56,17 +56,17 @@ int HandleTable::createHandle() {
return m_files.size() + RESERVED_HANDLES - 1; return m_files.size() + RESERVED_HANDLES - 1;
} }
void HandleTable::deleteHandle(int d) { void HandleTable::deleteHandle(int d) {
std::unique_lock lock{m_mutex}; std::scoped_lock lock{m_mutex};
delete m_files.at(d - RESERVED_HANDLES); delete m_files.at(d - RESERVED_HANDLES);
m_files[d - RESERVED_HANDLES] = nullptr; m_files[d - RESERVED_HANDLES] = nullptr;
} }
File* HandleTable::getFile(int d) { File* HandleTable::getFile(int d) {
std::unique_lock lock{m_mutex}; std::scoped_lock lock{m_mutex};
return m_files.at(d - RESERVED_HANDLES); return m_files.at(d - RESERVED_HANDLES);
} }
File* HandleTable::getFile(const std::string& host_name) { File* HandleTable::getFile(const std::string& host_name) {
std::unique_lock lock{m_mutex}; std::scoped_lock lock{m_mutex};
for (auto* file : m_files) { for (auto* file : m_files) {
if (file != nullptr && file->m_host_name == host_name) { if (file != nullptr && file->m_host_name == host_name) {
return file; return file;