Bug fix in SequenceGenerator

.NET library for SMPP protocol
Post Reply
murtz
Posts: 15
Joined: Thu May 14, 2015 11:04 am

Bug fix in SequenceGenerator

Post by murtz » Thu Jun 08, 2017 10:47 am

I have fixed a bug in SequenceGenerator class. Please see below.

Code: Select all

        public uint NextSequenceNumber()
        {
            lock (_syncSequenceNumber)
            {
                //Changed 0x7FFFFFFF to int.MaxValue for easy representation only
                if (_counter == int.MaxValue)
                    _counter = 0;

                //Return from within the lock body as value may get change by another thread before the call of return statement
                //_counter++;
                return ++_counter;
            }
            //No longer needed
            //return _counter;
        }

        public byte NextReferenceNumber()
        {
            lock (_syncReferenceNumber)
            {
                if (_byteCounter == byte.MaxValue)
                    _byteCounter = 0;

                //Return from within the lock body as value may get change by another thread before the call of return statement
                //_byteCounter++;
                return ++_byteCounter;
            }
            //No longer needed
            //return _byteCounter;
        }

alt
Site Admin
Posts: 727
Joined: Tue Apr 25, 2006 9:45 am

Re: Bug fix in SequenceGenerator

Post by alt » Mon Jul 03, 2017 7:42 pm

Thank you for pointing this bug to me.

Post Reply