| OLD | NEW |
| 1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
| 3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
| 4 */ | 4 */ |
| 5 #include "nacl_io/kernel_object.h" | 5 #include "nacl_io/kernel_object.h" |
| 6 | 6 |
| 7 #include <assert.h> | 7 #include <assert.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <fcntl.h> | 9 #include <fcntl.h> |
| 10 #include <pthread.h> | 10 #include <pthread.h> |
| 11 | 11 |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 #include <map> | 13 #include <map> |
| 14 #include <string> | 14 #include <string> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "nacl_io/kernel_handle.h" | 17 #include "nacl_io/kernel_handle.h" |
| 18 #include "nacl_io/mount.h" | 18 #include "nacl_io/mount.h" |
| 19 #include "nacl_io/mount_node.h" | 19 #include "nacl_io/mount_node.h" |
| 20 | 20 |
| 21 #include "sdk_util/auto_lock.h" | 21 #include "sdk_util/auto_lock.h" |
| 22 #include "sdk_util/ref_object.h" | 22 #include "sdk_util/ref_object.h" |
| 23 #include "sdk_util/scoped_ref.h" | 23 #include "sdk_util/scoped_ref.h" |
| 24 | 24 |
| 25 namespace nacl_io { |
| 26 |
| 25 KernelObject::KernelObject() { | 27 KernelObject::KernelObject() { |
| 26 cwd_ = "/"; | 28 cwd_ = "/"; |
| 27 } | 29 } |
| 28 | 30 |
| 29 KernelObject::~KernelObject() {}; | 31 KernelObject::~KernelObject() {}; |
| 30 | 32 |
| 31 Error KernelObject::AttachMountAtPath(const ScopedMount& mnt, | 33 Error KernelObject::AttachMountAtPath(const ScopedMount& mnt, |
| 32 const std::string& path) { | 34 const std::string& path) { |
| 33 std::string abs_path = GetAbsParts(path).Join(); | 35 std::string abs_path = GetAbsParts(path).Join(); |
| 34 | 36 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 } | 177 } |
| 176 | 178 |
| 177 void KernelObject::FreeAndReassignFD(int fd, const ScopedKernelHandle& handle) { | 179 void KernelObject::FreeAndReassignFD(int fd, const ScopedKernelHandle& handle) { |
| 178 if (NULL == handle) { | 180 if (NULL == handle) { |
| 179 FreeFD(fd); | 181 FreeFD(fd); |
| 180 } else { | 182 } else { |
| 181 AUTO_LOCK(handle_lock_); | 183 AUTO_LOCK(handle_lock_); |
| 182 | 184 |
| 183 // If the required FD is larger than the current set, grow the set | 185 // If the required FD is larger than the current set, grow the set |
| 184 if (fd >= handle_map_.size()) | 186 if (fd >= handle_map_.size()) |
| 185 handle_map_.resize(fd + 1, ScopedRef<KernelHandle>()); | 187 handle_map_.resize(fd + 1); |
| 186 | 188 |
| 187 handle_map_[fd] = handle; | 189 handle_map_[fd] = handle; |
| 188 } | 190 } |
| 189 } | 191 } |
| 190 | 192 |
| 191 void KernelObject::FreeFD(int fd) { | 193 void KernelObject::FreeFD(int fd) { |
| 192 AUTO_LOCK(handle_lock_); | 194 AUTO_LOCK(handle_lock_); |
| 193 | 195 |
| 194 handle_map_[fd].reset(NULL); | 196 handle_map_[fd].reset(NULL); |
| 195 free_fds_.push_back(fd); | 197 free_fds_.push_back(fd); |
| 196 | 198 |
| 197 // Force lower numbered FD to be available first. | 199 // Force lower numbered FD to be available first. |
| 198 std::push_heap(free_fds_.begin(), free_fds_.end(), std::greater<int>()); | 200 std::push_heap(free_fds_.begin(), free_fds_.end(), std::greater<int>()); |
| 199 } | 201 } |
| 202 |
| 203 } // namespace nacl_io |
| OLD | NEW |