MCPcopy Create free account
hub / github.com/Simple-XX/SimpleKernel / operator=

Method operator=

src/filesystem/file_descriptor.cpp:33–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31}
32
33auto FileDescriptorTable::operator=(FileDescriptorTable&& other)
34 -> FileDescriptorTable& {
35 if (this != &other) {
36 // 先关闭当前的所有文件
37 CloseAll().or_else([](auto&& err) {
38 klog::Warn("Failed to close all files in move assignment: {}",
39 err.message());
40 return Expected<void>{};
41 });
42
43 // 使用地址确定加锁顺序,避免死锁
44 auto* first_lock = (this < &other) ? &lock_ : &other.lock_;
45 auto* second_lock = (this < &other) ? &other.lock_ : &lock_;
46 LockGuard guard1(*first_lock);
47 LockGuard guard2(*second_lock);
48
49 for (int i = 0; i < kMaxFd; ++i) {
50 table_[i] = other.table_[i];
51 other.table_[i] = nullptr;
52 }
53
54 open_count_ = other.open_count_;
55 other.open_count_ = 0;
56 }
57
58 return *this;
59}
60
61auto FileDescriptorTable::Alloc(vfs::File* file) -> Expected<int> {
62 if (file == nullptr) {

Callers

nothing calls this directly

Calls 2

WarnFunction · 0.85
messageMethod · 0.80

Tested by

no test coverage detected