Chickenzilla commented on a change in pull request #23: URL: https://github.com/apache/pulsar-dotpulsar/pull/23#discussion_r449524039
########## File path: src/DotPulsar/Internal/SequenceId.cs ########## @@ -12,21 +12,24 @@ * limitations under the License. */ +using System.Threading; + namespace DotPulsar.Internal { public sealed class SequenceId { + private long _current; + public SequenceId(ulong initialSequenceId) { - Current = initialSequenceId; - - if (initialSequenceId > 0) - Increment(); + // Subtracting one because Interlocked.Increment will return the post-incremented value + // which is expected to be the initialSequenceId for the first call + _current = unchecked((long)initialSequenceId - 1); } - public ulong Current { get; private set; } - - public void Increment() - => ++Current; + public ulong FetchNext() + { + return unchecked((ulong)Interlocked.Increment(ref _current)); Review comment: That cast should be as close to free as code can get. In any case, I would love to have a ulong Interlocked.Increment but we just don't have one (the processor intrinsic doesn't care, it just sees 64-bits). ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org