Skip to content

Commit

Permalink
switch to safemutex v0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
rekby committed Sep 14, 2023
1 parent 9ca0912 commit 2b2facb
Show file tree
Hide file tree
Showing 18 changed files with 121 additions and 69 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -28,7 +28,7 @@ require (
github.com/jonboulle/clockwork v0.4.0
github.com/letsencrypt/pebble/v2 v2.4.0
github.com/rekby/fastuuid v0.9.0
github.com/rekby/safemutex v0.1.0
github.com/rekby/safemutex v0.2.0
golang.org/x/time v0.3.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -218,8 +218,8 @@ github.com/rekby/fastuuid v0.9.0 h1:iQk8V/AyqSrgQAtKRdqx/CVep+CaKwaSWeerw1yEP3Q=
github.com/rekby/fastuuid v0.9.0/go.mod h1:qP8Lh0BH2+4rNGVRDHmDpkvE/ZuLUhjmKpRWjx+WesY=
github.com/rekby/fixenv v0.3.1 h1:zOPocbQmcsxSIjiVu5U+9JAfeu6WeLN7a9ryZkGTGJY=
github.com/rekby/fixenv v0.3.1/go.mod h1:/b5LRc06BYJtslRtHKxsPWFT/ySpHV+rWvzTg+XWk4c=
github.com/rekby/safemutex v0.1.0 h1:DAj4PeL17C/4sfOmDaW+gGwL/dXzJmNducd3VZF9NUc=
github.com/rekby/safemutex v0.1.0/go.mod h1:6I/yJdmctX0RmxEp00RzYBJJXl3ona8PsBiIDqg0v+U=
github.com/rekby/safemutex v0.2.0 h1:iEfcPqsR3EApwWHwdHvp+srN9Wfna+IG8bSpN467Jmk=
github.com/rekby/safemutex v0.2.0/go.mod h1:6I/yJdmctX0RmxEp00RzYBJJXl3ona8PsBiIDqg0v+U=
github.com/rekby/zapcontext v0.0.4 h1:85600nHTteGCLcuOhGp/SzXHymm9QcCA5sn+MPKCodY=
github.com/rekby/zapcontext v0.0.4/go.mod h1:lTIxvHAwWXBZBPPfEvmAEXPbVEcTwd52VaASZWZWcxI=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand Down
4 changes: 2 additions & 2 deletions internal/acme_client_manager/client_manager.go
Expand Up @@ -45,7 +45,7 @@ type AcmeManager struct {
httpClient *http.Client

background sync.WaitGroup
mu safemutex.Mutex[acmeManagerSynced]
mu safemutex.MutexWithPointers[acmeManagerSynced]
}

type acmeManagerSynced struct {
Expand All @@ -71,7 +71,7 @@ func New(ctx context.Context, cache cache.Bytes) *AcmeManager {
AgreeFunction: acme.AcceptTOS,
RenewAccountInterval: renewAccountInterval,
httpClient: http.DefaultClient,
mu: safemutex.NewWithOptions(acmeManagerSynced{lastAccountIndex: -1}, safemutex.MutexOptions{AllowPointers: true}),
mu: safemutex.NewWithPointers(acmeManagerSynced{lastAccountIndex: -1}),
}
}

Expand Down
5 changes: 1 addition & 4 deletions internal/acme_client_manager/client_manager_test.go
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"crypto/rsa"
"encoding/json"
"github.com/rekby/safemutex"
"math/big"
"testing"

Expand Down Expand Up @@ -199,9 +198,7 @@ func TestClientManager_nextEnabledClientIndex(t *testing.T) {
e, _, flush := th.NewEnv(t)
defer flush()

m := AcmeManager{
mu: safemutex.NewWithOptions(acmeManagerSynced{}, safemutex.MutexOptions{AllowPointers: true}),
}
m := AcmeManager{}

m.mu.Lock(func(synced acmeManagerSynced) acmeManagerSynced {
synced.lastAccountIndex = test.lastAccountIndex
Expand Down
4 changes: 2 additions & 2 deletions internal/cert_manager/manager.go
Expand Up @@ -114,7 +114,7 @@ type Manager struct {

certForDomainAuthorize cache.Value

certStateMu safemutex.Mutex[cache.Value]
certStateMu safemutex.MutexWithPointers[cache.Value]

httpTokens cache.Bytes

Expand All @@ -127,7 +127,7 @@ func New(acmeClientManager AcmeClientManager, c cache.Bytes, r prometheus.Regist
res := Manager{}
res.acmeClientManager = acmeClientManager
res.certForDomainAuthorize = cache.NewMemoryValueLRU("authcert")
res.certStateMu = safemutex.NewWithOptions[cache.Value](cache.NewMemoryValueLRU("certstate"), safemutex.MutexOptions{AllowPointers: true})
res.certStateMu = safemutex.NewWithPointers[cache.Value](cache.NewMemoryValueLRU("certstate"))
res.CertificateIssueTimeout = time.Minute
res.httpTokens = cache.NewMemoryCache("Http validation tokens")
res.Cache = c
Expand Down
2 changes: 1 addition & 1 deletion internal/cert_manager/manager_test.go
Expand Up @@ -278,7 +278,7 @@ func createManager(t *testing.T) (res testManagerContext, cancel func()) {
AllowRSACert: true,
AllowECDSACert: true,
certForDomainAuthorize: res.certForDomainAuthorize,
certStateMu: safemutex.NewWithOptions[cache.Value](res.certState, safemutex.MutexOptions{AllowPointers: true}),
certStateMu: safemutex.NewWithPointers[cache.Value](res.certState),
httpTokens: res.httpTokens,
}
res.manager.initMetrics(nil)
Expand Down
3 changes: 1 addition & 2 deletions internal/th/fixenv.go
Expand Up @@ -21,7 +21,6 @@ func NewEnv(t *testing.T) (env *Env, ctx context.Context, cancel func()) {
ctx, ctxCancel := TestContext(td)
tWrap := &testWrapper{
T: td,
m: safemutex.NewWithOptions(testWrapperSynced{}, safemutex.MutexOptions{AllowPointers: true}),
}
env = &Env{
EnvT: fixenv.NewEnv(tWrap),
Expand All @@ -44,7 +43,7 @@ type TD struct {
type testWrapper struct {
*testdeep.T

m safemutex.Mutex[testWrapperSynced]
m safemutex.MutexWithPointers[testWrapperSynced]
}

type testWrapperSynced struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/th/fixtures.go
Expand Up @@ -15,7 +15,7 @@ import (
)

var (
freeListenAddressMutex = safemutex.NewWithOptions(map[string]bool{}, safemutex.MutexOptions{AllowPointers: true})
freeListenAddressMutex = safemutex.NewWithPointers(map[string]bool{})
)

func MockController(e fixenv.Env) minimock.MockController {
Expand Down
2 changes: 2 additions & 0 deletions vendor/github.com/egorgasay/cidranger/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions vendor/github.com/egorgasay/cidranger/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions vendor/github.com/rekby/safemutex/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vendor/github.com/rekby/safemutex/callback.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/rekby/safemutex/errors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 12 additions & 43 deletions vendor/github.com/rekby/safemutex/mutex.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions vendor/github.com/rekby/safemutex/mutex_allow_pointers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/rekby/safemutex/mutex_base.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions vendor/github.com/rekby/safemutex/mutex_try_lock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Expand Up @@ -139,7 +139,7 @@ github.com/rekby/fastuuid/internal/ibytes
# github.com/rekby/fixenv v0.3.1
## explicit; go 1.18
github.com/rekby/fixenv
# github.com/rekby/safemutex v0.1.0
# github.com/rekby/safemutex v0.2.0
## explicit; go 1.18
github.com/rekby/safemutex
# github.com/rekby/zapcontext v0.0.4
Expand Down

0 comments on commit 2b2facb

Please sign in to comment.