Skip to content

Commit

Permalink
ban lock
Browse files Browse the repository at this point in the history
  • Loading branch information
LordCasser committed Dec 14, 2022
1 parent 238686a commit 97490e3
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions clock.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"container/list"
"github.com/google/uuid"
"log"
"sync"
"time"
)

Expand All @@ -21,8 +20,8 @@ type Clock struct {
addTaskSig chan Task
removeTaskSig chan string
stopSig chan bool
lock *sync.Mutex
deleteList []string
//lock *sync.Mutex
deleteList []string
}

type Task struct {
Expand All @@ -48,8 +47,8 @@ func New(interval time.Duration, slotNum int, cb func()) *Clock {
addTaskSig: make(chan Task),
removeTaskSig: make(chan string),
stopSig: make(chan bool),
lock: &sync.Mutex{},
deleteList: make([]string, 1024),
//lock: &sync.Mutex{},
deleteList: make([]string, 1024),
}

clock.initSlots()
Expand All @@ -66,13 +65,13 @@ func (c *Clock) initSlots() {

// Start 启动时间轮
func (c *Clock) Start() {
if !c.lock.TryLock() {
log.Println("already started")
return
}
//if !c.lock.TryLock() {
// log.Println("already started")
// return
//}

c.ticker = time.NewTicker(c.interval)
c.lock.Lock()
//c.lock.Lock()
go c.start()

}
Expand Down Expand Up @@ -112,7 +111,7 @@ func (c *Clock) start() {
c.removeTask(key)
case <-c.stopSig:
c.ticker.Stop()
c.lock.Unlock()
//c.lock.Unlock()
return
}
}
Expand Down

0 comments on commit 97490e3

Please sign in to comment.