multimutex: remove HashMutex, make Mutex type a type param
In this commit, we eliminate some code duplication by removing the old `HashMutex` struct as it just duplicates all the code with a different type (uint64 and hash). We then make the main Mutex struct take a type param, so the key can be parametrized when the struct is instantiated.
This commit is contained in:
7 files changed
+45
-142
No files matched your search
@@ -132,7 +132,7 @@ type controlTower struct {
|
||||
// paymentsMtx provides synchronization on the payment level to ensure
|
||||
// that no race conditions occur in between updating the database and
|
||||
// sending a notification.
|
||||
paymentsMtx *multimutex.HashMutex
|
||||
paymentsMtx *multimutex.Mutex[lntypes.Hash]
|
||||
}
|
||||
|
||||
// NewControlTower creates a new instance of the controlTower.
|
||||
@@ -143,7 +143,7 @@ func NewControlTower(db *channeldb.PaymentControl) ControlTower {
|
||||
map[uint64]*controlTowerSubscriberImpl,
|
||||
),
|
||||
subscribers: make(map[lntypes.Hash][]*controlTowerSubscriberImpl),
|
||||
paymentsMtx: multimutex.NewHashMutex(),
|
||||
paymentsMtx: multimutex.NewMutex[lntypes.Hash](),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -442,7 +442,7 @@ type ChannelRouter struct {
|
||||
// channelEdgeMtx is a mutex we use to make sure we process only one
|
||||
// ChannelEdgePolicy at a time for a given channelID, to ensure
|
||||
// consistency between the various database accesses.
|
||||
channelEdgeMtx *multimutex.Mutex
|
||||
channelEdgeMtx *multimutex.Mutex[uint64]
|
||||
|
||||
// statTicker is a resumable ticker that logs the router's progress as
|
||||
// it discovers channels or receives updates.
|
||||
@@ -480,7 +480,7 @@ func New(cfg Config) (*ChannelRouter, error) {
|
||||
networkUpdates: make(chan *routingMsg),
|
||||
topologyClients: &lnutils.SyncMap[uint64, *topologyClient]{},
|
||||
ntfnClientUpdates: make(chan *topologyClientUpdate),
|
||||
channelEdgeMtx: multimutex.NewMutex(),
|
||||
channelEdgeMtx: multimutex.NewMutex[uint64](),
|
||||
selfNode: selfNode,
|
||||
statTicker: ticker.New(defaultStatInterval),
|
||||
stats: new(routerStats),
|
||||
|
||||
Reference in new issue
Block a user