Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

50 wiersze
982 B

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Threading;
  5. namespace JT808.Gateway.Metadata
  6. {
  7. /// <summary>
  8. ///
  9. /// <see cref="Grpc.Core.Internal"/>
  10. /// </summary>
  11. internal class JT808AtomicCounter
  12. {
  13. long counter = 0;
  14. public JT808AtomicCounter(long initialCount = 0)
  15. {
  16. this.counter = initialCount;
  17. }
  18. public void Reset()
  19. {
  20. Interlocked.Exchange(ref counter, 0);
  21. }
  22. public long Increment()
  23. {
  24. return Interlocked.Increment(ref counter);
  25. }
  26. public long Add(long len)
  27. {
  28. return Interlocked.Add(ref counter,len);
  29. }
  30. public long Decrement()
  31. {
  32. return Interlocked.Decrement(ref counter);
  33. }
  34. public long Count
  35. {
  36. get
  37. {
  38. return Interlocked.Read(ref counter);
  39. }
  40. }
  41. }
  42. }