diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2022-04-02 00:34:57 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-02 00:34:57 +0800 |
commit | 4f27c289472a4cfafb5a9b0e38e6a3413c30c562 (patch) | |
tree | 4a9388cfaf2efe4e9d0ed0242736769ef7e3e083 /modules/sync | |
parent | 4c5cb1e2f2c7a1fcc3b151192bd45bd1bbc090bd (diff) | |
download | gitea-4f27c289472a4cfafb5a9b0e38e6a3413c30c562.tar.gz gitea-4f27c289472a4cfafb5a9b0e38e6a3413c30c562.zip |
Remove legacy `unknwon/com` package (#19298)
Follows: #19284
* The `CopyDir` is only used inside test code
* Rewrite `ToSnakeCase` with more test cases
* The `RedisCacher` only put strings into cache, here we use internal `toStr` to replace the legacy `ToStr`
* The `UniqueQueue` can use string as ID directly, no need to call `ToStr`
Diffstat (limited to 'modules/sync')
-rw-r--r-- | modules/sync/unique_queue.go | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/modules/sync/unique_queue.go b/modules/sync/unique_queue.go index 414cc50f39..df115d7c96 100644 --- a/modules/sync/unique_queue.go +++ b/modules/sync/unique_queue.go @@ -5,8 +5,6 @@ package sync -import "code.gitea.io/gitea/modules/util" - // UniqueQueue is a queue which guarantees only one instance of same // identity is in the line. Instances with same identity will be // discarded if there is already one in the line. @@ -53,10 +51,10 @@ func (q *UniqueQueue) IsClosed() <-chan struct{} { } // IDs returns the current ids in the pool -func (q *UniqueQueue) IDs() []interface{} { +func (q *UniqueQueue) IDs() []string { q.table.lock.Lock() defer q.table.lock.Unlock() - ids := make([]interface{}, 0, len(q.table.pool)) + ids := make([]string, 0, len(q.table.pool)) for id := range q.table.pool { ids = append(ids, id) } @@ -70,20 +68,19 @@ func (q *UniqueQueue) Queue() <-chan string { // Exist returns true if there is an instance with given identity // exists in the queue. -func (q *UniqueQueue) Exist(id interface{}) bool { - return q.table.IsRunning(util.ToStr(id)) +func (q *UniqueQueue) Exist(id string) bool { + return q.table.IsRunning(id) } // AddFunc adds new instance to the queue with a custom runnable function, // the queue is blocked until the function exits. -func (q *UniqueQueue) AddFunc(id interface{}, fn func()) { - idStr := util.ToStr(id) +func (q *UniqueQueue) AddFunc(id string, fn func()) { q.table.lock.Lock() - if _, ok := q.table.pool[idStr]; ok { + if _, ok := q.table.pool[id]; ok { q.table.lock.Unlock() return } - q.table.pool[idStr] = struct{}{} + q.table.pool[id] = struct{}{} if fn != nil { fn() } @@ -91,17 +88,17 @@ func (q *UniqueQueue) AddFunc(id interface{}, fn func()) { select { case <-q.closed: return - case q.queue <- idStr: + case q.queue <- id: return } } // Add adds new instance to the queue. -func (q *UniqueQueue) Add(id interface{}) { +func (q *UniqueQueue) Add(id string) { q.AddFunc(id, nil) } // Remove removes instance from the queue. -func (q *UniqueQueue) Remove(id interface{}) { - q.table.Stop(util.ToStr(id)) +func (q *UniqueQueue) Remove(id string) { + q.table.Stop(id) } |