| 508 | |
| 509 | template <> |
| 510 | Status FileCache::DoOpenFile(const string& file_name, |
| 511 | shared_ptr<internal::Descriptor<RWFile>>* file, |
| 512 | bool* created_desc) { |
| 513 | shared_ptr<internal::Descriptor<RWFile>> d; |
| 514 | bool cd; |
| 515 | { |
| 516 | std::lock_guard<simple_spinlock> l(lock_); |
| 517 | d = FindDescriptorUnlocked(file_name, FindMode::CREATE_IF_NOT_EXIST, |
| 518 | &rwf_descs_, &cd); |
| 519 | DCHECK(d); |
| 520 | |
| 521 | #ifndef NDEBUG |
| 522 | // Enforce the invariant that a particular file name may only be used by one |
| 523 | // descriptor at a time. This is expensive so it's only done in DEBUG mode. |
| 524 | bool ignored; |
| 525 | CHECK(!FindDescriptorUnlocked(file_name, FindMode::DONT_CREATE, |
| 526 | &raf_descs_, &ignored)); |
| 527 | #endif |
| 528 | } |
| 529 | if (d->base_.deleted()) { |
| 530 | return Status::NotFound(kAlreadyDeleted, file_name); |
| 531 | } |
| 532 | *file = std::move(d); |
| 533 | *created_desc = cd; |
| 534 | return Status::OK(); |
| 535 | } |
| 536 | |
| 537 | template <> |
| 538 | Status FileCache::DoOpenFile(const string& file_name, |