Skip to content

Commit 4fbb4e3

Browse files
committed
updates
1 parent a61522b commit 4fbb4e3

16 files changed

Lines changed: 189 additions & 91 deletions

File tree

kernel/interfaces/lib/time.cppm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ export
1212
{
1313
time_t tv_sec;
1414
suseconds_t tv_usec;
15+
16+
constexpr std::uint64_t to_ns() const
17+
{
18+
return tv_sec * 1'000'000'000ul + tv_usec * 1'000;
19+
}
20+
21+
constexpr std::uint64_t to_ms() const
22+
{
23+
return tv_sec * 1000ul + tv_usec / 1'000;
24+
}
1525
};
1626

1727
struct itimerval

kernel/interfaces/system/proc/mutex.cppm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export namespace sched
6767
lib::panic("mutex deadlock");
6868
}
6969

70-
if (_waiters.wait())
70+
if (_waiters.wait().interrupted)
7171
return false;
7272
}
7373
}
@@ -121,7 +121,7 @@ export namespace sched
121121
if (now >= deadline)
122122
return false;
123123

124-
if (_waiters.wait(deadline - now))
124+
if (_waiters.wait(deadline - now).interrupted)
125125
return false;
126126
}
127127
}
@@ -200,7 +200,7 @@ export namespace sched
200200
}
201201
}
202202

203-
if (_waiters.wait())
203+
if (_waiters.wait().interrupted)
204204
return false;
205205
}
206206
}
@@ -281,7 +281,7 @@ export namespace sched
281281
if (now >= deadline)
282282
return false;
283283

284-
if (_waiters.wait(deadline - now))
284+
if (_waiters.wait(deadline - now).interrupted)
285285
return false;
286286
}
287287
}

kernel/interfaces/system/proc/wait_queue.cppm

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,17 @@ export namespace sched
4747
std::atomic<wait_queue_entry_t *> &entry_ref
4848
);
4949

50-
bool wait(std::uint64_t ns = 0);
51-
void wait_unint(std::uint64_t ns = 0);
50+
struct wait_result_t
51+
{
52+
bool interrupted;
53+
bool expired;
54+
};
55+
56+
wait_result_t wait(std::uint64_t ns = 0);
57+
wait_result_t wait_unint(std::uint64_t ns = 0);
5258

5359
std::size_t snapshot_gen() const;
54-
bool wait_prepared(std::size_t gen, std::uint64_t ns = 0);
60+
wait_result_t wait_prepared(std::size_t gen, std::uint64_t ns = 0);
5561

5662
void wake_one(bool drop = false);
5763
void wake_all();

kernel/interfaces/system/vfs/vfs.cppm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,16 @@ export namespace vfs
394394
lib::locked_ptr<filesystem::instance, sched::mutex> fs;
395395
std::shared_ptr<dentry> root;
396396
std::optional<path> mounted_on;
397+
398+
std::size_t id;
399+
std::size_t parent_id;
397400
std::uint64_t flags = 0;
398401

399402
std::string fstype;
400403
std::string source;
404+
405+
mount(lib::locked_ptr<filesystem::instance, sched::mutex> fs, std::shared_ptr<dentry> root)
406+
: fs { std::move(fs) }, root { std::move(root) } { }
401407
};
402408

403409
struct inode
@@ -710,6 +716,7 @@ export namespace vfs
710716
};
711717

712718
path get_root(bool absolute);
719+
std::shared_ptr<mount> get_mount(std::size_t id);
713720

714721
bool register_fs(std::unique_ptr<filesystem> fs);
715722
auto find_fs(std::string_view name)

kernel/source/drivers/fs/dev/tty.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,12 +868,15 @@ namespace fs::dev::tty
868868
return progress;
869869

870870
in_locked.unlock();
871-
bool interrupted = in_wq.wait(ms * 1'000'000);
871+
const auto [interrupted, expired] = in_wq.wait(ms * 1'000'000);
872872
in_locked.lock();
873873

874874
available = get_available(in_locked);
875875
if (!interrupted && available == 0) // expired
876+
{
877+
lib::bug_on(!expired);
876878
return progress;
879+
}
877880
}
878881
}
879882
return progress;

kernel/source/drivers/fs/devpts.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace fs::devpts
2626
{
2727
lib::unused(src, data);
2828

29-
auto mount = std::make_shared<struct vfs::mount>(instance, root, std::nullopt);
29+
auto mount = std::make_shared<struct vfs::mount>(instance, root);
3030
mounts.push_back(mount);
3131
return mount;
3232
}
@@ -48,7 +48,7 @@ namespace fs::devpts
4848
);
4949
root->parent = root;
5050

51-
internal_mnt = std::make_shared<struct vfs::mount>(instance, root, std::nullopt);
51+
internal_mnt = std::make_shared<struct vfs::mount>(instance, root);
5252
}
5353
};
5454

kernel/source/drivers/fs/devtmpfs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace fs::devtmpfs
2424
{
2525
lib::unused(src, data);
2626

27-
auto mount = std::make_shared<struct vfs::mount>(instance, root, std::nullopt);
27+
auto mount = std::make_shared<struct vfs::mount>(instance, root);
2828
mounts.push_back(mount);
2929
return mount;
3030
}
@@ -46,7 +46,7 @@ namespace fs::devtmpfs
4646
);
4747
root->parent = root;
4848

49-
internal_mnt = std::make_shared<struct vfs::mount>(instance, root, std::nullopt);
49+
internal_mnt = std::make_shared<struct vfs::mount>(instance, root);
5050
}
5151
};
5252

kernel/source/drivers/fs/procfs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ namespace fs::procfs
725725
{
726726
lib::unused(src, data);
727727

728-
auto mount = std::make_shared<struct vfs::mount>(inst, root, std::nullopt);
728+
auto mount = std::make_shared<struct vfs::mount>(inst, root);
729729
mounts.lock()->push_back(mount);
730730
return mount;
731731
}
@@ -741,7 +741,7 @@ namespace fs::procfs
741741
root->inode = locked->mkroot();
742742
root->parent = root;
743743

744-
internal_mnt = std::make_shared<struct vfs::mount>(inst, root, std::nullopt);
744+
internal_mnt = std::make_shared<struct vfs::mount>(inst, root);
745745
}
746746
};
747747

kernel/source/drivers/fs/stubs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace fs::stubs
3939
{
4040
lib::unused(src, data);
4141

42-
auto mount = std::make_shared<struct vfs::mount>(instance, root, std::nullopt);
42+
auto mount = std::make_shared<struct vfs::mount>(instance, root);
4343
mounts.push_back(mount);
4444
return mount;
4545
}

kernel/source/drivers/fs/tmpfs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ namespace fs::tmpfs
418418
root->inode->stat.st_gid = locked->opt_gid;
419419
root->parent = root;
420420

421-
auto mount = std::make_shared<struct vfs::mount>(std::move(instance), root, std::nullopt);
421+
auto mount = std::make_shared<struct vfs::mount>(std::move(instance), root);
422422
mounts.push_back(mount);
423423
return mount;
424424
}

0 commit comments

Comments
 (0)