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> |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 | 246 |
247 void KernelObject::FreeAndReassignFD(int fd, | 247 void KernelObject::FreeAndReassignFD(int fd, |
248 const ScopedKernelHandle& handle, | 248 const ScopedKernelHandle& handle, |
249 const std::string& path) { | 249 const std::string& path) { |
250 if (NULL == handle) { | 250 if (NULL == handle) { |
251 FreeFD(fd); | 251 FreeFD(fd); |
252 } else { | 252 } else { |
253 AUTO_LOCK(handle_lock_); | 253 AUTO_LOCK(handle_lock_); |
254 | 254 |
255 // If the required FD is larger than the current set, grow the set | 255 // If the required FD is larger than the current set, grow the set |
256 if (fd >= (int)handle_map_.size()) | 256 if (fd >= (int)handle_map_.size()) { |
binji
2014/12/12 18:55:20
use c++-style cast
bradn
2014/12/12 22:58:18
Done.
| |
257 int sz = (int)handle_map_.size(); | |
Sam Clegg
2014/12/12 00:44:40
Move this line outside the condition to avoid call
bradn
2014/12/12 22:58:18
Done.
| |
257 handle_map_.resize(fd + 1); | 258 handle_map_.resize(fd + 1); |
Sam Clegg
2014/12/12 00:44:40
A comment here to describe what is happening and w
bradn
2014/12/12 22:58:18
Done.
| |
259 for (; sz < fd; ++sz) { | |
260 free_fds_.push_back(sz); | |
261 std::push_heap(free_fds_.begin(), free_fds_.end(), | |
262 std::greater<int>()); | |
263 } | |
264 } | |
258 | 265 |
259 // This path will be from an existing handle, and absolute. | 266 // This path will be from an existing handle, and absolute. |
260 handle_map_[fd] = Descriptor_t(handle, path); | 267 handle_map_[fd] = Descriptor_t(handle, path); |
261 } | 268 } |
262 } | 269 } |
263 | 270 |
264 void KernelObject::FreeFD(int fd) { | 271 void KernelObject::FreeFD(int fd) { |
265 AUTO_LOCK(handle_lock_); | 272 AUTO_LOCK(handle_lock_); |
266 | 273 |
267 handle_map_[fd].handle.reset(NULL); | 274 handle_map_[fd].handle.reset(NULL); |
268 free_fds_.push_back(fd); | 275 free_fds_.push_back(fd); |
269 | 276 |
270 // Force lower numbered FD to be available first. | 277 // Force lower numbered FD to be available first. |
271 std::push_heap(free_fds_.begin(), free_fds_.end(), std::greater<int>()); | 278 std::push_heap(free_fds_.begin(), free_fds_.end(), std::greater<int>()); |
272 } | 279 } |
273 | 280 |
274 } // namespace nacl_io | 281 } // namespace nacl_io |
OLD | NEW |