Browse Source

增加mutex类

pull/1/head
Sydonian 2 years ago
parent
commit
89ed2ee4c0
1 changed files with 30 additions and 0 deletions
  1. +30
    -0
      pkg/distlock/service/mutex.go

+ 30
- 0
pkg/distlock/service/mutex.go View File

@@ -0,0 +1,30 @@
package service

import "gitlink.org.cn/cloudream/common/pkg/distlock"

type Mutex struct {
svc *Service
lockReq distlock.LockRequest
lockReqID string
}

func NewMutex(svc *Service, lockReq distlock.LockRequest) *Mutex {
return &Mutex{
svc: svc,
lockReq: lockReq,
}
}

func (m *Mutex) Lock() error {
reqID, err := m.svc.Acquire(m.lockReq)
if err != nil {
return err
}

m.lockReqID = reqID
return nil
}

func (m *Mutex) Unlock() error {
return m.svc.Release(m.lockReqID)
}

Loading…
Cancel
Save