You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
630 B

  1. package sequence
  2. import (
  3. "sync"
  4. )
  5. // just for testing
  6. type MemorySequencer struct {
  7. counter uint64
  8. sequenceLock sync.Mutex
  9. }
  10. func NewMemorySequencer() (m *MemorySequencer) {
  11. m = &MemorySequencer{counter: 1}
  12. return
  13. }
  14. func (m *MemorySequencer) NextFileId(count uint64) uint64 {
  15. m.sequenceLock.Lock()
  16. defer m.sequenceLock.Unlock()
  17. ret := m.counter
  18. m.counter += count
  19. return ret
  20. }
  21. func (m *MemorySequencer) SetMax(seenValue uint64) {
  22. m.sequenceLock.Lock()
  23. defer m.sequenceLock.Unlock()
  24. if m.counter <= seenValue {
  25. m.counter = seenValue + 1
  26. }
  27. }
  28. func (m *MemorySequencer) Peek() uint64 {
  29. return m.counter
  30. }