mirror of
https://gitea.com/gitea/act_runner.git
synced 2024-12-28 11:58:20 +01:00
34 lines
590 B
Go
34 lines
590 B
Go
|
package poller
|
||
|
|
||
|
import "sync/atomic"
|
||
|
|
||
|
// Metric interface
|
||
|
type Metric interface {
|
||
|
IncBusyWorker() uint64
|
||
|
DecBusyWorker() uint64
|
||
|
BusyWorkers() uint64
|
||
|
}
|
||
|
|
||
|
var _ Metric = (*metric)(nil)
|
||
|
|
||
|
type metric struct {
|
||
|
busyWorkers uint64
|
||
|
}
|
||
|
|
||
|
// NewMetric for default metric structure
|
||
|
func NewMetric() Metric {
|
||
|
return &metric{}
|
||
|
}
|
||
|
|
||
|
func (m *metric) IncBusyWorker() uint64 {
|
||
|
return atomic.AddUint64(&m.busyWorkers, 1)
|
||
|
}
|
||
|
|
||
|
func (m *metric) DecBusyWorker() uint64 {
|
||
|
return atomic.AddUint64(&m.busyWorkers, ^uint64(0))
|
||
|
}
|
||
|
|
||
|
func (m *metric) BusyWorkers() uint64 {
|
||
|
return atomic.LoadUint64(&m.busyWorkers)
|
||
|
}
|