Skip to content

Conversation

@yycptt
Copy link
Member

@yycptt yycptt commented Feb 11, 2026

What changed?

  • When checking waiters, only check waiter with higher or equal priority.
  • Allow specifying priority in TryAcquire()

Why?

  • If there's all waiters have lower priority, we don't really need to create a new waiter and later unblock it.

How did you test it?

  • built
  • run locally and tested manually
  • covered by existing tests
  • added new unit test(s)
  • added new functional test(s)

@yycptt yycptt requested a review from prathyushpv February 11, 2026 00:50
// On success, returns true. On failure, returns false and leaves the semaphore unchanged.
func (s *PrioritySemaphoreImpl) TryAcquire(n int) bool {
func (s *PrioritySemaphoreImpl) TryAcquire(priority Priority, n int) bool {
s.mu.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

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

It is good to validate the value of priority like we do in Acquire() here.

Copy link
Member Author

Choose a reason for hiding this comment

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

ah makes sense. will do!

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