Skip to content

Conversation

@Kellesi
Copy link
Collaborator

@Kellesi Kellesi commented Aug 15, 2025

@Kellesi Kellesi requested a review from Copilot August 15, 2025 14:22

This comment was marked as outdated.

@Kellesi Kellesi force-pushed the KF-30-test-Semaphore branch from eb411d0 to 18d496b Compare August 15, 2025 15:39
@Kellesi Kellesi requested a review from Copilot August 15, 2025 15:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive unit tests for the kf::Semaphore class to validate its basic functionality including wait/release operations, timeout behavior, and limit enforcement. The changes also include a minor enhancement to the Semaphore implementation to prevent releasing beyond the maximum limit.

  • Adds new test file SemaphoreTest.cpp with comprehensive test scenarios covering various semaphore behaviors
  • Updates CMakeLists.txt to include the new test file in the build
  • Enhances Semaphore implementation to check and enforce limit constraints during release operations

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
test/SemaphoreTest.cpp New comprehensive test suite covering semaphore wait/release scenarios, timeout behavior, and limit enforcement
test/CMakeLists.txt Adds SemaphoreTest.cpp to the test build configuration
include/kf/Semaphore.h Adds limit enforcement logic and stores limit value for validation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


private:
LONG m_limit = 0;
KSEMAPHORE m_semaphore;
Copy link

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a race condition between reading the semaphore state and releasing it. Another thread could modify the semaphore count between these operations, potentially allowing the count to exceed the limit. Consider using atomic operations or proper synchronization.

Suggested change
KSEMAPHORE m_semaphore;
{
KIRQL oldIrql;
KeAcquireSpinLock(&m_lock, &oldIrql);
LONG currentCount = KeReadStateSemaphore(&m_semaphore);
if (currentCount + adjustment > m_limit)
{
KeReleaseSpinLock(&m_lock, oldIrql);
return;
}
KeReleaseSemaphore(&m_semaphore, IO_NO_INCREMENT, adjustment, false);
KeReleaseSpinLock(&m_lock, oldIrql);
}
private:
LONG m_limit = 0;
KSEMAPHORE m_semaphore;
KSPIN_LOCK m_lock;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants