Adding locks and parents to vfs.

Progress on #305.
This commit is contained in:
Ben Vanik
2015-06-29 05:07:29 -07:00
parent 9a80b5e5be
commit 0104a2290f
16 changed files with 65 additions and 40 deletions

View File

@@ -16,8 +16,9 @@
namespace xe {
namespace vfs {
Entry::Entry(Device* device, const std::string& path)
Entry::Entry(Device* device, Entry* parent, const std::string& path)
: device_(device),
parent_(parent),
path_(path),
attributes_(0),
size_(0),
@@ -46,6 +47,7 @@ void Entry::Dump(xe::StringBuffer* string_buffer, int indent) {
bool Entry::is_read_only() const { return device_->is_read_only(); }
Entry* Entry::GetChild(std::string name) {
std::lock_guard<xe::mutex> lock(device_->mutex());
// TODO(benvanik): a faster search
for (auto& child : children_) {
if (strcasecmp(child->name().c_str(), name.c_str()) == 0) {
@@ -57,6 +59,7 @@ Entry* Entry::GetChild(std::string name) {
Entry* Entry::IterateChildren(const xe::filesystem::WildcardEngine& engine,
size_t* current_index) {
std::lock_guard<xe::mutex> lock(device_->mutex());
while (*current_index < children_.size()) {
auto& child = children_[*current_index];
*current_index = *current_index + 1;