-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathglobal.go
More file actions
45 lines (35 loc) · 939 Bytes
/
global.go
File metadata and controls
45 lines (35 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) 2025 pk910
// SPDX-License-Identifier: Apache-2.0
// This file is part of the dynamic-ssz library.
package dynssz
import (
"sync"
"sync/atomic"
)
var (
globalDynSsz atomic.Pointer[DynSsz]
globalMu sync.Mutex
)
// GetGlobalDynSsz returns the global DynSsz instance, creating one with default
// settings if none exists. Safe for concurrent use.
func GetGlobalDynSsz() *DynSsz {
if ds := globalDynSsz.Load(); ds != nil {
return ds
}
globalMu.Lock()
defer globalMu.Unlock()
// Double-check after acquiring lock.
if ds := globalDynSsz.Load(); ds != nil {
return ds
}
ds := NewDynSsz(nil)
globalDynSsz.Store(ds)
return ds
}
// SetGlobalSpecs replaces the global DynSsz instance with a new one configured
// with the given specification values. Safe for concurrent use.
func SetGlobalSpecs(specs map[string]any) {
globalMu.Lock()
defer globalMu.Unlock()
globalDynSsz.Store(NewDynSsz(specs))
}