Skip to content

Commit

Permalink
small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kkrik-es committed Dec 3, 2024
1 parent ce51392 commit d30d7b8
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,23 @@ static class Acceptor {

boolean accept() {
final long now = System.currentTimeMillis();
boolean accepted = false;
// Check without guarding first, to reduce contention.
if (now - lastAcceptedTimeMillis > intervalMillis) {
// Check if another concurrent logging operation succeeded.
// Check if another concurrent operation succeeded.
if (lastAcceptedGuard.compareAndSet(false, true)) {
// Repeat check under guard protection, so that only one message gets written per interval.
if (now - lastAcceptedTimeMillis > intervalMillis) {
lastAcceptedTimeMillis = now;
accepted = true;
try {
// Repeat check under guard protection, so that only one message gets written per interval.
if (now - lastAcceptedTimeMillis > intervalMillis) {
lastAcceptedTimeMillis = now;
return true;
}
} finally {
// Reset guard.
lastAcceptedGuard.set(false);
}
// Reset guard before logging.
lastAcceptedGuard.set(false);
}
}
return accepted;
return false;
}
}
}

0 comments on commit d30d7b8

Please sign in to comment.