[Kernel] ReleaseSemaphore for Posix to match Windows semantics

This commit is contained in:
Herman S.
2025-10-12 20:30:29 +09:00
parent 28e48410c5
commit 32b8c341ee
4 changed files with 32 additions and 13 deletions

View File

@@ -320,14 +320,15 @@ class PosixCondition<Semaphore> final : public PosixConditionBase {
bool Signal() override { return Release(1, nullptr); }
bool Release(uint32_t release_count, int* out_previous_count) {
if (maximum_count_ - count_ >= release_count) {
auto lock = std::unique_lock(mutex_);
if (out_previous_count) *out_previous_count = count_;
count_ += release_count;
cond_.notify_all();
return true;
auto lock = std::unique_lock(mutex_);
// Validate that releasing would not exceed the maximum count
if (count_ + release_count > maximum_count_) {
return false;
}
return false;
if (out_previous_count) *out_previous_count = count_;
count_ += release_count;
cond_.notify_all();
return true;
}
private: